SEM Notebook Assignment

Author

Seunghee Im

### DATA PREPRATION ###
library(lavaan)
This is lavaan 0.6-19
lavaan is FREE software! Please report any bugs.
dat <- read.csv("https://stats.idre.ucla.edu/wp-content/uploads/2021/02/worland5.csv")
#sample variance-covariance matrix 
cov(dat)
       motiv harm stabi ppsych ses verbal read arith spell
motiv    100   77    59    -25  25     32   53    60    59
harm      77  100    58    -25  26     25   42    44    45
stabi     59   58   100    -16  18     27   36    38    38
ppsych   -25  -25   -16    100 -42    -40  -39   -24   -31
ses       25   26    18    -42 100     40   43    37    33
verbal    32   25    27    -40  40    100   56    49    48
read      53   42    36    -39  43     56  100    73    87
arith     60   44    38    -24  37     49   73   100    72
spell     59   45    38    -31  33     48   87    72   100
### MODEL 1: SIMPLE REGRESSION ###

#simple regression using lm() 
m1a <- lm(read ~ motiv, data=dat)
(fit1a <-summary(m1a))

Call:
lm(formula = read ~ motiv, data = dat)

Residuals:
     Min       1Q   Median       3Q      Max 
-26.0995  -6.1109   0.2342   5.2237  24.0183 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.232e-07  3.796e-01    0.00        1    
motiv        5.300e-01  3.800e-02   13.95   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 8.488 on 498 degrees of freedom
Multiple R-squared:  0.2809,    Adjusted R-squared:  0.2795 
F-statistic: 194.5 on 1 and 498 DF,  p-value: < 2.2e-16
### MODELS 1 AND 2: REGRESSION ###
#simple regression using lavaan
m1b <-   '
  # regressions
  # regressions
    read ~ 1 + motiv
  # variance (optional)
  motiv ~~ motiv
'
fit1b <- sem(m1b, data=dat)
summary(fit1b)
lavaan 0.6-19 ended normally after 8 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         5

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    motiv             0.530    0.038   13.975    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             -0.000    0.379   -0.000    1.000
    motiv             0.000    0.447    0.000    1.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    motiv            99.800    6.312   15.811    0.000
   .read             71.766    4.539   15.811    0.000
#obtain sample mean and variance
mean(dat$motiv)
[1] 2.4e-07
var(dat$motiv)
[1] 100
# 4. Multivariate Regression removing residual covariance (Model 3D)
m3d <- '
  read ~ 1 + ppsych + motiv
  arith ~ 1 + motiv
  read ~~ 0*arith  # fix residual covariance to zero
'
fit3d <- sem(m3d, data=dat)
summary(fit3d)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         7

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                               234.960
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    motiv             0.600    0.036   16.771    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
 .read ~~                                             
   .arith             0.000                           

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             -0.000    0.360   -0.000    1.000
   .arith            -0.000    0.357   -0.000    1.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
   .arith            63.872    4.040   15.811    0.000
#convert least squares to maximum likelihood
498/500*(fit1a$sigma)**2
[1] 71.76618
#multiple regression
m2 <- '
  # regressions
    read ~ 1 + ppsych + motiv
    #covariance
    #ppsych ~~ motiv
'
fit2 <- sem(m2, data=dat)
summary(fit2)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         4

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             -0.000    0.360   -0.000    1.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
### MODEL 3:  MULTIVARIATE REGRESSION ###

#multivariate regression (default)
m3a <- '
  # regressions
    read ~ ppsych + motiv
    arith ~ motiv
'
fit3a <- sem(m3a, data=dat)
summary(fit3a)
lavaan 0.6-19 ended normally after 17 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         6

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 6.796
  Degrees of freedom                                 1
  P-value (Chi-square)                           0.009

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.216    0.030   -7.289    0.000
    motiv             0.476    0.037   12.918    0.000
  arith ~                                             
    motiv             0.600    0.036   16.771    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
 .read ~~                                             
   .arith            39.179    3.373   11.615    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             65.032    4.113   15.811    0.000
   .arith            63.872    4.040   15.811    0.000
inspect(fit3a,"partable")
$lambda
       read arith ppsych motiv
read      0     0      0     0
arith     0     0      0     0
ppsych    0     0      0     0
motiv     0     0      0     0

$theta
       read arith ppsych motiv
read      0                   
arith     0     0             
ppsych    0     0      0      
motiv     0     0      0     0

$psi
       read arith ppsych motiv
read      4                   
arith     6     5             
ppsych    0     0      7      
motiv     0     0      8     9

$beta
       read arith ppsych motiv
read      0     0      1     2
arith     0     0      0     3
ppsych    0     0      0     0
motiv     0     0      0     0
#regression of read on psych and motiv
m3b <- lm(read ~ ppsych + motiv, data=dat)
(fit3b <- summary(m3b))

Call:
lm(formula = read ~ ppsych + motiv, data = dat)

Residuals:
     Min       1Q   Median       3Q      Max 
-21.7734  -5.5633   0.1389   5.3662  25.8209 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.336e-07  3.608e-01   0.000        1    
ppsych      -2.747e-01  3.730e-02  -7.363 7.51e-13 ***
motiv        4.613e-01  3.730e-02  12.367  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 8.068 on 497 degrees of freedom
Multiple R-squared:  0.3516,    Adjusted R-squared:  0.349 
F-statistic: 134.8 on 2 and 497 DF,  p-value: < 2.2e-16
#regression of arith on motiv
m3c <- lm(arith ~ motiv, data=dat)
(fit3c <- summary(m3c))

Call:
lm(formula = arith ~ motiv, data = dat)

Residuals:
    Min      1Q  Median      3Q     Max 
-23.633  -5.341  -0.214   5.106  21.271 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -5.400e-08  3.581e-01    0.00        1    
motiv        6.000e-01  3.585e-02   16.74   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 8.008 on 498 degrees of freedom
Multiple R-squared:   0.36, Adjusted R-squared:  0.3587 
F-statistic: 280.1 on 1 and 498 DF,  p-value: < 2.2e-16
#multivariate regression (set covariance to 0)
m3d <- '
  # regressions
    read ~ ppsych + motiv
    arith ~  motiv
  # covariance
   read ~~ 0*arith 
'
fit3d <- sem(m3d, data=dat)
summary(fit3d)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         5

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                               234.960
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    motiv             0.600    0.036   16.771    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
 .read ~~                                             
   .arith             0.000                           

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
   .arith            63.872    4.040   15.811    0.000
#known values
cov(dat[,c("read","arith","ppsych","motiv")])
       read arith ppsych motiv
read    100    73    -39    53
arith    73   100    -24    60
ppsych  -39   -24    100   -25
motiv    53    60    -25   100
#multivariate regression (saturated model)
m3e <- '
  # regressions
    read ~ ppsych + motiv
    arith ~ ppsych + motiv
    #covariance
    ppsych ~~ motiv
    ppsych ~~ ppsych
    motiv ~~ motiv
'
fit3e <- sem(m3e, data=dat)
summary(fit3e)
lavaan 0.6-19 ended normally after 41 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        10

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    ppsych           -0.096    0.037   -2.616    0.009
    motiv             0.576    0.037   15.695    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  ppsych ~~                                           
    motiv           -24.950    4.601   -5.423    0.000
 .read ~~                                             
   .arith            38.651    3.338   11.579    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    ppsych           99.800    6.312   15.811    0.000
    motiv            99.800    6.312   15.811    0.000
   .read             64.708    4.092   15.811    0.000
   .arith            63.010    3.985   15.811    0.000
#inspect(fit3e,"partable")
### MODEL 4:  PATH ANALYSIS ###

#path analysis model 
m4a <- '
  # regressions
    read ~ ppsych + motiv
    arith ~ motiv + read
  # covariance
  #  read ~~ 0*arith 
'
fit4a <- sem(m4a, data=dat)
summary(fit4a)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         6

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 4.870
  Degrees of freedom                                 1
  P-value (Chi-square)                           0.027

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    motiv             0.296    0.034    8.841    0.000
    read              0.573    0.034   17.093    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
   .arith            40.314    2.550   15.811    0.000
#re-run with fit indexes
summary(fit4a, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         6

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 4.870
  Degrees of freedom                                 1
  P-value (Chi-square)                           0.027

Model Test Baseline Model:

  Test statistic                               674.748
  Degrees of freedom                                 5
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.994
  Tucker-Lewis Index (TLI)                       0.971

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3385.584
  Loglikelihood unrestricted model (H1)      -3383.149
                                                      
  Akaike (AIC)                                6783.168
  Bayesian (BIC)                              6808.456
  Sample-size adjusted Bayesian (SABIC)       6789.411

Root Mean Square Error of Approximation:

  RMSEA                                          0.088
  90 Percent confidence interval - lower         0.024
  90 Percent confidence interval - upper         0.172
  P-value H_0: RMSEA <= 0.050                    0.139
  P-value H_0: RMSEA >= 0.080                    0.662

Standardized Root Mean Square Residual:

  SRMR                                           0.018

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    motiv             0.296    0.034    8.841    0.000
    read              0.573    0.034   17.093    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
   .arith            40.314    2.550   15.811    0.000
#model chi-square 
pchisq(q=4.870,df=1,lower.tail=FALSE)
[1] 0.0273275
#modification index
modindices(fit4a,sort=TRUE)
      lhs op    rhs     mi    epc sepc.lv sepc.all sepc.nox
17  motiv  ~  arith 68.073  8.874   8.874    8.874    8.874
10   read ~~  arith  4.847 16.034  16.034    0.314    0.314
12  arith  ~ ppsych  4.847  0.068   0.068    0.068    0.007
11   read  ~  arith  4.847  0.398   0.398    0.398    0.398
14 ppsych  ~  arith  2.188  0.071   0.071    0.071    0.071
16  motiv  ~   read  0.000  0.000   0.000    0.000    0.000
18  motiv  ~ ppsych  0.000  0.000   0.000    0.000    0.000
13 ppsych  ~   read  0.000  0.000   0.000    0.000    0.000
8  ppsych ~~  motiv  0.000  0.000   0.000       NA    0.000
15 ppsych  ~  motiv  0.000  0.000   0.000    0.000    0.000
## model4a customized for degrees of freedom
m4aa <- '
  # regressions
    read ~ 1 + ppsych + motiv
    motiv ~ 1 + arith + read
  # covariance
  #  read ~~ 0*arith 
'
fit4aa <- sem(m4aa, data=dat)
summary(fit4aa)
lavaan 0.6-19 ended normally after 26 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         8

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                55.114
  Degrees of freedom                                 1
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.108    0.047   -2.322    0.020
    motiv             1.127    0.075   15.035    0.000
  motiv ~                                             
    arith             1.864    0.197    9.483    0.000
    read             -1.732    0.256   -6.775    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             -0.000    0.461   -0.000    1.000
   .motiv             0.000    0.686    0.000    1.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read            106.183   11.504    9.230    0.000
   .motiv           235.494   48.319    4.874    0.000
#path analysis model after modification
m4b <- '
  # regressions
    read ~ ppsych + motiv
    arith ~ motiv + read + ppsych
'
fit4b <- sem(m4b, data=dat)
summary(fit4b)
lavaan 0.6-19 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         7

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  read ~                                              
    ppsych           -0.275    0.037   -7.385    0.000
    motiv             0.461    0.037   12.404    0.000
  arith ~                                             
    motiv             0.300    0.033    8.993    0.000
    read              0.597    0.035   17.004    0.000
    ppsych            0.068    0.031    2.212    0.027

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read             64.708    4.092   15.811    0.000
   .arith            39.923    2.525   15.811    0.000
modindices(fit4b,sort=TRUE)
[1] lhs      op       rhs      mi       epc      sepc.lv  sepc.all sepc.nox
<0 rows> (or 0-length row.names)
#baseline model
m4c <- '
  # variances only
    read ~~ read 
    ppsych ~~ ppsych
    motiv ~~ motiv
    arith ~~ arith
'
fit4c <- sem(m4c, data=dat)
summary(fit4c, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 8 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         4

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                               707.017
  Degrees of freedom                                 6
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               707.017
  Degrees of freedom                                 6
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.000
  Tucker-Lewis Index (TLI)                       0.000

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -7441.045
  Loglikelihood unrestricted model (H1)      -7087.537
                                                      
  Akaike (AIC)                               14890.091
  Bayesian (BIC)                             14906.949
  Sample-size adjusted Bayesian (SABIC)      14894.253

Root Mean Square Error of Approximation:

  RMSEA                                          0.483
  90 Percent confidence interval - lower         0.454
  90 Percent confidence interval - upper         0.514
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.380

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    read             99.800    6.312   15.811    0.000
    ppsych           99.800    6.312   15.811    0.000
    motiv            99.800    6.312   15.811    0.000
    arith            99.800    6.312   15.811    0.000
### MODEL 5:  MEASUREMENT MODEL ###

#exogenous factor analysis for adjust
m5a <- 'risk =~ verbal + ses + ppsych
          #intercepts (nu = tau) 
          verbal ~ 1
          ses ~ 1 
          ppsych ~ 1' 
fit5a <- sem(m5a, data=dat) 
summary(fit5a, standardized=TRUE)
lavaan 0.6-19 ended normally after 37 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         9

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  risk =~                                                               
    verbal            1.000                               6.166    0.617
    ses               1.050    0.126    8.358    0.000    6.474    0.648
    ppsych           -1.050    0.126   -8.358    0.000   -6.474   -0.648

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .verbal            0.000    0.447    0.000    1.000    0.000    0.000
   .ses              -0.000    0.447   -0.000    1.000   -0.000   -0.000
   .ppsych           -0.000    0.447   -0.000    1.000   -0.000   -0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .verbal           61.781    5.810   10.634    0.000   61.781    0.619
   .ses              57.884    5.989    9.664    0.000   57.884    0.580
   .ppsych           57.884    5.989    9.664    0.000   57.884    0.580
    risk             38.019    6.562    5.794    0.000    1.000    1.000
### MODEL 6: STRUCTURAL REGRESSION ###

#structural regression (one endogenous variable)
m6a <- '
  # measurement model
    adjust =~ motiv + harm + stabi
    risk =~ verbal + ppsych + ses
    achieve =~ read + arith + spell
  # regressions
    achieve ~ adjust + risk
'
fit6a <- sem(m6a, data=dat)
summary(fit6a, standardized=TRUE, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 130 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                               148.982
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              2597.972
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.951
  Tucker-Lewis Index (TLI)                       0.927

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -15517.857
  Loglikelihood unrestricted model (H1)     -15443.366
                                                      
  Akaike (AIC)                               31077.713
  Bayesian (BIC)                             31166.220
  Sample-size adjusted Bayesian (SABIC)      31099.565

Root Mean Square Error of Approximation:

  RMSEA                                          0.102
  90 Percent confidence interval - lower         0.087
  90 Percent confidence interval - upper         0.118
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.990

Standardized Root Mean Square Residual:

  SRMR                                           0.041

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust =~                                                             
    motiv             1.000                               9.324    0.933
    harm              0.884    0.041   21.774    0.000    8.246    0.825
    stabi             0.695    0.043   15.987    0.000    6.478    0.648
  risk =~                                                               
    verbal            1.000                               7.319    0.733
    ppsych           -0.770    0.075  -10.223    0.000   -5.636   -0.564
    ses               0.807    0.076   10.607    0.000    5.906    0.591
  achieve =~                                                            
    read              1.000                               9.404    0.941
    arith             0.837    0.034   24.437    0.000    7.873    0.788
    spell             0.976    0.028   34.338    0.000    9.178    0.919

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  achieve ~                                                             
    adjust            0.375    0.046    8.085    0.000    0.372    0.372
    risk              0.724    0.078    9.253    0.000    0.564    0.564

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust ~~                                                             
    risk             32.098    4.320    7.431    0.000    0.470    0.470

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .motiv            12.870    2.852    4.512    0.000   12.870    0.129
   .harm             31.805    2.973   10.698    0.000   31.805    0.319
   .stabi            57.836    3.990   14.494    0.000   57.836    0.580
   .verbal           46.239    4.788    9.658    0.000   46.239    0.463
   .ppsych           68.033    5.068   13.425    0.000   68.033    0.682
   .ses              64.916    4.975   13.048    0.000   64.916    0.650
   .read             11.372    1.608    7.074    0.000   11.372    0.114
   .arith            37.818    2.680   14.109    0.000   37.818    0.379
   .spell            15.560    1.699    9.160    0.000   15.560    0.156
    adjust           86.930    6.830   12.727    0.000    1.000    1.000
    risk             53.561    6.757    7.927    0.000    1.000    1.000
   .achieve          30.685    3.449    8.896    0.000    0.347    0.347
#structural regression (two endogenous variables)
m6b <- '
  # measurement model
    adjust =~ motiv + harm + stabi
    risk =~ verbal + ses + ppsych
    achieve =~ read + arith + spell
  # regressions
    adjust ~ risk 
    achieve ~ adjust + risk
'
fit6b <- sem(m6b, data=dat)
summary(fit6b, standardized=TRUE, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 112 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                               148.982
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              2597.972
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.951
  Tucker-Lewis Index (TLI)                       0.927

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -15517.857
  Loglikelihood unrestricted model (H1)     -15443.366
                                                      
  Akaike (AIC)                               31077.713
  Bayesian (BIC)                             31166.220
  Sample-size adjusted Bayesian (SABIC)      31099.565

Root Mean Square Error of Approximation:

  RMSEA                                          0.102
  90 Percent confidence interval - lower         0.087
  90 Percent confidence interval - upper         0.118
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.990

Standardized Root Mean Square Residual:

  SRMR                                           0.041

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust =~                                                             
    motiv             1.000                               9.324    0.933
    harm              0.884    0.041   21.774    0.000    8.246    0.825
    stabi             0.695    0.043   15.987    0.000    6.478    0.648
  risk =~                                                               
    verbal            1.000                               7.319    0.733
    ses               0.807    0.076   10.607    0.000    5.906    0.591
    ppsych           -0.770    0.075  -10.223    0.000   -5.636   -0.564
  achieve =~                                                            
    read              1.000                               9.404    0.941
    arith             0.837    0.034   24.437    0.000    7.873    0.788
    spell             0.976    0.028   34.338    0.000    9.178    0.919

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust ~                                                              
    risk              0.599    0.076    7.837    0.000    0.470    0.470
  achieve ~                                                             
    adjust            0.375    0.046    8.085    0.000    0.372    0.372
    risk              0.724    0.078    9.253    0.000    0.564    0.564

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .motiv            12.870    2.852    4.512    0.000   12.870    0.129
   .harm             31.805    2.973   10.698    0.000   31.805    0.319
   .stabi            57.836    3.990   14.494    0.000   57.836    0.580
   .verbal           46.239    4.788    9.658    0.000   46.239    0.463
   .ses              64.916    4.975   13.048    0.000   64.916    0.650
   .ppsych           68.033    5.068   13.425    0.000   68.033    0.682
   .read             11.372    1.608    7.074    0.000   11.372    0.114
   .arith            37.818    2.680   14.109    0.000   37.818    0.379
   .spell            15.560    1.699    9.160    0.000   15.560    0.156
   .adjust           67.694    6.066   11.160    0.000    0.779    0.779
    risk             53.561    6.757    7.927    0.000    1.000    1.000
   .achieve          30.685    3.449    8.896    0.000    0.347    0.347
#structural regression (observed endogenous variable)
m6c <- '
  # measurement model
    adjust =~ motiv + harm + stabi
    risk =~ verbal + ses + ppsych
  # regressions
    adjust ~ risk 
    read ~ adjust + risk
'
fit6c <- sem(m6c, data=dat)
summary(fit6c, standardized=TRUE, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 105 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        16

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                35.555
  Degrees of freedom                                12
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              1339.008
  Degrees of freedom                                21
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.982
  Tucker-Lewis Index (TLI)                       0.969

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -12370.103
  Loglikelihood unrestricted model (H1)     -12352.325
                                                      
  Akaike (AIC)                               24772.206
  Bayesian (BIC)                             24839.640
  Sample-size adjusted Bayesian (SABIC)      24788.855

Root Mean Square Error of Approximation:

  RMSEA                                          0.063
  90 Percent confidence interval - lower         0.039
  90 Percent confidence interval - upper         0.087
  P-value H_0: RMSEA <= 0.050                    0.170
  P-value H_0: RMSEA >= 0.080                    0.127

Standardized Root Mean Square Residual:

  SRMR                                           0.025

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust =~                                                             
    motiv             1.000                               9.172    0.918
    harm              0.914    0.043   21.334    0.000    8.379    0.839
    stabi             0.716    0.045   16.025    0.000    6.569    0.658
  risk =~                                                               
    verbal            1.000                               7.208    0.722
    ses               0.829    0.076   10.848    0.000    5.973    0.598
    ppsych           -0.794    0.076  -10.486    0.000   -5.726   -0.573

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  adjust ~                                                              
    risk              0.604    0.077    7.834    0.000    0.474    0.474
  read ~                                                                
    adjust            0.285    0.050    5.658    0.000    2.610    0.261
    risk              0.853    0.087    9.824    0.000    6.147    0.615

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .motiv            15.676    2.982    5.257    0.000   15.676    0.157
   .harm             29.595    3.030    9.767    0.000   29.595    0.297
   .stabi            56.650    3.960   14.307    0.000   56.650    0.568
   .verbal           47.846    4.666   10.254    0.000   47.846    0.479
   .ses              64.125    4.903   13.078    0.000   64.125    0.643
   .ppsych           67.008    4.993   13.421    0.000   67.008    0.671
   .read             39.974    3.823   10.456    0.000   39.974    0.401
   .adjust           65.185    6.022   10.824    0.000    0.775    0.775
    risk             51.954    6.580    7.895    0.000    1.000    1.000
#inspect(fit6c,"partable")
#model6c (manual specification) 
m6cc <- '
  # measurement model
    adjust =~ motiv + harm + stabi
    risk =~ verbal + ses + ppsych
  #single indicator factor
    readf =~ 1*read
  #residuel variance to zero
    read ~~ 0*read
  # regressions
    adjust ~ risk 
    readf ~ adjust + risk
'
fit6cc <- sem(m6cc, data=dat, optim.method=list("BFGS"))
summary(fit6cc)
lavaan 0.6-19 ended normally after 2153 iterations

  Estimator                                         ML
  Optimization method                             BFGS
  Number of model parameters                        16

  Number of observations                           500

Model Test User Model:
                                                      
  Test statistic                                35.585
  Degrees of freedom                                12
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  adjust =~                                           
    motiv             1.000                           
    harm              0.914    0.043   21.345    0.000
    stabi             0.717    0.045   16.043    0.000
  risk =~                                             
    verbal            1.000                           
    ses               0.834    0.077   10.876    0.000
    ppsych           -0.799    0.076  -10.518    0.000
  readf =~                                            
    read              1.000                           

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  adjust ~                                            
    risk              0.605    0.077    7.832    0.000
  readf ~                                             
    adjust            0.285    0.050    5.671    0.000
    risk              0.854    0.087    9.822    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .read              0.000                           
   .motiv            15.752    2.980    5.286    0.000
   .harm             29.529    3.028    9.752    0.000
   .stabi            56.536    3.953   14.301    0.000
   .verbal           48.246    4.669   10.334    0.000
   .ses              63.580    4.879   13.032    0.000
   .ppsych           66.414    4.964   13.380    0.000
   .adjust           65.143    6.019   10.822    0.000
    risk             51.680    6.566    7.871    0.000
   .readf            40.060    3.820   10.486    0.000
#inspect(fit6cc,"partable")