You are here

Factor scores following WLS estimation

9 posts / 0 new
Last post
PaulTwin's picture
Offline
Joined: 01/29/2017 - 09:25
Factor scores following WLS estimation

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

AdminRobK's picture
Offline
Joined: 01/24/2014 - 12:15
version?

What version of the package are you running? You can use mxVersion() to see.

PaulTwin's picture
Offline
Joined: 01/29/2017 - 09:25
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

AdminRobK's picture
Offline
Joined: 01/24/2014 - 12:15
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.

PaulTwin's picture
Offline
Joined: 01/29/2017 - 09:25
Update

Thanks, I updated the OpenMx R-package, but encountered the same problem as described in my opening post.

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
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.

PaulTwin's picture
Offline
Joined: 01/29/2017 - 09:25
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?

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
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. 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.

PaulTwin's picture
Offline
Joined: 01/29/2017 - 09:25
No problem

No problem! And thanks, it works now using the RAM specification.

Log in or register to post comments