# Individual slope and intercept estimates?

Posted on

kme
Joined: 04/27/2022

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?

## Example Script

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.

Log in or register to post comments

In reply to Example Script 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()`

?Log in or register to post comments

## Bug

`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!Log in or register to post comments

In reply to Bug by mhunter

## Thanks for helping with this!

Log in or register to post comments

In reply to Bug by mhunter

## Thanks + Factor Score alternatives

Log in or register to post comments

## Try LISREL matrix specification

`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

Log in or register to post comments