Individual slope and intercept estimates?

Posted on
No user picture. kme Joined: 04/27/2022
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?

Replied on Thu, 07/06/2023 - 13:31
Picture of user. mhunter Joined: 07/31/2009

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](https://github.com/OpenMx/OpenMx/blob/master/demo/LatentGrowthCurveModel_PathRaw_ObjectAdd.R)

It's easy enough to add

fs <- mxFactorScores(growthCurveFit)

to this script and successfully get factor scores.

Replied on Thu, 07/06/2023 - 19:13
No user picture. kme Joined: 04/27/2022

In reply to by mhunter

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](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()?

Replied on Fri, 07/07/2023 - 00:34
Picture of user. mhunter Joined: 07/31/2009

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!

Replied on Mon, 07/17/2023 - 12:02
No user picture. ElaineHoan Joined: 07/09/2023

In reply to by mhunter

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!
Replied on Thu, 07/20/2023 - 10:57
Picture of user. mhunter Joined: 07/31/2009

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