From e4731754db9eecb915d38671d305e1b0b4e0ff4e Mon Sep 17 00:00:00 2001 From: Soumya Ray Date: Tue, 19 Nov 2024 14:54:04 +0800 Subject: [PATCH] fix: S3 generic method and implementations use same function signatures --- DESCRIPTION | 4 ++-- R/evaluate_measurement_model.R | 2 +- R/evaluate_reliability.R | 27 ++++++--------------------- R/evaluate_validity.R | 2 +- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 10c1e80..c667d52 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: seminr Type: Package Title: Building and Estimating Structural Equation Models -Version: 2.3.4 +Version: 2.3.5 Date: 2024-10-12 Authors@R: c(person("Soumya", "Ray", email = "soumya.ray@gmail.com", role = c("aut", "ths")), person("Nicholas Patrick", "Danks", email = "nicholasdanks@hotmail.com", role = c("aut","cre")), @@ -33,7 +33,7 @@ Depends: R (>= 3.5.0) LazyData: TRUE URL: https://github.com/sem-in-r/seminr BugReports: https://github.com/sem-in-r/seminr/issues -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Enhances: rsvg (>= 2.1), semPlot, vdiffr diff --git a/R/evaluate_measurement_model.R b/R/evaluate_measurement_model.R index 8f149fc..4e158ab 100644 --- a/R/evaluate_measurement_model.R +++ b/R/evaluate_measurement_model.R @@ -13,7 +13,7 @@ reliability <- function(seminr_model) { #get HOC model_constructs <- constructs_in_model(seminr_model) alpha <- cronbachs_alpha(seminr_model, model_constructs$construct_names) - mat1 <- rhoC_AVE(pls_model = seminr_model, constructs = model_constructs$construct_names) + mat1 <- rhoC_AVE(seminr_model, constructs = model_constructs$construct_names) mat2 <- rho_A(seminr_model, model_constructs$construct_names) table <- cbind(alpha, mat1, mat2) colnames(table) <- c("alpha", "rhoC", "AVE", "rhoA") diff --git a/R/evaluate_reliability.R b/R/evaluate_reliability.R index 160928e..81d3d47 100644 --- a/R/evaluate_reliability.R +++ b/R/evaluate_reliability.R @@ -80,34 +80,19 @@ rho_A <- function(seminr_model, constructs) { # and Applications. Biometrical Journal 29 (6). # Average Variance Extracted as per: Fornell, C. and D. F. Larcker (February 1981). Evaluating # structural equation models with unobservable variables and measurement error, Journal of Marketing Research, 18, pp. 39-5 -rhoC_AVE <- function(x, ...) { +rhoC_AVE <- function(x, constructs = NULL) { UseMethod("rhoC_AVE") } +# rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(pls_model, constructs) { #' @export -rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(pls_model, constructs) { - dgr <- matrix(NA, nrow=length(constructs), ncol=2) - rownames(dgr) <- constructs - colnames(dgr) <- c("rhoC", "AVE") - for(i in constructs){ - loadings <- pls_model$outer_loadings[, i] - ind <- which(loadings != 0) - if(measure_mode(i, pls_model$mmMatrix) %in% c("A", "B", "HOCA", "HOCB", "C", "UNIT")) { - if(length(ind) == 1) { - dgr[i, 1:2] <- 1 - } else { - lambdas <- loadings[ind] - dgr[i, 1] <- compute_rhoC(lambdas) - dgr[i, 2] <- compute_AVE(lambdas) - } - } +rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(x, constructs = NULL) { + pls_model <- x + if (is.null(constructs)) { + constructs <- pls_model$constructs } - return(dgr) -} -rhoC_AVE_boot_seminr_model <- function(pls_model, constructs){ dgr <- matrix(NA, nrow=length(constructs), ncol=2) - rownames(dgr) <- constructs colnames(dgr) <- c("rhoC", "AVE") for(i in constructs){ diff --git a/R/evaluate_validity.R b/R/evaluate_validity.R index fed97ae..34164e5 100644 --- a/R/evaluate_validity.R +++ b/R/evaluate_validity.R @@ -89,7 +89,7 @@ fl_criteria_table <- function(seminr_model, model_constructs) { # } table <- stats::cor(model_constructs$construct_scores) table[upper.tri(table)] <- NA - diag(table) <- sqrt(rhoC_AVE(seminr_model, model_constructs$construct_names)[,"AVE"]) + diag(table) <- sqrt(rhoC_AVE(seminr_model, constructs = model_constructs$construct_names)[,"AVE"]) comment(table) <- "FL Criteria table reports square root of AVE on the diagonal and construct correlations on the lower triangle." convert_to_table_output(table) }