binHS5imps | R Documentation |
A version of the classic Holzinger and Swineford (1939) dataset, with
missing data imposed on variables x5
and x9
:
x5
is missing not at random (MNAR) by deleting the lowest 30% of
x5
values.
x9
is missing at random (MAR) conditional on age, by deleting x9
values for the youngest 30% of subjects in the data.
The data are then dichotomized using a median split, and imputed 5 times
using the syntax shown in the example. The data include only the 9 tests
(x1
through x9
) and school.
Terrence D. Jorgensen (University of Amsterdam; TJorgensen314@gmail.com)
The lavaan package.
Holzinger, K., & Swineford, F. (1939). A study in factor analysis: The stability of a bifactor solution. Supplementary Educational Monograph, no. 48. Chicago, IL: University of Chicago Press.
lavaan::HolzingerSwineford1939
data(HolzingerSwineford1939, package = "lavaan")
## impose missing data for example
HSMiss <- HolzingerSwineford1939[ , c(paste("x", 1:9, sep = ""),
"ageyr","agemo","school")]
set.seed(123)
HSMiss$x5 <- ifelse(HSMiss$x5 <= quantile(HSMiss$x5, .3), NA, HSMiss$x5)
age <- HSMiss$ageyr + HSMiss$agemo/12
HSMiss$x9 <- ifelse(age <= quantile(age, .3), NA, HSMiss$x9)
## median split
HSbinary <- as.data.frame( lapply(HSMiss[ , paste0("x", 1:9)],
FUN = cut, breaks = 2, labels = FALSE) )
HSbinary$school <- HSMiss$school
## impute binary missing data using mice package
library(mice)
set.seed(456)
miceImps <- mice(HSbinary)
## save imputations in a list of data.frames
binHS5imps <- list()
for (i in 1:miceImps$m) binHS5imps[[i]] <- complete(miceImps, action = i)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.