need help about "lavaan" and "blavaan"

190 views
Skip to first unread message

luquany...@gmail.com

unread,
May 4, 2016, 3:43:00 AM5/4/16
to lavaan

 I am a beginner in lavaan and blavaan library. I have some basic questions in my code.

library(lavaan)
x<-read.csv("C:/Users/Quanying LU/Desktop/5.csv")
co2model<-'"
> 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
+ tech=~y11
+ # regressions
+ co2~total+struct+tech
+ total~struct+tech
+ struct~tech
+ # residual covariances
+ y2~~y3+y4+y5+y6+y7+y8+y9+y10+y11
+ y3 ~~ y4+y7
+ y5 ~~ y4+y7+y8+y9+y11
+ y6 ~~ y4+y7+y8+y9+y11
+ y7~~y4
+ y8~~y11
+ y9~~y11
+ y10~~y11'
> 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 619 iterations
 
  Number of observations                            27
 
  Estimator                                         ML
  Minimum Function Test Statistic               86.803
  Degrees of freedom                                15
  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.736    0.969
    y3                0.094    0.003   28.857    0.000    0.069    0.974
    y4                1.539    0.048   32.027    0.000    1.132    0.966
    y5                1.043    0.088   11.861    0.000    0.767    0.905
    y6                0.652    0.040   16.395    0.000    0.480    0.955
  struct =~                                                             
    y7                1.000                               0.243    0.999
    y8                0.196    0.054    3.647    0.000    0.048    0.544
    y9                2.795    0.076   36.652    0.000    0.679    0.991
    y10              -1.052    0.065  -16.125    0.000   -0.256   -0.952
  tech =~                                                               
    y11               1.000                               0.307    1.000
 
Regressions:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  co2 ~                                                                 
    total             0.864    0.190    4.547    0.000    0.737    0.737
    struct            0.910    0.817    1.113    0.266    0.256    0.256
    tech              0.032    0.309    0.104    0.917    0.011    0.011
  total ~                                                               
    struct            3.043    0.452    6.731    0.000    1.005    1.005
    tech             -0.043    0.347   -0.125    0.900   -0.018   -0.018
  struct ~                                                              
    tech             -0.766    0.037  -20.437    0.000   -0.969   -0.969
 
Covariances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
  y2 ~~                                                                 
    y3                0.002    0.001    3.731    0.000    0.002    0.728
    y4                0.046    0.010    4.625    0.000    0.046    0.808
    y5                0.024    0.006    4.076    0.000    0.024    0.353
    y6                0.010    0.002    4.249    0.000    0.010    0.347
    y7               -0.005    0.001   -4.376    0.000   -0.005   -2.480
    y8               -0.001    0.001   -1.003    0.316   -0.001   -0.051
    y9               -0.006    0.002   -3.769    0.000   -0.006   -0.349
    y10              -0.007    0.001   -4.367    0.000   -0.007   -0.420
    y11               0.003    0.001    2.483    0.013    0.003      Inf
  y3 ~~                                                                 
    y4                0.004    0.001    3.971    0.000    0.004    0.849
    y7               -0.001    0.000   -4.915    0.000   -0.001   -3.000
  y4 ~~                                                                 
    y5                0.034    0.010    3.439    0.001    0.034    0.313
  y5 ~~                                                                 
    y7               -0.004    0.002   -2.030    0.042   -0.004   -0.870
    y8                0.011    0.003    3.242    0.001    0.011    0.425
    y9               -0.017    0.005   -3.619    0.000   -0.017   -0.501
    y11               0.002    0.004    0.499    0.618    0.002      Inf
  y4 ~~                                                                 
    y6                0.012    0.003    3.477    0.001    0.012    0.261
  y6 ~~                                                                 
    y7               -0.003    0.001   -3.632    0.000   -0.003   -2.001
    y8               -0.008    0.002   -3.785    0.000   -0.008   -0.744
    y9               -0.009    0.002   -3.502    0.000   -0.009   -0.634
    y11               0.011    0.003    3.896    0.000    0.011      Inf
  y4 ~~                                                                 
    y7               -0.008    0.002   -4.256    0.000   -0.008   -2.301
  y8 ~~                                                                 
    y11              -0.003    0.001   -2.990    0.003   -0.003     -Inf
  y9 ~~                                                                 
    y11              -0.003    0.001   -2.609    0.009   -0.003     -Inf
  y10 ~~                                                                
    y11               0.001    0.001    0.855    0.393    0.001      Inf
 
Variances:
                   Estimate  Std.Err  Z-value  P(>|z|)   Std.lv  Std.all
    y1                0.000                               0.000    0.000
    y2                0.036    0.008    4.713    0.000    0.036    0.062
    y3                0.000    0.000    3.938    0.000    0.000    0.052
    y4                0.093    0.018    5.049    0.000    0.093    0.067
    y5                0.130    0.032    4.071    0.000    0.130    0.181
    y6                0.022    0.006    3.705    0.000    0.022    0.087
    y7                0.000    0.000    1.263    0.206    0.000    0.002
    y8                0.005    0.001    4.198    0.000    0.005    0.704
    y9                0.008    0.002    4.790    0.000    0.008    0.018
    y10               0.007    0.001    4.791    0.000    0.007    0.094
    y11               0.000                               0.000    0.000
    co2               0.021    0.006    3.381    0.001    0.028    0.028
    total            -0.025    0.007   -3.391    0.001   -0.045   -0.045
    struct            0.004    0.001    3.943    0.000    0.061    0.061

    tech              0.094    0.026    3.685    0.000    1.000    1.000



library(blavaan)

library(rjags)

library(runjags)

x<-read.csv("C:/Users/Quanying LU/Desktop/5.csv")

co2.model<-'

# measurement model

co2=~y1

total=~y2+y3+y4+y5+y6

struct=~y7+y8+y9+y10

tech=~y11

# regressions

co2~total+struct+tech

total~struct+tech

struct~tech

# residual covariances

y2~~y3+y4+y5+y6+y7+y8+y9+y10+y11

y3 ~~ y4+y7

y5 ~~ y7+y8+y9

y6 ~~ y7+y8+y9+y11

y7~~y8

y8~~y11

y10~~y11'

fit <- bsem(co2.model, data=x,

            dp=dpriors(nu="dnorm(5,1e-3)", itheta="dlnorm(1,.1)[sd]",

                       ipsi="dlnorm(1,.1)[sd]", rho="dbeta(3,3)"),

            jagcontrol=list(method="rjparallel"))

       

summary(fit)

 

 

Failed with error:  ‘there is no package called ‘modeest’’

Compiling rjags model...

Error : The following error occured when compiling and adapting the model using rjags:

 Error in rjags::jags.model(model, data = dataenv, inits = inits, n.chains = length(runjags.object$end.state),  :

  Error in node theta[1,1]

Invalid parent values

 

 

It may help to use failed.jags(c('model','data','inits')) to see model/data/inits syntax with line numbers

Error in blavaan(co2.model, data = x, dp = dpriors(nu = "dnorm(5,1e-3)",  :

  blavaan ERROR: problem with jags estimation.  The jags model and data have been exported.

luquany...@gmail.com

unread,
May 4, 2016, 3:44:11 AM5/4/16
to lavaan
I think that there may be some mistakes in my "residual covariances" setting. I do not know how to set this part in all codes. 

在 2016年5月4日星期三 UTC+8下午3:43:00,luquany...@gmail.com写道:

Terrence Jorgensen

unread,
May 4, 2016, 4:06:29 AM5/4/16
to lavaan
You are using the correct lavaan syntax (~~) to specify residual covariances, assuming you have informative enough priors to empirically identify this model.  There is actually a blavaan Google group where you can post questions about that package. 


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

luquany...@gmail.com

unread,
May 4, 2016, 5:09:36 AM5/4/16
to lavaan
Thank you so much!

在 2016年5月4日星期三 UTC+8下午4:06:29,Terrence Jorgensen写道:

luquany...@gmail.com

unread,
May 5, 2016, 5:41:39 AM5/5/16
to lavaan
Dear Terrence Jorgensen:

Do you know how to set residual covariances in the model?

在 2016年5月4日星期三 UTC+8下午5:09:36,luquany...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages