-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:sem-in-r/seminr into develop
- Loading branch information
Showing
15 changed files
with
809 additions
and
709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' Return all path bootstraps as a long dataframe. | ||
#' Columns of the dataframes are specified paths and rows are the estimated | ||
#' coefficients for the paths at each bootstrap iteration. | ||
#' | ||
#' @param pls_boot bootstrapped PLS model | ||
#' | ||
#' @examples | ||
#' data(mobi) | ||
#' | ||
#' mobi_mm <- constructs( | ||
#' composite("Image", multi_items("IMAG", 1:5)), | ||
#' composite("Expectation", multi_items("CUEX", 1:3)), | ||
#' composite("Satisfaction", multi_items("CUSA", 1:3)) | ||
#' ) | ||
#' | ||
#' mobi_sm <- relationships( | ||
#' paths(from = c("Image", "Expectation"), to = "Satisfaction") | ||
#' ) | ||
#' | ||
#' pls_model <- estimate_pls(data = mobi, | ||
#' measurement_model = mobi_mm, | ||
#' structural_model = mobi_sm) | ||
#' | ||
#' pls_boot <- bootstrap_model(seminr_model = pls_model, | ||
#' nboot = 50, cores = 2, seed = NULL) | ||
#' | ||
#' boot_paths_df(pls_boot) | ||
#' | ||
#' @export | ||
boot_paths_df <- function(pls_boot) { | ||
path_names <- apply(pls_boot$smMatrix, 1, \(path) { | ||
paste(path['source'], '->', path['target']) | ||
}) | ||
|
||
boot_paths <- apply(pls_boot$smMatrix, 1, \(path) { | ||
pls_boot$boot_paths[path['source'], path['target'], 1:pls_boot$boots] | ||
}) | ||
|
||
colnames(boot_paths) <- path_names | ||
boot_paths | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#' Standardize (scale) a matrix/df and report interpretable errors | ||
#' | ||
#' @param x vector, data.frame, or matrix | ||
#' @return scaled object as returned by \code{scale} function | ||
standardize_safely <- function(x) { | ||
# NOTE: we could return zeros for columns with zero variance: | ||
# apply(x, 2, function(y) (y - mean(y)) / sd(y) ^ as.logical(sd(y))) | ||
res <- scale(x, TRUE, TRUE) | ||
if (any(is.nan(res))) stop("zero variance items cannot be scaled") | ||
res | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.