Factor scores following WLS estimation

Posted on
Picture of user. PaulTwin Joined: 01/29/2017
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

Replied on Fri, 09/08/2017 - 11:31
Picture of user. AdminRobK Joined: 01/24/2014

What version of the package are you running? You can use mxVersion() to see.
Replied on Sat, 09/09/2017 - 16:12
Picture of user. PaulTwin Joined: 01/29/2017

In reply to by AdminRobK

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
Replied on Mon, 09/11/2017 - 04:18
Picture of user. PaulTwin Joined: 01/29/2017

Thanks, I updated the OpenMx R-package, but encountered the same problem as described in my opening post.
Replied on Mon, 09/11/2017 - 11:15
Picture of user. mhunter Joined: 07/31/2009

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.

Replied on Fri, 09/15/2017 - 08:29
Picture of user. PaulTwin Joined: 01/29/2017

In reply to by mhunter

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?

Replied on Tue, 09/26/2017 - 00:54
Picture of user. mhunter Joined: 07/31/2009

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' with mxPath statements or using mxExpectationRAM will specify a RAM model.