Created
March 20, 2021 05:06
-
-
Save soumyaray/403e884cefe2627f995fd148b2f89f3e to your computer and use it in GitHub Desktop.
Unstandardizes construct scores of an estimated SEMinR model
This file contains hidden or 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
# Unstandardizes construct scores of an estimated SEMinR model | |
# (Based on rescale function of plspm) | |
# usage: | |
# my_model <- estimate_pls(...) | |
# ustd <- unstandardize(my_model) | |
unstandardize_scores <- function(pls_model) { | |
construct_names <- seminr:::construct_names(pls_model$smMatrix) | |
construct_names -> . | |
sapply(., seminr:::items_of_construct, model=pls_model) -> . | |
unlist(.) -> . | |
unname(.) -> . | |
. -> construct_items | |
relevant_data <- pls_model$data[, construct_items] | |
weights <- pls_model$outer_weights[names(relevant_data), ] | |
weight_sums <- matrix(colSums(weights), ncol(weights), ncol(weights)) | |
weights %*% (1/weight_sums) -> . | |
.[weights == 0] <- 0 | |
colnames(.) <- colnames(weights) | |
. -> normalized_wts | |
unstd_scores <- as.matrix(relevant_data) %*% normalized_wts | |
as.data.frame(unstd_scores) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment