Non-standard error variances

550 views
Skip to first unread message

Lakshika Nawarathna

unread,
Jul 24, 2014, 6:33:28 PM7/24/14
to lav...@googlegroups.com
Hello everyone,
I want to fit a model whose error variance depend on the true measurement. 
These error variances depend on unknown constants sigma1sq, delta1, sigma2sq, delta2 and known bstar. 
I am getting this error.


> fit1 <- sem(model1, data=yshort)

Error in getDataFull(data = data, group = group, group.label = group.label,  : 
  lavaan ERROR: missing observed variables in dataset: sigma1sq delta1 sigma2sq delta2

Does anyone know how to fix this error and make this program work? Any help would be very much appreciated!

Thank you!


library(lavaan)
chol.dat <- read.table("chol3.csv", sep=",", header=T)
chol.dat$subject <- as.factor(chol.dat$subject)

ymat <- matrix(chol.dat$obs, byrow=F, ncol=100) 

y11 <- ymat[1,]
y12 <- ymat[2,]
y21 <- ymat[11,]
y22 <- ymat[12,]

bstar <- (y11 + y12)/2 
yshort <- data.frame(y11, y12, y21, y22, bstar)

model1 <- 
  '
#latent variable definitions
b =~ y11 + 1*y12 
b1 =~ y11 + 1*y12
b2 =~ y21 + 1*y22

#regressions
y21 + y22 ~ alpha*1
y21 + y22 ~ beta*b

#intercepts
b ~ 1
y11 ~ 0*1
y12 ~ 0*1

bstar ~ 0*1

#variances and covariances
b ~~ 0*b1
b ~~ 0*b2
b1 ~~ 0*b2

b ~~ tausq*b 

b1 ~~ psisq*b1
b2 ~~ psisq*b2

#assume: same error variance for all subjects
y11 ~~ var1*y11
y12 ~~ var1*y12
y21 ~~ var2*y21
y22 ~~ var2*y22

var1 =~ sigma1sq  + delta1 + bstar
var2 =~ sigma2sq  + delta2 + bstar

#Model constraints
var1 == sigma1sq* bstar^(2*delta1) 
var2 == sigma2sq*bstar^(2*delta2) 

'
fit1 <- sem(model1, data=yshort)

chol3.csv

Sunthud Pornprasertmanit

unread,
Jul 25, 2014, 11:05:24 AM7/25/14
to lav...@googlegroups.com
I think you would like to define var1 and var2 from the parameters in the model. You probably need the := operator instead of =~. That is,

var1 := sigma1sq  + delta1 + bstar
var2 := sigma2sq  + delta2 + bstar



--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Lakshika Nawarathna

unread,
Jul 25, 2014, 12:00:22 PM7/25/14
to lav...@googlegroups.com

 Thank you Sunthud.  Now I am getting the following error.              

Error in Model(partable = lavaanParTable, start = lavaanStart, representation = lavaanOptions$representation,  :

  lavaan ERROR: unknown label(s) in variable definitions: sigma1sq delta1 bstar sigma2sq delta2

In addition: Warning message:

In lavSampleStatsFromData(Data = lavaanData, missing = lavaanOptions$missing,  :

  lavaan WARNING: sample covariance can not be inverted

 

The variables sigma1sq, delta1,  sigma2sq and  delta2 are unknown parameters and  want to estimate them. Is there already a script/tutorial on how lavaan can fit non-standard variance structures? Thank you.

chol3.csv

Sunthud Pornprasertmanit

unread,
Jul 25, 2014, 1:11:35 PM7/25/14
to lav...@googlegroups.com
Something are not quite right in your script. I actually confuse what you are trying to do here. First, you assign both b and b1 to have the same loadings with the same variables.Further, you assign all factors to have the variances of 0 but assign labels on to it. Do you have any examples on other SEM packages or picture representations of your model? Next, sigma1sq, delta, sigma2sq, delta2 are not defined in your model. Finally, bstar is a linear combination of other variables in your data set. Thus, the covariance matrix between y11, y12, y21, y22, and bstar cannot be inversed. 

Lakshika Nawarathna

unread,
Jul 25, 2014, 2:54:51 PM7/25/14
to lav...@googlegroups.com

Thank you for the quick response. My model is attached as pdf document. 

The model.pdf

Sunthud Pornprasertmanit

unread,
Jul 25, 2014, 5:39:50 PM7/25/14
to lav...@googlegroups.com
I do not understand the variance of e. However, if the variance of e depend on the average data point (bstar), I think you cannot do that in SEM framework. If I assume that your e has a variance of sigma_j, I would write your script as follows:

y11 =~ 1*b + 1*b1
y11 ~ 0*1
y12 =~ 1*b + 1*b1
y12 ~ 0*1
y21 =~ beta*b + 1*b2
y21 ~ alpha*1
y22 =~ beta*b + 1*b2
y22 ~ alpha*1
b ~ mu*1
b ~~ tau*b
b1 ~~ psi*b1
b2 ~~ psi*b2
b ~~ 0*b1
b ~~ 0*b2
b1 ~~ 0*b2
y11 ~~ sigma1*y11
y12 ~~ sigma1*y12
y21 ~~ sigma2*y21
y22 ~~ sigma2*y22


I have not run it yet. However, it should not have any problems.

Lakshika Nawarathna

unread,
Jul 25, 2014, 9:42:01 PM7/25/14
to lav...@googlegroups.com

Thank for your reply. These error variances depend on the bstar. 

We proposed this model to deal with heteroscedastic error variances. We can develop this model using R. But if we can do this using lavann, more people can use our approach. 


Yves Rosseel

unread,
Jul 26, 2014, 11:18:25 AM7/26/14
to lav...@googlegroups.com
You did not give us a lot of context, so I have no idea what you try to
do here. But it looks like you are using a hierarchical bayesian
approach. This is something lavaan can not handle.

In any case, you can use something like

y11 ~~ var1*y11
y12 ~~ var1*y12
y21 ~~ var2*y21
y22 ~~ var2*y22

and

var1 := sigma1sq + delta1 + bstar
var2 := sigma2sq + delta2 + bstar


When you are using the ":=" operator, the lhs must be a new name, while
everything on the rhs must be existing labels of model parameters.

Yves.

Reply all
Reply to author
Forward
0 new messages