fixing parameter in simsem

75 views
Skip to first unread message

Seongho Bae

unread,
Nov 3, 2016, 4:20:47 AM11/3/16
to lavaan
Hi, all.

I encountered too much improper solution when fixing parameters in the 'simsem' context.
Can I solve too much improper solution issue?

Seongho
  
  # Specifying population (true-parameter) model
    pop.model <- "
    F1 =~ .70*y1 + .75*y2 + .80*y3 + .85*y4 + .65*y5
    F2 =~ .70*y5 + .75*y6 + .80*y7 + .85*y8 + .65*y9
    F3 =~ .70*y9 + .75*y10 + .80*y11 + .85*y12 + .65*y13
    F4 =~ .70*y13 + .75*y14 + .80*y15 + .85*y16

    F1 ~~ .30*F3
    F2 ~~ .35*F3
    F2 ~~ .40*F4

    F1 ~~ 0*F2
    F1 ~~ 0*F4
    F3 ~~ 0*F4

    F1 ~~ 1*F1
    F2 ~~ 1*F2
    F3 ~~ 1*F3
    F4 ~~ 1*F4

    y1 ~~ .51*y1
    y2 ~~ .4375*y2
    y3 ~~ .36*y3
    y4 ~~ .2775*y4
    y5 ~~ .0875*y5
    y6 ~~ .4375*y6
    y7 ~~ .36*y7
    y8 ~~ .2775*y8
    y9 ~~ .0875*y9
    y10 ~~ .4375*y10
    y11 ~~ .36*y11
    y12 ~~ .2775*y12
    y13 ~~ .0875*y13
    y14 ~~ .4375*y14
    y15 ~~ .36*y15
    y16 ~~ .2775*y16
    y2 ~~ .14*y10
    y7 ~~ .15*y11
    y8 ~~ .16*y16
    "

  # ... and set simulation model for the true-parameter condition (checkup data generation bias)
    c0.model <-"
    F1 =~ NA*y1 + NA*y2 + NA*y3 + NA*y4 + NA*y5
    F2 =~ NA*y5 + NA*y6 + NA*y7 + NA*y8 + NA*y9
    F3 =~ NA*y9 + NA*y10 + NA*y11 + NA*y12 + NA*y13
    F4 =~ NA*y13 + NA*y14 + NA*y15 + NA*y16

    F1 ~~ Z1*F1
    F2 ~~ Z2*F2
    F3 ~~ Z3*F3
    F4 ~~ Z4*F4

    F1 ~~ 0*F2
    F1 ~~ NA*F3 # NA means forcely set to 'free parameter'
    F1 ~~ 0*F4
    F2 ~~ NA*F3
    F2 ~~ NA*F4
    F3 ~~ 0*F4

    y2 ~~ y10
    y7 ~~ y11
    y8 ~~ y16

    # Constrain parameters
    Z1 == 1
    Z2 == 1
    Z3 == 1
    Z4 == 1
    "

  # output of c0 (population model itself)
    c0.output_50 <- sim(nRep = 500, model = c0.model, n = 50, generate = pop.model, lavaanfun = "cfa", multicore = F, seed = 20161020, completeRep = T)

Alex Schoemann

unread,
Nov 3, 2016, 1:05:05 PM11/3/16
to lavaan
I think the issue is occuring with how you're setting the scale of your latent variables. It looks like you're fixing each latent variance to 1 using the labels Z1-Z4. If you simply set the variances to 1 in the code (eliminating the labels z1-z4 ) things should work a little better. So this:

    F1 ~~ Z1*F1
    F2 ~~ Z2*F2
    F3 ~~ Z3*F3
    F4 ~~ Z4*F4

Should be this:

    F1 ~~ 1*F1
    F2 ~~ 1*F2
    F3 ~~ 1*F3
    F4 ~~ 1*F4

And then you can remove the Constrain parameters section.

I should also note that with an N of 50 you're likely to run into some improper solutions even if your model is correct.

Seongho Bae

unread,
Nov 6, 2016, 3:52:29 PM11/6/16
to lavaan
Dear Alex,

Sorry, No. I already tried it a long time ago. but I was encountered an unknown error message, like this;

> # ... and set simulation model for the true-parameter condition (checkup data generation bias)
>     c0.model <-"
+     F1 =~ NA*y1 + NA*y2 + NA*y3 + NA*y4 + NA*y5
+     F2 =~ NA*y5 + NA*y6 + NA*y7 + NA*y8 + NA*y9
+     F3 =~ NA*y9 + NA*y10 + NA*y11 + NA*y12 + NA*y13
+     F4 =~ NA*y13 + NA*y14 + NA*y15 + NA*y16
+ 
+     F1 ~~ 1*F1
+     F2 ~~ 1*F2
+     F3 ~~ 1*F3
+     F4 ~~ 1*F4
+ 
+     F1 ~~ 0*F2
+     F1 ~~ NA*F3 # NA means forcely set to 'free parameter'
+     F1 ~~ 0*F4
+     F2 ~~ NA*F3
+     F2 ~~ NA*F4
+     F3 ~~ 0*F4
+ 
+     y2 ~~ y10
+     y7 ~~ y11
+     y8 ~~ y16
+ 
+     # Constrain parameters
+     # Z1 == 1
+     # Z2 == 1
+     # Z3 == 1
+     # Z4 == 1
+     "
> 
>   # output of c0 (population model itself)
>     c0.output_50 <- sim(nRep = 500, model = c0.model, n = 50, generate = pop.model, lavaanfun = "cfa", multicore = F, seed = 20161020, completeRep = T, smartStart= T)
Progress: 1 / 500 
Error in names(coef) <- lab : 
  'names' 속성 [45]는 반드시 벡터 [41]와 같은 길이를 가져야 합니다

2016년 11월 4일 금요일 오전 2시 5분 5초 UTC+9, Alex Schoemann 님의 말:

Alex Schoemann

unread,
Nov 7, 2016, 8:59:06 AM11/7/16
to lavaan
Interesting. That code ran on my machine with no issues. Can you send the sessionInfo() from when you get that Error and the full R script that produced it?

Seongho Bae

unread,
Nov 7, 2016, 9:20:04 AM11/7/16
to lavaan
Okay, I attached it. Thanks.

Seongho

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=ko_KR.UTF-8       LC_NUMERIC=C               LC_TIME=ko_KR.UTF-8        LC_COLLATE=ko_KR.UTF-8    
 [5] LC_MONETARY=ko_KR.UTF-8    LC_MESSAGES=ko_KR.UTF-8    LC_PAPER=ko_KR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=ko_KR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] simsem_0.5-13      semTools_0.4-14    lavaan_0.5-23.1026

loaded via a namespace (and not attached):
 [1] MASS_7.3-45        zoo_1.7-13         parallel_3.3.1     sandwich_2.3-4     tools_3.3.1        nonnest2_0.4-1    
 [7] mvtnorm_1.0-5      mnormt_1.5-5       grid_3.3.1         pbivnorm_0.6.0     CompQuadForm_1.4.2 stats4_3.3.1      
[13] lattice_0.20-34    quadprog_1.5-5    
>
Fixing_Parameter_SimSem.R

Seongho Bae

unread,
Nov 11, 2016, 4:56:14 AM11/11/16
to lavaan
Hi, Alex.

Could you find out what is the matter? Should I provide the Rstudio server account to investigate?

Seongho

2016년 11월 7일 월요일 오후 10시 59분 6초 UTC+9, Alex Schoemann 님의 말:

Alex Schoemann

unread,
Nov 14, 2016, 2:47:04 PM11/14/16
to lavaan
Hi Seongho,

It looks like an issue with the newest version of lavaan 0.5-23 (and maybe 0.5-22). I thought we caught all the bugs associated with parameter labels but we must have missed some. For now, if you're using labels you can use an earlier version of lavaan (I believe 0.5-20 should work). We'll try to track down the issue ASAP.

Thanks,

Alex

Seongho Bae

unread,
Nov 18, 2016, 4:44:38 AM11/18/16
to lavaan
Hi, Alex.

I following your advice, but I still stuck to run correctly. What should I do to run correctly?

Seongho

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=ko_KR.UTF-8       LC_NUMERIC=C               LC_TIME=ko_KR.UTF-8        LC_COLLATE=ko_KR.UTF-8    
 [5] LC_MONETARY=ko_KR.UTF-8    LC_MESSAGES=ko_KR.UTF-8    LC_PAPER=ko_KR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=ko_KR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] simsem_0.5-13 lavaan_0.5-20

loaded via a namespace (and not attached):
[1] tools_3.3.1     mnormt_1.5-5    pbivnorm_0.6.0  packrat_0.4.8-1 stats4_3.3.1    quadprog_1.5-5 

2016년 11월 15일 화요일 오전 4시 47분 4초 UTC+9, Alex Schoemann 님의 말:

Seongho Bae

unread,
Nov 18, 2016, 5:10:18 AM11/18/16
to lavaan
Hi Alex,

Finally, I fix it. the simsem 0.5-14 work correctly with lavaan 0.5-20. Why don't update simsem 0.5-14 on the CRAN?

Seongho

2016년 11월 18일 금요일 오후 6시 44분 38초 UTC+9, Seongho Bae 님의 말:
Reply all
Reply to author
Forward
0 new messages