Factor scores following WLS estimation
Posted on

Forums
Dear reader,
Currently I am struggling with computing factor scores with maximum likelihood estimation using the mxFactorScores(model, type="ML") function. If I understand it correctly, the input model should include a means vector for the indicators. However, because my indicators are categorical I fit my model with mxFitFunctionWLS() and specify the data with mxDataWLS(data,type="WLS"). To my knowledge the mxDataWLS() function does not allow the specification of the means. As a result my model does not provide the means necessary to use the mxFactorScores() function.
Do you know a solution to my problem?
Best,
Paul
version?
What version of the package are you running? You can use
mxVersion()
to see.Log in or register to post comments
In reply to version? by AdminRobK
OpenMx
OpenMx version: 2.5.2 [GIT v2.5.2]
R version: R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0
MacOS: 10.11.6
Default optimiser: SLSQP
Log in or register to post comments
In reply to OpenMx by PaulTwin
update and retry
Version 2.5.2 is almost a year and a half old. I'd say the first thing to try is to update OpenMx and then see if it can do what you want.
Log in or register to post comments
Update
Thanks, I updated the OpenMx R-package, but encountered the same problem as described in my opening post.
Log in or register to post comments
Sorry that factor scores aren
Sorry that factor scores aren't working for this problem! I think your explanation of the problem is incorrect. WLS data does include means. Without even the error/warning message this problem is hard to diagnose. However, here's an example of fitting a model with WLS, swapping in raw data, and then fitting ML factor scores to the WLS estimated model.
require(OpenMx)
#require(devtools)
#install_bitbucket('mhunter/easymx')
# need a bleeding edge version of EasyMx
# to get the deviation=FALSE argument
# However, if your ordinal variables all have the
# same number of categories this isn't needed.
# Then you can use
# install.packages('EasyMx')
require(EasyMx)
# Load data
data(jointdata)
jointdata[, c(2, 4, 5)] <- mxFactor(jointdata[,c(2, 4, 5)],
levels=sapply(jointdata[,c(2, 4, 5)], function(x){sort(unique(x))}))
# Build a basic factor model
m0 <- emxFactorModel(list(F1=names(jointdata)), jointdata)
m0$Loadings$lbound <- 0
# Make this a WLS factor model
m1 <- mxModel("WLSFactorModel",
emxThresholds(jointdata, ordinal=c(2, 4, 5), deviation=FALSE),
m0$Loadings, m0$Residuals, m0$LatentMeans, m0$Means, m0$LatentVariances,
m0$expectation,
mxDataWLS(jointdata),
mxFitFunctionWLS())
# Run it
m1r <- mxRun(m1)
# Try factor scores. Error.
mxFactorScores(m1r, 'ML')
# Error in mxFactorScores(m1r, "ML") :
# The 'model' argument must have raw (not summary) data.
# Swap in raw data for WLS, and ML fit function for WLS
m1rd <- mxModel(m1r,
mxData(jointdata, 'raw'),
mxFitFunctionML())
# Estimate scores
scores <- mxFactorScores(m1rd, 'ML')
It's worth mentioning that this is a strange thing to do. ML factor scores from the WLS model might not behave well. I don't think it has been studied.
Another point to consider, your ML model might run faster with better starting values. From the example above,
# Get good starting values for ML model
m0s <- mxAutoStart(m0)
The model
m0s
is an ML model with pretty good starting values. Many times this makes the ML estimation faster.Log in or register to post comments
In reply to Sorry that factor scores aren by mhunter
Thanks!
Thanks for the reply! I used your script to compute the factor scores, but R returns an error when fitting the WLS model: "Error: The row names of the LX matrix and the row names of the TX matrix in model 'WLSFactorModel' do not contain identical names."
After I constrain these rownames to be equal I receive a different error: "Error in runHelper(model, frontendStart, intervals, silent, suppressWarnings,: Observed thresholds were provided, but an expected thresholds matrix was not specified.
If you provide observed thresholds, you must specify a model for the thresholds."
You mention that estimating ML factor scores is a strange thing to do for a WLS model. What do you think would be the best method to compute factor scores for a WLS model?
Log in or register to post comments
Try a non-LISREL model
I'm sorry I walked you into that problem! There was a bug in LISREL WLS models that was fixed [here](https://github.com/OpenMx/OpenMx/commit/e53585b22a6ff879f35fc584811d78fd9c2fbe03). This fix will be part of the next release, probably in the next 2-3 weeks. In the meantime, if you specify a non-LISREL model it will work. Using
type='RAM'
withmxPath
statements or usingmxExpectationRAM
will specify a RAM model.Log in or register to post comments
In reply to Try a non-LISREL model by mhunter
No problem
No problem! And thanks, it works now using the RAM specification.
Log in or register to post comments