| makeMissing | R Documentation |
Amputation generator for simulation studies (the variable-wise counterpart
of mice::ampute()): takes complete data, sets a controlled share of
cells to NA under a chosen missingness mechanism, and returns the
amputed data together with an attr(., "where") indicator matrix that
plugs directly into evaluation(), nrmse() and
pfc():
makeMissing(
data,
prop = 0.1,
mechanism = c("MCAR", "MAR", "MNAR"),
vars = NULL,
weights = NULL,
seed = NULL
)
data |
A complete data.frame or data.table (no missing values). |
prop |
Proportion of cells set to missing per target variable, strictly between 0 and 1. |
mechanism |
One of |
vars |
Character vector of target variables to receive missing values. Default: all columns. |
weights |
Optional named numeric vector. For |
seed |
Optional single number: applied via |
amp <- makeMissing(dat, prop = 0.2, mechanism = "MAR") imp <- vimpute(amp) evaluation(dat, imp, m = attr(amp, "where"))
Mechanisms (applied per target variable, each receiving exactly
round(prop * nrow(data)) missing cells):
"MCAR"cells are drawn uniformly at random.
"MAR"the probability of a cell going missing grows with a
weighted score of the other (observed) variables: rows are
drawn with probabilities plogis(z) where z is the
standardized weighted sum of the driver columns. Default drivers: all
numeric columns except the target, with equal weights; use
weights to select drivers and directions (negative weights make
low driver values predictive of missingness).
"MNAR"as "MAR", but the score is the target's
own standardized values, so high values are more often missing
(a weights entry named after the target flips or scales the
direction). Numeric targets only.
With several target variables the scores are computed on the complete input, so each target's mechanism conditions on the pre-amputation values of its drivers.
The amputed data, classed like the input (data.frame in,
data.frame out; data.table in, data.table out), with attributes
"where" (logical indicator matrix of the introduced missings),
"mechanism" and "prop".
Matthias Templ
evaluation(), vimpute(), kNN()
data(sleep)
complete_rows <- na.omit(sleep[, c("BodyWgt", "BrainWgt", "Sleep", "Span")])
amp <- makeMissing(complete_rows, prop = 0.2, mechanism = "MAR",
vars = "Sleep", seed = 1)
colSums(is.na(amp))
imp <- kNN(amp, imp_var = FALSE)
evaluation(complete_rows, imp, m = attr(amp, "where"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.