Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in lavScore with missing data #372

Open
jhorzek opened this issue Jul 22, 2024 · 2 comments
Open

Error in lavScore with missing data #372

jhorzek opened this issue Jul 22, 2024 · 2 comments

Comments

@jhorzek
Copy link
Contributor

jhorzek commented Jul 22, 2024

Hi,

I just ran into some errors with the updated version of the lavScore function that sent me down a small rabbit hole :). According to the comments, the function was updated in version 0.5-17 to always use all cases - even those with missings. However, if I try to get the scores of a model with listwise deletion, I get an error:

library(lavaan)

model <- ' 
  # latent variable definitions
     ind60 =~ x1 + x2 + x3
     dem60 =~ y1 + a*y2 + b*y3 + c*y4
     dem65 =~ y5 + a*y6 + b*y7 + c*y8

  # regressions
    dem60 ~ ind60
    dem65 ~ ind60 + dem60
'

PoliticalDemocracy_NA <- PoliticalDemocracy
PoliticalDemocracy_NA[1, "x3"] <- NA

# if there are missing data points, the scores function runs into errors.
fit <- sem(model, 
           data = PoliticalDemocracy_NA)
lavScores(fit)
# Error in t(X) - lavsamplestats@mean[[g]] %*% J : non-conformable arrays

This error occurs because all data points with missings have been removed from data X, but J is still based on the full sample size (see here).

Best,
Jannik

@jhorzek
Copy link
Contributor Author

jhorzek commented Jul 22, 2024

I've also found a separate bug in lavScores that is resolved in a pull request.

@yrosseel
Copy link
Owner

yrosseel commented Aug 1, 2024

Indeed. The code in lavScores() is very old, and needs to be revised. It did not follow up on changes that were made later. I will have a good look at this in the next days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants