How to set residual covariances in the SEM model?

763 views
Skip to first unread message

luquany...@gmail.com

unread,
May 5, 2016, 6:57:39 AM5/5/16
to lavaan
We I set the residual covariances, I find that different residual covariances setting will lead to different results.
I don not know how to set this part. If I delet this part, the results will also change.
library(lavaan)
x<-read.csv("C:/Users/Quanying LU/Desktop/5.csv")
> co2model<-'
+ # measurement model
+ co2=~y1
+ total=~y2+y3+y4+y5+y6
+ struct=~y7+y8+y9+y10
+ # regressions
+ co2~total+struct
+ total~struct
+ # residual covariances
+ y2~~y3+y4+y5+y6+y7+y8+y9+y10
+ y3 ~~ y4+y7+y9
+ y5 ~~ y4+y7+y8+y9
+ y6 ~~ y4+y7+y8+y9
+ y7~~y4
+ '
> fit <- sem(co2model, data = x,meanstructure = "default",
+            conditional.x = "default", fixed.x = "default",
+            orthogonal = FALSE, std.lv = FALSE,
+            parameterization = "default", std.ov = FALSE,
+            missing = "default", ordered = NULL,
+            sample.cov = NULL, sample.cov.rescale = "default",
+            sample.mean = NULL, sample.nobs = NULL,
+            ridge = 1e-05, group = NULL,
+            group.label = NULL, group.equal = "", group.partial = "",
+            group.w.free = FALSE, cluster = NULL, constraints = '',
+            estimator = "default", likelihood = "default", link = "default",
+            information = "default", se = "default", test = "default",
+            bootstrap = 1000L, mimic = "default", representation = "default",
+            do.fit = TRUE, control = list(), WLS.V = NULL, NACOV = NULL,
+            zero.add = "default", zero.keep.margins = "default",zero.cell.warn = TRUE,
+            start = "default", verbose = FALSE, warn = TRUE, debug = FALSE)
Warning messages:
1: In lav_object_post_check(lavobject) :
  lavaan WARNING: some estimated variances are negative
2: In lav_object_post_check(lavobject) :
  lavaan WARNING: covariance matrix of latent variables is not positive definite; use inspect(fit,"cov.lv") to investigate.
3: In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.
> summary(fit, standardized = TRUE)
lavaan (0.5-20) converged normally after 444 iterations

  Number of observations                            27

  Estimator                                         ML
  Minimum Function Test Statistic               71.870
  Degrees of freedom                                13
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Information                                 Expected
  Standard Errors                             Standard

Latent Variables:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 =~                                                                
    y1                1.000                               0.863    1.000
  total =~                                                              
    y2                1.000                               0.744    0.974
    y3                0.093    0.003   28.033    0.000    0.069    0.966
    y4                1.544    0.040   38.915    0.000    1.149    0.974
    y5                1.064    0.085   12.521    0.000    0.792    0.914
    y6                0.655    0.041   16.166    0.000    0.487    0.952
  struct =~                                                             
    y7                1.000                               0.244    0.998
    y8                0.195    0.059    3.327    0.001    0.047    0.521
    y9                2.784    0.079   35.086    0.000    0.679    0.991
    y10              -1.060    0.058  -18.176    0.000   -0.259   -0.962

Regressions:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 ~                                                                 
    total             0.630    0.146    4.319    0.000    0.544    0.544
    struct            1.571    0.449    3.497    0.000    0.444    0.444
  total ~                                                               
    struct            3.118    0.144   21.684    0.000    1.022    1.022

Covariances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  y2 ~~                                                                 
    y3                0.002    0.001    3.680    0.000    0.002    0.729
    y4                0.038    0.009    4.221    0.000    0.038    0.832
    y5                0.021    0.006    3.798    0.000    0.021    0.352
    y6                0.009    0.002    3.519    0.000    0.009    0.318
    y7               -0.004    0.001   -4.050    0.000   -0.004   -1.692
    y8               -0.001    0.001   -1.265    0.206   -0.001   -0.072
    y9               -0.004    0.001   -2.996    0.003   -0.004   -0.255
    y10              -0.005    0.001   -3.929    0.000   -0.005   -0.366
  y3 ~~                                                                 
    y4                0.004    0.001    3.921    0.000    0.004    0.855
    y7               -0.000    0.000   -4.410    0.000   -0.000   -1.620
    y9                0.000    0.000    2.653    0.008    0.000    0.282
  y4 ~~                                                                 
    y5                0.028    0.009    3.162    0.002    0.028    0.299
  y5 ~~                                                                 
    y7               -0.002    0.002   -1.547    0.122   -0.002   -0.485
    y8                0.010    0.003    3.037    0.002    0.010    0.384
    y9               -0.016    0.004   -3.668    0.000   -0.016   -0.503
  y4 ~~                                                                 
    y6                0.007    0.003    2.539    0.011    0.007    0.172
  y6 ~~                                                                 
    y7               -0.003    0.001   -3.317    0.001   -0.003   -1.159
    y8               -0.009    0.002   -3.677    0.000   -0.009   -0.756
    y9               -0.008    0.002   -3.574    0.000   -0.008   -0.583
  y4 ~~                                                                 
    y7               -0.006    0.002   -4.079    0.000   -0.006   -1.731

Variances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    y1                0.000                               0.000    0.000
    y2                0.030    0.007    4.443    0.000    0.030    0.051
    y3                0.000    0.000    3.899    0.000    0.000    0.066
    y4                0.070    0.015    4.562    0.000    0.070    0.051
    y5                0.123    0.030    4.082    0.000    0.123    0.164
    y6                0.024    0.007    3.660    0.000    0.024    0.093
    y7                0.000    0.000    1.878    0.060    0.000    0.003
    y8                0.006    0.001    4.063    0.000    0.006    0.729
    y9                0.009    0.002    4.547    0.000    0.009    0.019
    y10               0.005    0.001    4.521    0.000    0.005    0.074
    co2               0.011    0.004    2.870    0.004    0.014    0.014
    total            -0.024    0.007   -3.360    0.001   -0.044   -0.044
    struct            0.059    0.016    3.662    0.000    1.000    1.000


> library(lavaan)
> x<-read.csv("C:/Users/Quanying LU/Desktop/5.csv")
> co2model<-'
+ # measurement model
+ co2=~y1
+ total=~y2+y3+y4+y5+y6
+ struct=~y7+y8+y9+y10
+ # regressions
+ co2~total+struct
+ total~struct
+ # residual covariances
+ y2~~y3+y4+y5+y6+y7+y8+y9+y10
+ y3 ~~ y4+y7
+ y5 ~~ y7+y8+y9
+ y6~~y7+y8+y9
+ y9~~y4'
> fit <- sem(co2model, data = x,meanstructure = "default",
+            conditional.x = "default", fixed.x = "default",
+            orthogonal = FALSE, std.lv = FALSE,
+            parameterization = "default", std.ov = FALSE,
+            missing = "default", ordered = NULL,
+            sample.cov = NULL, sample.cov.rescale = "default",
+            sample.mean = NULL, sample.nobs = NULL,
+            ridge = 1e-05,group = NULL,
+            group.label = NULL, group.equal = "", group.partial = "",
+            group.w.free = FALSE, cluster = NULL, constraints = '',
+            estimator = "default", likelihood = "default", link = "default",
+            information = "default", se = "default", test = "default",
+            bootstrap = 1000L, mimic = "default", representation = "default",
+            do.fit = TRUE, control = list(), WLS.V = NULL, NACOV = NULL,
+            zero.add = "default", zero.keep.margins = "default",zero.cell.warn = TRUE,
+            start = "default", verbose = FALSE, warn = TRUE, debug = FALSE)
Warning messages:
1: In lav_object_post_check(lavobject) :
  lavaan WARNING: some estimated variances are negative
2: In lav_object_post_check(lavobject) :
  lavaan WARNING: covariance matrix of latent variables is not positive definite; use inspect(fit,"cov.lv") to investigate.
3: In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.
> summary(fit, standardized = TRUE)
lavaan (0.5-20) converged normally after 481 iterations

  Number of observations                            27

  Estimator                                         ML
  Minimum Function Test Statistic              121.532
  Degrees of freedom                                16
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Information                                 Expected
  Standard Errors                             Standard

Latent Variables:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 =~                                                                
    y1                1.000                               0.863    1.000
  total =~                                                              
    y2                1.000                               0.746    0.981
    y3                0.094    0.003   31.389    0.000    0.070    0.978
    y4                1.524    0.061   24.967    0.000    1.136    0.968
    y5                1.054    0.089   11.877    0.000    0.786    0.909
    y6                0.654    0.038   17.081    0.000    0.487    0.957
  struct =~                                                             
    y7                1.000                               0.242    0.996
    y8                0.196    0.058    3.400    0.001    0.047    0.538
    y9                2.822    0.074   38.310    0.000    0.682    0.995
    y10              -1.071    0.060  -17.816    0.000   -0.259   -0.963

Regressions:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 ~                                                                 
    total             0.549    0.145    3.797    0.000    0.475    0.475
    struct            1.831    0.448    4.085    0.000    0.513    0.513
  total ~                                                               
    struct            3.137    0.132   23.853    0.000    1.017    1.017

Covariances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  y2 ~~                                                                 
    y3                0.002    0.000    3.291    0.001    0.002    0.678
    y4                0.027    0.009    3.041    0.002    0.027    0.612
    y5                0.016    0.005    3.339    0.001    0.016    0.302
    y6                0.007    0.002    3.211    0.001    0.007    0.302
    y7               -0.003    0.001   -4.815    0.000   -0.003   -0.932
    y8               -0.001    0.001   -1.036    0.300   -0.001   -0.071
    y9               -0.004    0.001   -3.359    0.001   -0.004   -0.434
    y10              -0.004    0.001   -3.778    0.000   -0.004   -0.393
  y3 ~~                                                                 
    y4                0.002    0.001    2.417    0.016    0.002    0.513
    y7               -0.000    0.000   -4.909    0.000   -0.000   -1.266
  y5 ~~                                                                 
    y7               -0.004    0.001   -3.114    0.002   -0.004   -0.558
    y8                0.011    0.004    2.865    0.004    0.011    0.422
    y9               -0.019    0.005   -4.097    0.000   -0.019   -0.750
  y6 ~~                                                                 
    y7               -0.003    0.001   -4.324    0.000   -0.003   -0.928
    y8               -0.008    0.002   -3.446    0.001   -0.008   -0.732
    y9               -0.009    0.002   -3.770    0.000   -0.009   -0.869
  y4 ~~                                                                 
    y9                0.005    0.003    1.629    0.103    0.005    0.235

Variances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    y1                0.000                               0.000    0.000
    y2                0.022    0.005    4.058    0.000    0.022    0.038
    y3                0.000    0.000    4.068    0.000    0.000    0.044
    y4                0.088    0.022    3.943    0.000    0.088    0.064
    y5                0.130    0.033    3.897    0.000    0.130    0.174
    y6                0.022    0.006    3.558    0.000    0.022    0.084
    y7                0.000    0.000    2.540    0.011    0.000    0.008
    y8                0.006    0.001    4.055    0.000    0.006    0.711
    y9                0.005    0.001    4.929    0.000    0.005    0.010
    y10               0.005    0.001    4.557    0.000    0.005    0.073
    co2               0.013    0.003    4.023    0.000    0.017    0.017
    total            -0.019    0.006   -3.048    0.002   -0.034   -0.034
    struct            0.058    0.016    3.645    0.000    1.000    1.000

library(lavaan)
> x<-read.csv("C:/Users/Quanying LU/Desktop/5.csv")
> co2model<-'
+ # measurement model
+ co2=~y1
+ total=~y2+y3+y4+y5+y6
+ struct=~y7+y8+y9+y10
+ # regressions
+ co2~total+struct
+ total~struct
+ '
> fit <- sem(co2model, data = x,meanstructure = "default",
+            conditional.x = "default", fixed.x = "default",
+            orthogonal = FALSE, std.lv = FALSE,
+            parameterization = "default", std.ov = FALSE,
+            missing = "default", ordered = NULL,
+            sample.cov = NULL, sample.cov.rescale = "default",
+            sample.mean = NULL, sample.nobs = NULL,
+            ridge = 1e-05,group = NULL,
+            group.label = NULL, group.equal = "", group.partial = "",
+            group.w.free = FALSE, cluster = NULL, constraints = '',
+            estimator = "default", likelihood = "default", link = "default",
+            information = "default", se = "default", test = "default",
+            bootstrap = 1000L, mimic = "default", representation = "default",
+            do.fit = TRUE, control = list(), WLS.V = NULL, NACOV = NULL,
+            zero.add = "default", zero.keep.margins = "default",zero.cell.warn = TRUE,
+            start = "default", verbose = FALSE, warn = TRUE, debug = FALSE)
Warning messages:
1: In lav_object_post_check(lavobject) :
  lavaan WARNING: some estimated variances are negative
2: In lav_object_post_check(lavobject) :
  lavaan WARNING: covariance matrix of latent variables is not positive definite; use inspect(fit,"cov.lv") to investigate.
3: In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.
> summary(fit, standardized = TRUE)
lavaan (0.5-20) converged normally after 159 iterations

  Number of observations                            27

  Estimator                                         ML
  Minimum Function Test Statistic              232.481
  Degrees of freedom                                33
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Information                                 Expected
  Standard Errors                             Standard

Latent Variables:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 =~                                                                
    y1                1.000                               0.863    1.000
  total =~                                                              
    y2                1.000                               0.757    1.000
    y3                0.092    0.004   21.444    0.000    0.069    0.972
    y4                1.532    0.048   31.653    0.000    1.159    0.987
    y5                1.048    0.081   12.980    0.000    0.793    0.928
    y6                0.657    0.043   15.396    0.000    0.497    0.947
  struct =~                                                             
    y7                1.000                               0.243    0.996
    y8                0.160    0.054    2.958    0.003    0.039    0.494
    y9                2.786    0.102   27.187    0.000    0.677    0.986
    y10              -1.085    0.045  -24.145    0.000   -0.264   -0.982

Regressions:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 ~                                                                 
    total            -0.618    0.398   -1.551    0.121   -0.542   -0.542
    struct            5.468    1.244    4.395    0.000    1.540    1.540
  total ~                                                               
    struct            3.098    0.080   38.568    0.000    0.995    0.995

Variances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    y1                0.000                               0.000    0.000
    y2               -0.000    0.001   -0.322    0.748   -0.000   -0.001
    y3                0.000    0.000    3.669    0.000    0.000    0.056
    y4                0.037    0.010    3.545    0.000    0.037    0.027
    y5                0.101    0.027    3.685    0.000    0.101    0.139
    y6                0.028    0.008    3.686    0.000    0.028    0.103
    y7                0.001    0.000    3.395    0.001    0.001    0.008
    y8                0.005    0.001    3.682    0.000    0.005    0.756
    y9                0.013    0.003    3.878    0.000    0.013    0.027
    y10               0.003    0.001    3.904    0.000    0.003    0.037
    co2              -0.004    0.003   -1.424    0.154   -0.005   -0.005
    total             0.006    0.003    2.034    0.042    0.010    0.010
    struct            0.059    0.016    3.643    0.000    1.000    1.000

Terrence Jorgensen

unread,
May 6, 2016, 7:01:29 AM5/6/16
to lavaan
Just like in your previous post, you are already specifying residual covariances correctly.  It looks like your question was already answered on the blavaan group:  https://groups.google.com/d/msg/blavaan/YBN43AcKO7k/hzvW7hMEBgAJ

luquany...@gmail.com

unread,
May 7, 2016, 2:59:07 AM5/7/16
to lavaan
I have a puzzle. If we do not have a tiny sample size, add "co2~~0.01*co2", whether the results will be affected?
Whether we can change "total~~0.01*total" or "struct~~0.01*struct"? What is the foundation? Exogenous variable? Endogenous Variable?
Please forgive me for interrupting!
Thank you very much!

在 2016年5月6日星期五 UTC+8下午7:01:29,Terrence Jorgensen写道:

Mauricio Garnier-Villarreal

unread,
May 7, 2016, 12:59:21 PM5/7/16
to lavaan
this line co2~~0.01*co2 fixes the variance of co2 to the value 0.01, so it will not be estimated

luquany...@gmail.com

unread,
May 8, 2016, 10:21:09 PM5/8/16
to lavaan
If I delete it, it will also not be estimated. 

在 2016年5月8日星期日 UTC+8上午12:59:21,Mauricio Garnier-Villarreal写道:

Terrence Jorgensen

unread,
May 9, 2016, 6:24:57 AM5/9/16
to lavaan
If I delete it, it will also not be estimated.

This is a free estimate:  co2 ~~ co2  (or)  co2 ~~ NA*co2
This is a free estimate, with a starting value:  co2 ~~ 0.01?co2
This is a fixed estimated:  co2 ~~ 0.01*co2
Deleting the line altogether from your syntax implies you want it fixed to zero, so it is equivalent to including this line of syntax:
  co2 ~~ 0*co2

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

luquany...@gmail.com

unread,
May 9, 2016, 10:39:08 AM5/9/16
to lavaan
Dear Terrence D. Jorgensen:

Thank you for your help!

I tried to correct it like you said. I add co2 ~~ co2  (or)  co2 ~~ NA*co2, the error could not be corrected. I do not know why. 

Warning messages:
1: In lav_object_post_check(lavobject) :
  lavaan WARNING: some estimated variances are negative
2: In lav_object_post_check(lavobject) :
  lavaan WARNING: covariance matrix of latent variables is not positive definite; use inspect(fit,"cov.lv") to investigate.
3: In lav_object_post_check(lavobject) :
  lavaan WARNING: observed variable error term matrix (theta) is not positive definite; use inspect(fit,"theta") to investigate.



在 2016年5月9日星期一 UTC+8下午6:24:57,Terrence Jorgensen写道:
Reply all
Reply to author
Forward
0 new messages