bschmalbach / ezCutoffs

R-package ezCutoffs
0 stars 0 forks source link

Missing data cannot be handled by default #2

Closed martscht closed 5 years ago

martscht commented 5 years ago

When using listwise deletion (the lavaan default) missing data is handled incorrectly. The Problem is probably using inspect() in line 168 to determine N, which removes all missings by default, while varTable in line 221 does not. Here's a MWE:

sig <- matrix(.7, ncol = 5, nrow = 5)
diag(sig) <- 1
dats <- mvtnorm::rmvnorm(200, rep(0, 5), sig)
dats[sample(c(TRUE, FALSE), length(dats), TRUE, c(.2, .8))] <- NA
dats <- as.data.frame(dats)
names(dats) <- paste0('y', 1:5)

mod <- paste0('f =~ ', paste0('y', 1:5, collapse = ' + '))

# Works
ezCutoffs::ezCutoffs(mod, dats, n_rep = 10)

# Does not
ezCutoffs::ezCutoffs(mod, dats, n_rep = 10, missing_data = 'missing')

# Works again
ezCutoffs::ezCutoffs(mod, dats, n_rep = 10, missing_data = 'missing', missing = 'fiml')
jpirmer commented 5 years ago

I think this should be resolved now:

sig <- matrix(.7, ncol = 5, nrow = 5) diag(sig) <- 1 dats <- mvtnorm::rmvnorm(200, rep(0, 5), sig) dats[sample(c(TRUE, FALSE), length(dats), TRUE, c(.2, .8))] <- NA dats <- as.data.frame(dats) names(dats) <- paste0('y', 1:5)

mod <- paste0('f =~ ', paste0('y', 1:5, collapse = ' + '))

Works

ezCutoffs::ezCutoffs(mod, dats, n_rep = 10)

Does now

ezCutoffs::ezCutoffs(mod, dats, n_rep = 10, missing_data = 'missing')