Skip to content

Commit

Permalink
fix: S3 implementation of rhoC_AVE for cfa_model
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyaray committed Nov 19, 2024
1 parent 0dc1e7a commit 6ef8464
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 66 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ S3method(print,summary.seminr_model)
S3method(print,table_output)
S3method(rerun,pls_model)
S3method(rhoC_AVE,cbsem_model)
S3method(rhoC_AVE,cfa_model)
S3method(rhoC_AVE,pls_model)
S3method(summary,boot_seminr_model)
S3method(summary,cbsem_model)
Expand Down Expand Up @@ -84,6 +85,7 @@ export(regression_weights)
export(relationships)
export(report_paths)
export(rerun)
export(rhoC_AVE)
export(rho_A)
export(save_plot)
export(seminr_theme_create)
Expand Down
54 changes: 27 additions & 27 deletions R/evaluate_reliability.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,25 @@ rho_A <- function(seminr_model, constructs) {
}
# End rho_A function

# RhoC and AVE
# Dillon-Goldstein's Rho as per: Dillon, W. R, and M. Goldstein. 1987. Multivariate Analysis: Methods
# 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
#' seminr rhoC_AVE() function
#'
#' Get rhoC and AVE for a CFA model estimated with \code{estimate_pls}, \code{estimate_cbsem} or \code{estimate_cfa}.
#' Dillon-Goldstein's Rho as per: Dillon, W. R, and M. Goldstein. 1987. Multivariate Analysis: Methods
#' 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
#'
#' @param x Estimated \code{seminr_model} object.
#'
#' @param constructs Vector containing the names of the constructs to calculate rhoC and AVE for; if NULL, all constructs are used.
#'
#' @return A matrix containing the rhoC and AVE metrics for each construct.
#'
#' @export
rhoC_AVE <- function(x, constructs = NULL) {
UseMethod("rhoC_AVE")
}

#' Get rhoC and AVE for a PLS model estimated with \code{estimate_pls}
#' @param x Estimated \code{pls_model} object.
#' @param constructs Vector containing the names of the constructs to calculate rhoC and AVE for; if NULL, all constructs are used.
#' @return A matrix containing the rhoC and AVE metrics for each construct.
#'
#' @export
rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(x, constructs = NULL) {
pls_model <- x
Expand All @@ -115,20 +120,9 @@ rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(x, constructs = NUL
return(dgr)
}

#' seminr rhoC_AVE() function
#'
#' Get rhoC and AVE for a CBSEM model estimated with \code{estimate_cbsem}
#'
#' @param x Estimated \code{cbsem_model} object.
#'
#' @param constructs Vector containing the names of the constructs to calculate rhoC and AVE for; if NULL, all constructs are used.
#'
#' @return A matrix containing the rhoC and AVE metrics for each construct.
#'
#' @export
rhoC_AVE.cbsem_model <- function(x, constructs = NULL) {
# Assumes factor loadings are in model:
# lavaan::inspect(fit,what="std")$lambda
# Assumes factor loadings are in model: lavaan::inspect(fit,what="std")$lambda
cbsem_model <- x
if (is.null(constructs)) {
constructs <- cbsem_model$constructs
Expand All @@ -151,12 +145,18 @@ rhoC_AVE.cbsem_model <- function(x, constructs = NULL) {
return(dgr)
}

rhoC_AVE_cfa_model <- function(seminr_model) {
dgr <- matrix(NA, nrow=length(seminr_model$constructs), ncol=2)
rownames(dgr) <- seminr_model$constructs
#' @export
rhoC_AVE.cfa_model <- function(x, constructs = NULL) {
cfa_model <- x
if (is.null(constructs)) {
constructs <- cfa_model$constructs
}

dgr <- matrix(NA, nrow=length(constructs), ncol=2)
rownames(dgr) <- constructs
colnames(dgr) <- c("rhoC", "AVE")
for(i in seminr_model$constructs) {
loadings <- seminr_model$factor_loadings[, i]
for(i in constructs) {
loadings <- cfa_model$factor_loadings[, i]
ind <- which(loadings != 0)
if(length(ind) == 1) {
dgr[i, 1:2] <- 1
Expand Down
2 changes: 1 addition & 1 deletion R/report_cfa.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ summary.cfa_model <- function(object, na.print=".", digits=3, alpha=0.05,...) {
model_summary <- summarize_cb_measurement(object, alpha=alpha)
model_summary$quality <- list(
fit = summarize_fit(object$lavaan_output),
reliability = rhoC_AVE_cfa_model(object)
reliability = rhoC_AVE(object)
)

class(model_summary) <- c("summary.cfa_model", class(model_summary))
Expand Down
23 changes: 23 additions & 0 deletions man/rhoC_AVE.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions man/rhoC_AVE.cbsem_model.Rd

This file was deleted.

19 changes: 0 additions & 19 deletions man/rhoC_AVE.pls_model.Rd

This file was deleted.

0 comments on commit 6ef8464

Please sign in to comment.