Skip to contents

Fit Path Models to a Correlation Matrix

Usage

model_fit(model_input, R, method_null = "sem", N)

Arguments

model_input

Model input as a character string. Multiple models need to be on their own line. Regression paths use ~, latent measurement paths use =~, and residual variances or covariances use ~~.

R

A named correlation matrix, typically the pooled correlation matrix extracted from a fitted mars object.

method_null

Null-model method for observed-variable path models. Currently "sem" uses an independence model with all off-diagonal correlations set to zero.

N

Sample size used to scale the discrepancy function into chi-square fit statistics.

Value

A list containing path coefficients, chi-square fit statistics, CFI, TLI, RMSEA, SRMR, raw fit-index values, and flags indicating whether bounded display values were clipped.

Details

model_fit() chooses between two fitting paths based on the syntax in model_input.

For observed-variable path models that use only ~, coefficients are computed algebraically from the supplied correlation matrix. For each regression equation, standardized coefficients are \(R_{xx}^{-1}R_{xy}\). The implied residual covariance matrix is assembled from the observed exogenous correlations and \(1 - R^2\) residual variances, and model fit is evaluated with the package's GLS-style discrepancy between the observed and implied correlation matrices. The SEM-style null model is an independence model with the diagonal of R retained.

For latent-variable or covariance models using =~ or ~~, the function builds RAM-style directed-effect (A) and residual covariance (S) matrices and minimizes the normal-theory SEM discrepancy $$ F(\theta) = \log|\Sigma(\theta)| + \mathrm{tr}\{R\Sigma(\theta)^{-1}\} - \log|R| - p, $$ where \(\Sigma(\theta)\) is the model-implied correlation matrix for the observed variables. Optimization is performed with optim using method = "BFGS", up to 2000 iterations, and a numerical Hessian is requested for downstream uncertainty calculations. Variance parameters are optimized on the log scale to keep them positive. Fixed parameters can be supplied as value * variable; otherwise the first loading for each unscaled latent factor is fixed to one for marker-variable identification.

Chi-square statistics use (N - 1) * F. Incremental and residual fit indices are derived from the fitted and null discrepancies. CFI, TLI, and SRMR are bounded for display, with raw values returned in fit_index_raw and clipping indicators returned in fit_index_flags.

Examples

Br <-  matrix(c(1.00000000, -0.09773331, -0.1755029,  0.3186775,
-0.09773331,  1.00000000,  0.5271873, -0.4175596,
-0.17550292,  0.5271872,  1.0000000, -0.4006848,
0.31867753, -0.41755963, -0.4006848,  1.0000000),
nrow = 4, byrow = TRUE)

colnames(Br) <- c("Performance",  "Self_confidence",  "Cognitive", "Somatic" )

rownames(Br) <- colnames(Br)

## Proposed path model
model <- "## Regression paths
Performance ~  Self_confidence  + Cognitive  + Somatic
Self_confidence ~ Cognitive + Somatic "

N <- 573
model_fit(model_input = model, R = Br,
         method_null = "sem", N)
#> $path_coefficients
#> $path_coefficients[[1]]
#> Self_confidence -> Performance       Cognitive -> Performance 
#>                     0.08316153                    -0.09261001 
#>         Somatic -> Performance 
#>                     0.31629500 
#> 
#> $path_coefficients[[2]]
#> Cognitive -> Self_confidence   Somatic -> Self_confidence 
#>                    0.4287053                   -0.2457839 
#> 
#> 
#> $Model
#>    Chi2      df  pvalue 
#> 59.1102  2.0000  0.0000 
#> 
#> $NullModel
#> Chi2Null   dfNull 
#> 643.3373   6.0000 
#> 
#> $CFI
#> [1] 0.9103925
#> 
#> $TLI
#> [1] 0.7311776
#> 
#> $RMSEA
#> [1] 0.2234312
#> 
#> $RMSEA_CI
#> [1] 0.1671203 0.2835352
#> 
#> $SRMR
#> [1] 0.2672185
#> 
#> $fit_index_raw
#>       CFI       TLI     RMSEA      SRMR 
#> 0.9103925 0.7311776 0.2234312 0.2672185 
#> 
#> $fit_index_flags
#>    CFI_clipped    TLI_clipped RMSEA_adjusted   SRMR_clipped 
#>          FALSE          FALSE          FALSE          FALSE 
#> 
model_fit(model_input = model, R = Br,
         method_null = "sem", N )
#> $path_coefficients
#> $path_coefficients[[1]]
#> Self_confidence -> Performance       Cognitive -> Performance 
#>                     0.08316153                    -0.09261001 
#>         Somatic -> Performance 
#>                     0.31629500 
#> 
#> $path_coefficients[[2]]
#> Cognitive -> Self_confidence   Somatic -> Self_confidence 
#>                    0.4287053                   -0.2457839 
#> 
#> 
#> $Model
#>    Chi2      df  pvalue 
#> 59.1102  2.0000  0.0000 
#> 
#> $NullModel
#> Chi2Null   dfNull 
#> 643.3373   6.0000 
#> 
#> $CFI
#> [1] 0.9103925
#> 
#> $TLI
#> [1] 0.7311776
#> 
#> $RMSEA
#> [1] 0.2234312
#> 
#> $RMSEA_CI
#> [1] 0.1671203 0.2835352
#> 
#> $SRMR
#> [1] 0.2672185
#> 
#> $fit_index_raw
#>       CFI       TLI     RMSEA      SRMR 
#> 0.9103925 0.7311776 0.2234312 0.2672185 
#> 
#> $fit_index_flags
#>    CFI_clipped    TLI_clipped RMSEA_adjusted   SRMR_clipped 
#>          FALSE          FALSE          FALSE          FALSE 
#>