You are here

Individual slope and intercept estimates?

7 posts / 0 new
Last post
kme's picture
kme
Offline
Joined: 04/27/2022 - 13:44
Individual slope and intercept estimates?

I'm fitting a growth curve model (not latent growth curve model yet) using intercept and slope factors, and need individuals' slope and intercept estimates.

My inclination is to get factor score estimates for the intercept and slope factors, but when I do this using mxFactorScores(), I get an error message:

"Error: In model 'FactorScoresLGCM_N' the name 'fscore' is used as a free parameter in 'FactorScoresLGCM_N.Score' but as a fixed parameter in 'FactorScoresLGCM_N.Score'.

The model itself seems to run and converge without errors or warning messages.

Any advice?

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
Example Script

I don't know what you mean by a "growth curve model" that is distinct from a "latent growth curve model".

Here is a link to a latent growth curve model script

It's easy enough to add

fs <- mxFactorScores(growthCurveFit)

to this script and successfully get factor scores.

kme's picture
kme
Offline
Joined: 04/27/2022 - 13:44
Thanks.

Thanks.

By "growth curve" I meant modeled change is in observed variables, not in latent variables per se; there's no measurement model in between the intercept and slope factors and the observed variables.

I wrote the code in terms of the matrix specification rather than path specification.

Interestingly, if I run the matrix growth curve model here:

https://github.com/OpenMx/OpenMx/blob/master/demo/LatentGrowthCurveModel_MatrixRaw.R

It runs, I can get the coefficients, but if I run your code above, i.e.,

fs <- mxFactorScores(growthCurveFit)

I get this error:

Error: In model 'FactorScoresLinearGrowthCurveModelMatrixSpecification' the name 'fscore' is used as a free parameter in 'FactorScoresLinearGrowthCurveModelMatrixSpecification.Score' but as a fixed parameter in 'FactorScoresLinearGrowthCurveModelMatrixSpecification.Score'

I admit I haven't tried the path specification but I'm assuming it wouldn't be different? Or is a path specified model necessary to use mxFactorScores()?

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
Bug

Ahh. It looks like you've found a bug with mxFactorScores(). Sorry about that! Factor scores should work in that situation (matrix spec, path spec, RAM expectation, LISREL expectation, etc.), but they are evidently broken at the moment. I'll track the problem down and write a patch shortly. The fix will be in the next release of OpenMx and available in the source version as soon as I figure it out.

My first guess is that mxFactorScores() is getting confused by RAM expectations with matrix specification; that it's not correctly figuring out which variables are latent and which are manifest. I'll post again on this thread linking to the resolution. Again, sorry for the bug!

kme's picture
kme
Offline
Joined: 04/27/2022 - 13:44
Thanks for helping with this!

Thanks for helping with this!

ElaineHoan's picture
Offline
Joined: 07/09/2023 - 17:57
Thanks + Factor Score alternatives

Thank you for addressing this issue! I was running into this error when trying to use the mxFactorScores() function on a matrix model. As I'm sure is the case for others, my project is currently dependent on generating these factor scores and I was wondering if you or anyone knew of alternative packages in R that could generate factor scores (specifically EAP) from a matrix model? Thanks again and looking forward to your update!

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
Try LISREL matrix specification

Below is a latent growth curve model in matrix form that uses the LISREL expectation. You can get factor scores from it. The bug in mxFactorScores() is only in the RAM matrix form. Path specification and LISREL specification both work fine.

I think the EAP form of factor scores is what OpenMx calls "ML" in ?mxFactorScores.

#------------------------------------------------------------------------------
# Program: LatentGrowthModel_LISREL.R  
# Author: Michael D. Hunter
# Date: 2023.07.20
# Purpose: Demonstrate a matrix-specified latent growth curve model
#  using the LISREL expectation.
#  This also tests that factor scores work.
#------------------------------------------------------------------------------
 
 
#------------------------------------------------------------------------------
# Load package(s) and data
 
require(OpenMx)
 
data(myLongitudinalData)
 
 
#------------------------------------------------------------------------------
# Specify LISREL form of latent growth curve model
 
#--------------------------------------
# Variable names
 
mnames <- names(myLongitudinalData)
lnames <- c('I', 'S')
nvar <- length(mnames)
 
#--------------------------------------
# Matrices
 
loadings <- mxMatrix(name='L', values=c(rep(1, nvar), 0:(nvar-1)),
    nrow=nvar, ncol=2, dimnames=list(mnames, lnames))
 
residuals <- mxMatrix(name='E', type='Diag', values=.2, labels='residVar',
    free=TRUE, nrow=nvar, ncol=nvar, dimnames=list(mnames, mnames))
 
lcovs <- mxMatrix(name='P', type='Symm', nrow=2, ncol=2, free=TRUE,
    values=c(1, .5, 1), labels=c('varI', 'covIS', 'varS'),
    dimnames=list(lnames, lnames))
 
intercepts <- mxMatrix(name='M', type='Zero', nrow=nvar, ncol=1,
    dimnames=list(mnames, NULL))
 
lmeans <- mxMatrix(name='K', nrow=2, ncol=1, free=TRUE, values=1,
    labels=c('meanI', 'meanS'), dimnames=list(lnames, NULL))
 
#--------------------------------------
# Data, fit function, and expectation
 
md <- mxData(myLongitudinalData, type='raw')
mf <- mxFitFunctionML()
me <- mxExpectationLISREL(LX='L', PH='P', TD='E', TX='M', KA='K')
 
#--------------------------------------
# Model
 
mod <- mxModel('LISRELGrowth',
    loadings, residuals, lcovs, intercepts, lmeans,
    md, mf, me)
 
modr <- mxRun(mod)
 
summary)(modr)
 
 
#------------------------------------------------------------------------------
# Factor scores
 
fs_ml <- mxFactorScores(modr)
fs_wml <- mxFactorScores(modr, 'WeightedML')
fs_reg <- mxFactorScores(modr, 'Regression')
 
 
#------------------------------------------------------------------------------
# Done