cormat <- '
1.00
-.03 1.00
.39  .07 1.00
-.05 -.23 -.13 1.00
-.08 -.16 -.29 .34 1.00'

Cmat <- getCov(cormat)

dat.sdev <- c(66.50,3.80,18.40,6.70,62.48)

Dmat <- diag(dat.sdev)
covmat <- Dmat %*% Cmat %*% Dmat

# assign row and column names to the covariance matrix
rownames(covmat) <- c("Exercise", "Hardy", "Fitness", "Stress", "Illness")
colnames(covmat) <- rownames(covmat)

path.model <- '
Illness~Fitness+Stress
Fitness~Exercise
Stress~Hardy
Exercise~~Hardy
'

path.fit <- sem(path.model, sample.cov = covmat, sample.nobs = 373)
summary(path.fit, fit.measures = T, standardized = T)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations                           373
## 
## Model Test User Model:
##                                                       
##   Test statistic                                11.107
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.049
## 
## Model Test Baseline Model:
## 
##   Test statistic                               165.944
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.961
##   Tucker-Lewis Index (TLI)                       0.922
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7968.001
##   Loglikelihood unrestricted model (H1)      -7962.447
##                                                       
##   Akaike (AIC)                               15956.002
##   Bayesian (BIC)                             15995.218
##   Sample-size adjusted Bayesian (SABIC)      15963.491
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.057
##   90 Percent confidence interval - lower         0.003
##   90 Percent confidence interval - upper         0.103
##   P-value H_0: RMSEA <= 0.050                    0.336
##   P-value H_0: RMSEA >= 0.080                    0.236
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.051
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Illness ~                                                             
##     Fitness          -0.849    0.159   -5.323    0.000   -0.849   -0.253
##     Stress            2.868    0.438    6.546    0.000    2.868    0.311
##   Fitness ~                                                             
##     Exercise          0.108    0.013    8.180    0.000    0.108    0.390
##   Stress ~                                                              
##     Hardy            -0.406    0.089   -4.564    0.000   -0.406   -0.230
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Exercise ~~                                                           
##     Hardy            -7.561   13.055   -0.579    0.562   -7.561   -0.030
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .Illness        3203.954  234.610   13.657    0.000 3203.954    0.840
##    .Fitness         286.295   20.964   13.657    0.000  286.295    0.848
##    .Stress           42.401    3.105   13.657    0.000   42.401    0.947
##     Exercise       4410.394  322.952   13.657    0.000 4410.394    1.000
##     Hardy            14.401    1.055   13.657    0.000   14.401    1.000

© Copyright 2024 @Yi Feng and @Gregory R. Hancock.