From 0dc1e7a19382df719f2d32983a0298f5b61ed40b Mon Sep 17 00:00:00 2001 From: Soumya Ray Date: Tue, 19 Nov 2024 20:30:06 +0800 Subject: [PATCH] fix: S3 implementation of rhoC_AVE for cbsem_model --- NAMESPACE | 1 + R/evaluate_reliability.R | 36 ++++++++++++++++++++++++++++-------- R/report_cbsem.R | 2 +- man/rhoC_AVE.cbsem_model.Rd | 19 +++++++++++++++++++ man/rhoC_AVE.pls_model.Rd | 19 +++++++++++++++++++ 5 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 man/rhoC_AVE.cbsem_model.Rd create mode 100644 man/rhoC_AVE.pls_model.Rd diff --git a/NAMESPACE b/NAMESPACE index 1b51a7f..0267682 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/evaluate_reliability.R b/R/evaluate_reliability.R index 81d3d47..be78a03 100644 --- a/R/evaluate_reliability.R +++ b/R/evaluate_reliability.R @@ -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 @@ -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 diff --git a/R/report_cbsem.R b/R/report_cbsem.R index 5040111..8b64910 100644 --- a/R/report_cbsem.R +++ b/R/report_cbsem.R @@ -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 ) diff --git a/man/rhoC_AVE.cbsem_model.Rd b/man/rhoC_AVE.cbsem_model.Rd new file mode 100644 index 0000000..6a67ba7 --- /dev/null +++ b/man/rhoC_AVE.cbsem_model.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/evaluate_reliability.R +\name{rhoC_AVE.cbsem_model} +\alias{rhoC_AVE.cbsem_model} +\title{seminr rhoC_AVE() function} +\usage{ +\method{rhoC_AVE}{cbsem_model}(x, constructs = NULL) +} +\arguments{ +\item{x}{Estimated \code{cbsem_model} object.} + +\item{constructs}{Vector containing the names of the constructs to calculate rhoC and AVE for; if NULL, all constructs are used.} +} +\value{ +A matrix containing the rhoC and AVE metrics for each construct. +} +\description{ +Get rhoC and AVE for a CBSEM model estimated with \code{estimate_cbsem} +} diff --git a/man/rhoC_AVE.pls_model.Rd b/man/rhoC_AVE.pls_model.Rd new file mode 100644 index 0000000..7250d9a --- /dev/null +++ b/man/rhoC_AVE.pls_model.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/evaluate_reliability.R +\name{rhoC_AVE.pls_model} +\alias{rhoC_AVE.pls_model} +\title{Get rhoC and AVE for a PLS model estimated with \code{estimate_pls}} +\usage{ +\method{rhoC_AVE}{pls_model}(x, constructs = NULL) +} +\arguments{ +\item{x}{Estimated \code{pls_model} object.} + +\item{constructs}{Vector containing the names of the constructs to calculate rhoC and AVE for; if NULL, all constructs are used.} +} +\value{ +A matrix containing the rhoC and AVE metrics for each construct. +} +\description{ +Get rhoC and AVE for a PLS model estimated with \code{estimate_pls} +}