Definition variable for mean regression not working in WLS

Posted on
Picture of user. iloo Joined: 05/26/2010
Hi,
The use of definition variable for regression in means model is not working for me when using WLS. Think it was supposed to work from version 2.12 and onwards, but I haven't gotten it to work. I haven't tried different platforms or software configs, so maybe it has something to do with these.

Attached is an example where it fails (but the ML-fitfunction works fine).

Here's my sessionInfo():
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Swedish_Sweden.1252 LC_CTYPE=Swedish_Sweden.1252 LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C
[5] LC_TIME=Swedish_Sweden.1252

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

other attached packages:
[1] OpenMx_2.13.2

loaded via a namespace (and not attached):
[1] MASS_7.3-50 compiler_3.4.1 Matrix_1.2-10 parallel_3.4.1 tools_3.4.1 Rcpp_0.12.17 grid_3.4.1 digest_0.6.12
[9] lattice_0.20-35

Replied on Mon, 06/17/2019 - 08:33
Picture of user. jpritikin Joined: 05/23/2012

You'll need to use RAM or LISREL so OpenMx knows which variables are latent. This feature isn't supported for mxExpectationNormal.
Replied on Mon, 06/17/2019 - 09:08
Picture of user. iloo Joined: 05/26/2010

In reply to by jpritikin

Aha!
This was not clear from the release comments, but makes perfect sense to me now!
Thanks for quick response.
Replied on Wed, 06/19/2019 - 02:42
Picture of user. iloo Joined: 05/26/2010

In reply to by jpritikin

Hi again,
I cannot seem to understand exactly how I do get the definition variables to work in the LISREL model using WLS, do you have a working example? (RAM isn't flexible enough for the implementations I'm considering.)

The only info I can find is from the 2.12 release: " Third, the WLS fitfunction is now compatible with exogenous covariates. That is, you can now use WLS if your model contains definition variables, as long as those definition variables are only involved in the model for the endogenous variables' means. "

"Endogenuous variables' means", does that mean the mean the model for eta ('alpha' in the latent variable equation)? Or does it imply the indicators of eta ('tau_y' in the measurement equation for endogoneous variables)? I've tried including the definition variable to work on the mean in both those places (i.e., alpha or tau_y), but doesn't work for me (works fine using ML fit function).

Am I misunderstanding some central concept? Like, should definition variables not be intered as "data.variablename"? Or something about the dimnames I've entered?

Would be glad to get some feedback since definition variable adjustment (to be used for simple regressions for expected means/thresholds) in WLS would save me a lot of optimization time, especially now when the WLS is so quick (and ML often fails when many ordinal variables are included).

Here's some code where I tried to use definition variable, entered as "data.u", covariate for regression.


# Generate data
N <- 1000

u <- rbinom(N,1,.4)
y <- -.2*u + rnorm(N,0,1)+1
dat <- data.frame( y,u )
summary(lm(y~u,data=dat))

lismod <- mxModel( 'LISRELmodel' ,
# Definition variable and regression coefficient
mxMatrix('Full',1,1,free=T,values=-.02,name='BU' , dimnames=list('y',NA) ),
mxMatrix('Full',1,1,labels='data.u', name='U' , dimnames=list('y',NA) ),
# Manifest endogenuous variable
mxMatrix('Full',1,1,free=T,values=1, name='M' , dimnames=list('y',NA) ),
mxAlgebra( M, name='Tau_y' , dimnames=list('y','y') ),
#mxAlgebra( M+BU*U, name='Tau_y' ,
# dimnames=list(c('y'),NA) ), # IF definition variable used on manifest variable
# Endogenuous latent variable mean
mxMatrix('Full',1,1,free=F,values=0,labels='am',name='Alpha' ,
dimnames=list(c('Fa'),NA) ),
mxAlgebra( Alpha+BU*U, name='Alpha_M' , dimnames=list('Fa','u') ),
# Loading from latent engenuous to manifest
mxMatrix('Full',1,1,free=F,values=1,name='LambdaY' ,
dimnames=list(c('y'),c('Fa') ) ),
# Covariance of latent endogenuous
mxMatrix('Full',1,1,free=T,values=c(1),name='Psi',
dimnames=list(c('Fa'),c('Fa') ) ),
# Latent variable equation
mxMatrix('Full',1,1,free=F,values=c(0),name='Beta',
dimnames=list(c('Fa'),c('Fa') ) ),
# Residual Variance of manifest variable
mxMatrix('Full',1,1,free=F,values=0,name='ThetaEps'),

# Data
mxData( dat[, c('y','u') ], type='raw' ) ,
mxExpectationLISREL(LY='LambdaY', PS='Psi',TE='ThetaEps',TY = 'Tau_y', AL = 'Alpha_M', BE='Beta',
LX=NA,GA=NA, PH=NA, TD=NA, TH=NA,TX = NA, KA = NA ),
mxFitFunctionWLS( type='WLS' , allContinuousMethod='marginals' )
)
# Doesn't work:
lismodFit <- mxRun( lismod )
summary( lismodFit )

# Works fine:
lismod$fitfunction <- mxFitFunctionML()
lismodFit <- mxRun( lismod )
summary( lismodFit )

Replied on Wed, 06/19/2019 - 08:38
Picture of user. jpritikin Joined: 05/23/2012

In reply to by iloo

I'll look at your script soon. Until then, here's [an example](https://github.com/OpenMx/OpenMx/blob/master/inst/models/passing/exoPredWLS.R). I'm not sure whether I've tested models specified using matrix notation. Path notation should work though.
Replied on Wed, 06/19/2019 - 09:52
Picture of user. AdminRobK Joined: 01/24/2014

In reply to by iloo

I'm sorry the release announcement for v2.12 wasn't clearer about definition variables with WLS. I scribe the release announcements, and it was news to me when, earlier in this thread, Joshua said you have to use RAM or LISREL specification to use definition variables with WLS.
Replied on Wed, 06/19/2019 - 09:54
Picture of user. jpritikin Joined: 05/23/2012

In reply to by iloo

TY cannot be an algebra. You need to express the exogenous predictor as a latent variable with zero variance (PS(u,u)=0). Estimate the regression coefficient in LY (manifest loadings). Entries associated with u in BE (latent loadings) must be fixed to zero.
Replied on Fri, 07/12/2019 - 13:38
Picture of user. jpritikin Joined: 05/23/2012

In reply to by jpritikin

I received a notification for this thread today. Did something change? Is your issue solved?