Calculating factor scores from a fited model

75 views
Skip to first unread message

Ulf Larsson

unread,
Feb 4, 2025, 12:06:28 PM2/4/25
to lav...@googlegroups.com
Hi, I am trying to calculate factor scores for a new person not in the sample on which I fitted my 2-factor CFA model. Indicators are items in a questionnaire on a likert scale, thus ordered. My original data is numeric. I changed to ordered data and the same with the new person and using str (data) they both look like ordered. I have tried "everything" and I always get this error message: "Error: lavaan->lav_predict_internal():  mismatch number of categories for some ordered variables in newdata compared to original data." 
When using lavInspect, however, original data seems to still be numeric. So, could someone please help me with some guidelines to get this right from the beginning?

Regards
Ulf L.

Yves Rosseel

unread,
Feb 5, 2025, 3:02:04 AM2/5/25
to lav...@googlegroups.com
This indeed not trivial when data is categorical. This is due to the
fact that 'newdata' is processed just like the original data, and then
we check if newdata set has the same properties as the original data.
For categorical data, this also implies we need the same number of
categories for all categorical variables.

Instead of providing a single 'not-in-sample' profile, you should add
many more, so that for each variable, all possible categories occur at
least one.

A simple trick that I use is to copy the full dataset (or a big chunk of
it), and just add the 'not-in-sample' profile to the end. And then use
this augmented dataset as the 'newdata' data.

Yves.

Ulf Larsson

unread,
Feb 7, 2025, 9:28:31 AM2/7/25
to lavaan
Thank you! I understand how to work around it. However, we have a need to evaluate the patients responses on this 3-factors each on 2 latent factors questionnaire to measure Fear of Falling. This ought to be done immediately by a physiotherapist in front of the patient in a simple way. I have tried to extract the weight matrix to be multiplied with raw scores on indicators, which is obviously wrong. So I wonder whether it would be possible to use values, like the centre (median or mean) within the -infinity/thresholds/+infinity to multiply with weights?
Reply all
Reply to author
Forward
0 new messages