Skip to contents

This helper function creates a valid where matrix. The where matrix is an argument to the mice function. It has the same size as data and specifies which values are to be imputed (TRUE) or nor (FALSE).

Usage

make.where(data, keyword = c("missing", "all", "none", "observed"))

Arguments

data

A data.frame with the source data

keyword

An optional keyword, one of "missing" (missing values are imputed), "observed" (observed values are imputed), "all" and "none". The default is keyword = "missing"

Value

A matrix with logical

Examples

head(make.where(nhanes), 3)
#>     age   bmi   hyp   chl
#> 1 FALSE  TRUE  TRUE  TRUE
#> 2 FALSE FALSE FALSE FALSE
#> 3 FALSE  TRUE FALSE FALSE

# create & analyse synthetic data
where <- make.where(nhanes2, "all")
imp <- mice(nhanes2,
  m = 10, where = where,
  print = FALSE, seed = 123
)
fit <- with(imp, lm(chl ~ bmi + age + hyp))
summary(pool.syn(fit))
#>          term   estimate std.error statistic         df    p.value
#> 1 (Intercept) 131.574797 63.262279 2.0798302  970.66355 0.03780306
#> 2         bmi   1.774018  2.298282 0.7718887  795.99667 0.44040943
#> 3    age40-59  18.895593 20.771314 0.9096966 1513.73872 0.36312737
#> 4    age60-99  29.884250 20.936150 1.4273995  655.88704 0.15394068
#> 5      hypyes   8.784214 21.349328 0.4114515   91.38507 0.68170484