Error in t(jac0C) %*% W

Attachment | Size |
---|---|
Data | 408.97 KB |
Model | 60.46 KB |
forumscript.R | 2.28 KB |
For my research, I am running a latent variable model with a structural regression between four latent variables that are all measured by a set of ordinal manifest variables. Attached is the dataset, a minimalized R-script and a screenshot of the structural model. Because the manifest variables are ordinal (3 or 4 categories) and highly skewed, I applied a threshold model and used WLS as an estimator. I have been able to successfully run the separate measurement models of each of the X, Y, and Z constructs. However, when I combine these models and add a structural regression between the latent constructs I receive the error message: "Error in t(jac0C) %*% W: Non-conformable arguments"
.
According to mxCheckIdentification() my model is correctly identified. I also used mxAutoStart() to improve the starting values, but this results in the error: "Error in dataThresh[, tName] : no 'dimnames' attribute for array"
.
Can you reproduce this problem? And do you know a solution?
**Details:**
OpenMx version: 2.7.17 [GIT v2.7.17]
R version: R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0
MacOS: 10.11.6
Default optimiser: CSOLNP
NPSOL-enabled?: No
OpenMP-enabled?: No
**Script:**
forumdata<-read.table(file="forumdata.dat")
xa.manifests=c("X1","X3","X6","X8","X10","X11","X14")
xb.manifests=c("X2","X4","X5","X7","X9","X12","X13")
y.manifests=c("Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8","Y9")
z.manifests=c("Z1","Z2","Z3","Z4","Z5","Z6","Z7")
manifests=c(xa.manifests,xb.manifests,y.manifests,z.manifests)
# The model
mod <- mxModel(name="model1",type="RAM",
# Data
mxDataWLS(forumdata,type="WLS"),
# Specify variables
manifestVars=manifests,
latentVars=c("Xa","Xb","Y","Z"),
# Means
mxPath(from="one",to=manifests,arrows=1,free=T,values=0,labels=manifests),
# Thresholds
mxThreshold(vars=c(xa.manifests,xb.manifests),nThres=4,free=c(F,T,T,F),values=c(-.5,-.3,.3,.5)),
mxThreshold(vars=y.manifests, nThres=3,free=c(F,T,F),values=c(-.5,0,.5)),
mxThreshold(vars=z.manifests, nThres=3,free=c(F,T,F),values=c(-.5,0,.5)),
# Residual variances
mxPath(from=manifests, arrows=2,free=T,labels=paste("error",manifests)),
# Factor loadings
mxPath(from="Xa", to=xa.manifests,arrows=1,free=T,values=.8,labels=paste("loading",xa.manifests)),
mxPath(from="Xb", to=xb.manifests,arrows=1,free=T,values=.8,labels=paste("loading",xb.manifests)),
mxPath(from="Y", to=y.manifests, free=T, values=.8,labels=paste("loading",y.manifests)),
mxPath(from="Z", to=z.manifests, free=T, values=.8,labels=paste("loading",z.manifests)),
# Latent (co)variances
mxPath(from=c("Xa","Xb"), arrows=2, connect="unique.pairs",free=c(F,T,F), values=c(1,.5,1),labels=c("varXa","covXab","varXb")),
mxPath(from="Y", arrows=2, free=F, values=1, labels="varY"),
mxPath(from="Z", arrows=2, free=F, values=1, labels="varZ"),
mxPath(from="Y", to="Z", arrows=2, free=T, values=.5, labels=c("covYZ")),
# Structural regression
mxPath(from=c("Xa","Xb"), to="Y", arrows=1, free=c(T,T), values=c(-.05,.5), labels=c("b_Xa_Y","b_Xb_Y")),
mxPath(from=c("Xa","Xb"), to="Z", arrows=1, free=c(T,T), values=c(-.05,.5), labels=c("b_Xa_Z","b_Xb_Z")),
# Fit model with WLS
fitFunction <- mxFitFunctionWLS()
)
mxCheckIdentification(mod)
mxAutoStart(mod)
modrun<-mxRun(mod)
Here's a fix
Thanks for sharing a full working example! That really help resolve issues like this. The problem seems to be related to the thresholds. More specifically, because the number of thresholds differs across items and
mxThresholds
build s a threshold matrix with zeros in it instead of NA for the thresholds that do not get used. On the development side, the team will need to discuss what the best fix for this is. In the meantime for you, you can just add a couple lines of code to get the model to run. Changemodrun<-mxRun(mod)
to
mod$Thresholds$values[4, c(y.manifests, z.manifests)] <- NA
modrun<-mxRun(mod)
The added line puts NA in the last threshold for the items that only have values from 0 through 3, instead of the items that have values from 0 through 4.
Also, note that the
mxAutoStart
function does not modify the model, but rather returns a new model with starting values changed.coef(mod)
mxAutoStart(mod) # I return a new model
coef(mod)
coef(mod)
modas <- mxAutoStart(mod)
# modas is a new model with new start values
coef(mod) # original start values
coef(modas) # automatic start values
But there appears to be a bug in
mxAutoStart
in that it does not work for WLS data. The method itself uses WLS, so I didn't conceive of anyone using it for WLS. It won't make anything much faster for WLS.Log in or register to post comments
In reply to Here's a fix by mhunter
Thanks!
Log in or register to post comments
Update
Log in or register to post comments