Skip to contents

This vignette shows how to:

  1. Synthesize correlation matrices with mars
  2. Fit latent factor models using lavaan-style syntax in path_model()
library(mars)

Synthesize Correlations

becker09 <- na.omit(becker09)

model_out <- mars(
  data = becker09,
  studyID = "ID",
  effectID = "numID",
  sample_size = "N",
  effectsize_type = "cor",
  varcov_type = "weighted",
  variable_names = c(
    "Cognitive_Performance",
    "Somatic_Performance",
    "Selfconfidence_Performance",
    "Somatic_Cognitive",
    "Selfconfidence_Cognitive",
    "Selfconfidence_Somatic"
  )
)

summary(model_out)
#> Results generated with MARS:v 0.5.3 
#> Friday, July 17, 2026
#> 
#> Model Type: 
#> multivariate
#> 
#> Estimation Method: 
#> Restricted Maximum Likelihood
#> 
#> Model Formula: 
#> NULL
#> 
#> Data Summary: 
#> Number of Effect Sizes: 48
#> Number of Fixed Effects: 6
#> Number of Random Effects: 6
#> 
#> Random Components: 
#>          ri_1     ri_2     ri_3      ri_4      ri_5       ri_6
#> ri_1  0.13205  0.07631 -0.03146  0.003062 -0.018152  0.0022289
#> ri_2  0.99877  0.04420 -0.01699  0.001533 -0.009862  0.0008388
#> ri_3 -0.42101 -0.39300  0.04230 -0.007313  0.009632 -0.0122545
#> ri_4  0.23205  0.20075 -0.97922  0.001319 -0.001499  0.0022769
#> ri_5 -0.62516 -0.58706  0.58616 -0.516641  0.006384 -0.0024638
#> ri_6  0.09654  0.06279 -0.93778  0.986829 -0.485301  0.0040370
#> 
#> Fixed Effects Estimates: 
#>  attribute estimate      SE  z_test   p_value   lower     upper
#>          1 -0.09772 0.13777 -0.7093 4.781e-01 -0.3678  0.172310
#>          2 -0.17557 0.08620 -2.0367 4.168e-02 -0.3445 -0.006617
#>          3  0.31868 0.08407  3.7909 1.501e-04  0.1539  0.483451
#>          4  0.52720 0.03335 15.8069 2.786e-56  0.4618  0.592565
#>          5 -0.41756 0.04590 -9.0968 9.307e-20 -0.5075 -0.327592
#>          6 -0.40072 0.04182 -9.5817 9.543e-22 -0.4827 -0.318752
#> 
#> Model Fit Statistics: 
#>  logLik    Dev   AIC   BIC  AICc
#>   18.63 -37.25 16.75 63.67 29.48
#> 
#> Q Error: 230.642 (42), p < 0.0001
#> 
#> I2 (General): 
#>  names values
#>   ri_1  94.53
#>   ri_2  85.26
#>   ri_3  84.70
#>   ri_4  14.71
#>   ri_5  45.51
#>   ri_6  34.56
#> 
#> I2 (Jackson): 
#>  names values
#>   ri_1  90.98
#>   ri_2  77.93
#>   ri_3  81.33
#>   ri_4  16.14
#>   ri_5  43.25
#>   ri_6  31.43
#> 
#> I2 (Between): 83.3943
#> 
#> Residual Diagnostics: 
#>   n n_finite_raw mean_raw sd_raw   rmse    mae q_pearson mean_abs_studentized
#>  48           48 -0.02155 0.2127 0.2116 0.1646     133.5                1.419
#>  max_abs_studentized prop_abs_studentized_gt2 prop_abs_studentized_gt3
#>                5.006                   0.2708                   0.1042
#> 
#> Normality (whitened residuals):                   test n_tested statistic p_value
#>  shapiro_wilk_whitened       48    0.9789  0.5353
#> 
#> Heteroscedasticity trend (|raw residual| ~ fitted):   n corr_abs_raw_fitted     slope p_value
#>  48           -0.002888 -0.001089  0.9845

The synthesized (average) correlation matrix can be inspected directly:

R_hat <- corpcor::vec2sm(model_out$beta_r)
diag(R_hat) <- 1
R_hat
#>             [,1]        [,2]       [,3]       [,4]
#> [1,]  1.00000000 -0.09772205 -0.1755668  0.3186840
#> [2,] -0.09772205  1.00000000  0.5271958 -0.4175586
#> [3,] -0.17556678  0.52719585  1.0000000 -0.4007203
#> [4,]  0.31868398 -0.41755862 -0.4007203  1.0000000

One-Factor CFA

path_model() accepts lavaan-like latent syntax (for example, =~, ~~, ~).

model_cfa <- "
General =~ Performance + Cognitive + Somatic + Selfconfidence
"

fit_cfa <- path_model(
  mars_object = model_out,
  model = model_cfa
)

summary(fit_cfa)
#> Results generated with MARS:v 0.5.3 
#> Friday, July 17, 2026
#> 
#> Model Type: 
#> multivariate
#>  
#> Average Correlation Matrix: 
#>                Performance   Cognitive    Somatic Selfconfidence
#> Performance     1.00000000 -0.09772205 -0.1755668      0.3186840
#> Cognitive      -0.09772205  1.00000000  0.5271958     -0.4175586
#> Somatic        -0.17556678  0.52719585  1.0000000     -0.4007203
#> Selfconfidence  0.31868398 -0.41755862 -0.4007203      1.0000000
#> 
#> Synthesis options:
#>   method: model 
#>   transform: none 
#>   missing_corr: available 
#>   attenuation: none 
#>   pd_adjust: none 
#>   pd_adjusted: FALSE 
#>   min eigen (before/after): 0.4579 / 0.4579 
#>   SE note: Latent-model delta SEs are conditional on the synthesized correlation matrix and are not reported. Use se_method = "simulation" or "bootstrap" to propagate correlation uncertainty. 
#> 
#>  
#>  Model Fitted: 
#>  
#> General =~ Performance + Cognitive + Somatic + Selfconfidence
#>  
#>  
#> Fixed Effects: 
#>                           predictor        outcome  estimate standard_errors
#> General -> Performance      General    Performance  1.000000              NA
#> General -> Cognitive        General      Cognitive -2.667960              NA
#> General -> Somatic          General        Somatic -2.700978              NA
#> General -> Selfconfidence   General Selfconfidence  2.249672              NA
#>                           test_statistic p_value
#> General -> Performance                NA      NA
#> General -> Cognitive                  NA      NA
#> General -> Somatic                    NA      NA
#> General -> Selfconfidence             NA      NA
#> 
#>  
#>  Fit Statistics: 
#>                    Type         Value
#> 1      Model Chi-Square 37.633 (2), 0
#> 2 Null Model Chi-Square    393.32 (6)
#> 3                   CFI         0.908
#> 4                   TLI         0.724
#> 5                 RMSEA          <NA>
#> 6                  SRMR         0.059
#> 7             CFI (raw)         0.908
#> 8             TLI (raw)         0.724

Two-Factor Structural Model

This example adds structural regression between latent constructs.

model_sem <- "
Preparation =~ Cognitive + Selfconfidence
Execution =~ Performance + Somatic
Execution ~ Preparation
"

fit_sem <- path_model(
  mars_object = model_out,
  model = model_sem
)

summary(fit_sem)
#> Results generated with MARS:v 0.5.3 
#> Friday, July 17, 2026
#> 
#> Model Type: 
#> multivariate
#>  
#> Average Correlation Matrix: 
#>                Performance   Cognitive    Somatic Selfconfidence
#> Performance     1.00000000 -0.09772205 -0.1755668      0.3186840
#> Cognitive      -0.09772205  1.00000000  0.5271958     -0.4175586
#> Somatic        -0.17556678  0.52719585  1.0000000     -0.4007203
#> Selfconfidence  0.31868398 -0.41755862 -0.4007203      1.0000000
#> 
#> Synthesis options:
#>   method: model 
#>   transform: none 
#>   missing_corr: available 
#>   attenuation: none 
#>   pd_adjust: none 
#>   pd_adjusted: FALSE 
#>   min eigen (before/after): 0.4579 / 0.4579 
#>   SE note: Latent-model delta SEs are conditional on the synthesized correlation matrix and are not reported. Use se_method = "simulation" or "bootstrap" to propagate correlation uncertainty. 
#> 
#>  
#>  Model Fitted: 
#>  
#> Preparation =~ Cognitive + Selfconfidence
#> Execution =~ Performance + Somatic
#> Execution ~ Preparation
#>  
#>  
#> Fixed Effects: 
#>                                 predictor        outcome   estimate
#> Preparation -> Cognitive      Preparation      Cognitive  1.0000000
#> Preparation -> Selfconfidence Preparation Selfconfidence -0.8429965
#> Execution -> Performance        Execution    Performance  1.0000000
#> Execution -> Somatic            Execution        Somatic -2.7029709
#> Preparation -> Execution      Preparation      Execution -0.3744452
#>                               standard_errors test_statistic p_value
#> Preparation -> Cognitive                   NA             NA      NA
#> Preparation -> Selfconfidence              NA             NA      NA
#> Execution -> Performance                   NA             NA      NA
#> Execution -> Somatic                       NA             NA      NA
#> Preparation -> Execution                   NA             NA      NA
#> 
#>  
#>  Fit Statistics: 
#>                    Type         Value
#> 1      Model Chi-Square 37.646 (1), 0
#> 2 Null Model Chi-Square    393.32 (6)
#> 3                   CFI         0.905
#> 4                   TLI         0.432
#> 5                 RMSEA          <NA>
#> 6                  SRMR         0.059
#> 7             CFI (raw)         0.905
#> 8             TLI (raw)         0.432

This workflow supports latent factor analysis after the correlation synthesis step, while keeping model fitting inside MARS.