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

Fix for missing scores in case of fiml. #373

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

jhorzek
Copy link
Contributor

@jhorzek jhorzek commented Jul 22, 2024

When estimating a model with fiml, only the scores of the first missingness-group are reported by lavScores. This is due to the seq_along function always evaluating to 1. I replaced seq_along with seq_len, which fixes the issue.

Example:

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:5, "x3"] <- NA

# if there are missing data points,.

fit <- sem(model, 
           data = PoliticalDemocracy_NA,
           missing = "ml")
lavScores(fit) |>
  head()

Note that the first five lines are all zeros because they are skipped in the for-loop.

Only scores for the first group were reported due to seq_along always evaluating to 1.
@yrosseel yrosseel merged commit 5c2065f into yrosseel:master Aug 1, 2024
5 checks passed
@yrosseel
Copy link
Owner

yrosseel commented Aug 1, 2024

Thanks. Merged now.

@jhorzek jhorzek deleted the fix_scores branch August 2, 2024 05:40
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

Successfully merging this pull request may close these issues.

2 participants