Skip to content

Commit

Permalink
fix: S3 implementation of rhoC_AVE for cbsem_model
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyaray committed Nov 19, 2024
1 parent e473175 commit 0dc1e7a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ S3method(print,summary.predict_pls_model)
S3method(print,summary.seminr_model)
S3method(print,table_output)
S3method(rerun,pls_model)
S3method(rhoC_AVE,cbsem_model)
S3method(rhoC_AVE,pls_model)
S3method(summary,boot_seminr_model)
S3method(summary,cbsem_model)
Expand Down
36 changes: 28 additions & 8 deletions R/evaluate_reliability.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ rhoC_AVE <- function(x, constructs = NULL) {
UseMethod("rhoC_AVE")
}

# rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(pls_model, constructs) {
#' 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 @@ -111,14 +115,30 @@ rhoC_AVE.pls_model <- rhoC_AVE.boot_seminr_model <- function(x, constructs = NUL
return(dgr)
}

# Assumes factor loadings are in model:
# lavaan::inspect(fit,what="std")$lambda
rhoC_AVE_cbsem_model <- function(seminr_model) {
dgr <- matrix(NA, nrow=length(seminr_model$constructs), ncol=2)
rownames(dgr) <- seminr_model$constructs
#' 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
cbsem_model <- x
if (is.null(constructs)) {
constructs <- cbsem_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 <- cbsem_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_cbsem.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ summary.cbsem_model <- function(object, na.print=".", digits=3, alpha=0.05,...)

model_summary$quality <- list(
fit = summarize_fit(object$lavaan_output),
reliability = rhoC_AVE_cbsem_model(object),
reliability = rhoC_AVE(object),
antecedent_vifs = regr_vifs
)

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

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

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

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

0 comments on commit 0dc1e7a

Please sign in to comment.