
Imputation by a two-level logistic model using glmer
Source: R/mice.impute.2l.bin.R
mice.impute.2l.bin.RdImputes univariate systematically and sporadically missing data
using a two-level logistic model using lme4::glmer()
Usage
mice.impute.2l.bin(
y,
ry,
x,
type,
wy = NULL,
intercept = TRUE,
random.effects = c("laplace", "eb", "marginal"),
...
)Arguments
- y
Vector to be imputed
- ry
Logical vector of length
length(y)indicating the the subsety[ry]of elements inyto which the imputation model is fitted. Therygenerally distinguishes the observed (TRUE) and missing values (FALSE) iny.- x
Numeric design matrix with
length(y)rows with predictors fory. Matrixxmay have no missing values.- type
Vector of length
ncol(x)identifying random and class variables. Random variables are identified by a '2'. The class variable (only one is allowed) is coded as '-2'. Fixed effects are indicated by a '1'.- wy
Logical vector of length
length(y). ATRUEvalue indicates locations inyfor which imputations are created.- intercept
Logical determining whether the intercept is automatically added.
- random.effects
Character string specifying how the random effect is drawn for sporadic clusters. One of
"laplace"(default),"eb", or"marginal". See Details.- ...
Arguments passed down to
glmer
Details
Data are missing systematically if they have not been measured, e.g., in the case where we combine data from different sources. Data are missing sporadically if they have been partially observed.
The random.effects argument controls how the cluster-specific random
effect \(b_i^*\) is drawn for clusters that have missing values:
"laplace"(default) For clusters with observed data, draws \(b_i^*\) from \(N(m_i, V_i)\) where \(m_i\) is the posterior mode (BLUP) and \(V_i\) is the Laplace-approximated posterior variance returned by
lme4::ranef(fit, condVar = TRUE). For clusters with no observed data, draws from the marginal prior \(N(0, \psi^*)\). This is the method recommended by Audigier et al. (2018)."eb"Empirical Bayes: for clusters with observed data, uses the BLUP as the mean but draws with the full marginal variance \(\psi^*\), ignoring posterior uncertainty in \(b_i\).
"marginal"Draws all \(b_i^*\) from the marginal prior \(N(0, \psi^*)\) regardless of whether the cluster has observed data. This was the original behaviour and is correct only for systematic missingness.
References
Audigier, V., White, I. R., Jolani, S., Debray, T. P. A., Quartagno, M., Carpenter, J., van Buuren, S., & Resche-Rigon, M. (2018). Multiple imputation for multilevel data with continuous and binary variables. Statistical Science, 33(2), 160-183. doi:10.1214/18-STS646
Jolani S., Debray T.P.A., Koffijberg H., van Buuren S., Moons K.G.M. (2015). Imputation of systematically missing predictors in an individual participant data meta-analysis: a generalized approach using MICE. Statistics in Medicine, 34:1841-1863.
See also
Other univariate-2l:
mice.impute.2l.lmer(),
mice.impute.2l.norm(),
mice.impute.2l.pan()
Examples
library(tidyr)
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
data("toenail2")
data <- tidyr::complete(toenail2, patientID, visit) %>%
tidyr::fill(treatment) %>%
dplyr::select(-time) %>%
dplyr::mutate(patientID = as.integer(patientID))
if (FALSE) { # \dontrun{
pred <- mice(data, print = FALSE, maxit = 0, seed = 1)$pred
pred["outcome", "patientID"] <- -2
imp <- mice(data, method = "2l.bin", pred = pred, maxit = 1, m = 1, seed = 1)
imp_laplace <- mice(data, method = "2l.bin", pred = pred, maxit = 1, m = 1,
seed = 1, random.effects = "laplace")
imp_eb <- mice(data, method = "2l.bin", pred = pred, maxit = 1, m = 1,
seed = 1, random.effects = "eb")
imp_marginal <- mice(data, method = "2l.bin", pred = pred, maxit = 1, m = 1,
seed = 1, random.effects = "marginal")
} # }