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) 149.152519  59.14165 2.5219541 1852.746 0.01175371
#> 2         bmi   1.356159   2.05894 0.6586684 2346.742 0.51017334
#> 3    age40-59  12.997701  22.39382 0.5804146  657.206 0.56183401
#> 4    age60-99   2.609238  20.72175 0.1259178 2068.888 0.89980921
#> 5      hypyes  15.886792  18.96335 0.8377628 1331.575 0.40231425