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 greater than one, used for single-sample normal-theory statistics and conditional covariance. These statistics do not account for meta-analytic synthesis; use path_model() for pooled matrices.

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. Numerical asymmetry below a relative tolerance of 1e-6 is symmetrized; larger asymmetry and non-positive-definite input matrices are rejected.

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 normal-theory 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.08316152                    -0.09261001 
#>         Somatic -> Performance 
#>                     0.31629498 
#> 
#> $path_coefficients[[2]]
#> Cognitive -> Self_confidence   Somatic -> Self_confidence 
#>                    0.4287054                   -0.2457839 
#> 
#> 
#> $A_mat
#>                 Performance Self_confidence   Cognitive    Somatic
#> Performance               0      0.08316152 -0.09261001  0.3162950
#> Self_confidence           0      0.00000000  0.42870538 -0.2457839
#> Cognitive                 0      0.00000000  0.00000000  0.0000000
#> Somatic                   0      0.00000000  0.00000000  0.0000000
#> 
#> $S_mat
#>                 Performance Self_confidence  Cognitive    Somatic
#> Performance       0.8910782       0.0000000  0.0000000  0.0000000
#> Self_confidence   0.0000000       0.6713626  0.0000000  0.0000000
#> Cognitive         0.0000000       0.0000000  1.0000000 -0.4006848
#> Somatic           0.0000000       0.0000000 -0.4006848  1.0000000
#> 
#> $C_mat
#>                 Performance Self_confidence  Cognitive    Somatic
#> Performance      1.00000000     -0.09773331 -0.1755029  0.3186775
#> Self_confidence -0.09773331      1.00000000  0.5271872 -0.4175596
#> Cognitive       -0.17550291      0.52718725  1.0000000 -0.4006848
#> Somatic          0.31867751     -0.41755961 -0.4006848  1.0000000
#> 
#> $Model
#>   Chi2     df pvalue 
#>      0      0     NA 
#> 
#> $NullModel
#> Chi2Null   dfNull 
#> 393.9795   6.0000 
#> 
#> $CFI
#> [1] 1
#> 
#> $TLI
#> [1] NA
#> 
#> $RMSEA
#> [1] NA
#> 
#> $RMSEA_CI
#> [1] NA NA
#> 
#> $SRMR
#> [1] 3.949688e-17
#> 
#> $fit_index_raw
#>          CFI          TLI        RMSEA         SRMR 
#> 1.000000e+00           NA           NA 3.949688e-17 
#> 
#> $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.08316152                    -0.09261001 
#>         Somatic -> Performance 
#>                     0.31629498 
#> 
#> $path_coefficients[[2]]
#> Cognitive -> Self_confidence   Somatic -> Self_confidence 
#>                    0.4287054                   -0.2457839 
#> 
#> 
#> $A_mat
#>                 Performance Self_confidence   Cognitive    Somatic
#> Performance               0      0.08316152 -0.09261001  0.3162950
#> Self_confidence           0      0.00000000  0.42870538 -0.2457839
#> Cognitive                 0      0.00000000  0.00000000  0.0000000
#> Somatic                   0      0.00000000  0.00000000  0.0000000
#> 
#> $S_mat
#>                 Performance Self_confidence  Cognitive    Somatic
#> Performance       0.8910782       0.0000000  0.0000000  0.0000000
#> Self_confidence   0.0000000       0.6713626  0.0000000  0.0000000
#> Cognitive         0.0000000       0.0000000  1.0000000 -0.4006848
#> Somatic           0.0000000       0.0000000 -0.4006848  1.0000000
#> 
#> $C_mat
#>                 Performance Self_confidence  Cognitive    Somatic
#> Performance      1.00000000     -0.09773331 -0.1755029  0.3186775
#> Self_confidence -0.09773331      1.00000000  0.5271872 -0.4175596
#> Cognitive       -0.17550291      0.52718725  1.0000000 -0.4006848
#> Somatic          0.31867751     -0.41755961 -0.4006848  1.0000000
#> 
#> $Model
#>   Chi2     df pvalue 
#>      0      0     NA 
#> 
#> $NullModel
#> Chi2Null   dfNull 
#> 393.9795   6.0000 
#> 
#> $CFI
#> [1] 1
#> 
#> $TLI
#> [1] NA
#> 
#> $RMSEA
#> [1] NA
#> 
#> $RMSEA_CI
#> [1] NA NA
#> 
#> $SRMR
#> [1] 3.949688e-17
#> 
#> $fit_index_raw
#>          CFI          TLI        RMSEA         SRMR 
#> 1.000000e+00           NA           NA 3.949688e-17 
#> 
#> $fit_index_flags
#>    CFI_clipped    TLI_clipped RMSEA_adjusted   SRMR_clipped 
#>          FALSE          FALSE          FALSE          FALSE 
#>