| inject_missingness | R Documentation |
Blanks cells of data under one of the three standard mechanisms. "MCAR"
gives every row the same probability proportion, so missingness depends on
nothing. "MAR" makes it depend on the fully observed predictor, which is
itself never made missing. "MNAR" makes each target variable's missingness
depend on its own value, so the values that disappear are not a random sample
of them. For MAR and MNAR the probability increases with the driving
variable's rank: its ties-averaged rank mapped into (0, 1), or 0.5 for a
missing or constant driver, scaled by the multiplier that makes the mean
probability equal proportion, and capped at 1. Each MAR target therefore
shares one probability vector, while each MNAR target gets its own.
inject_missingness(
data,
mechanism = c("MCAR", "MAR", "MNAR"),
proportion = 0.1,
variables = NULL,
predictor = NULL,
seed = NULL
)
data |
Complete base |
mechanism |
Missingness mechanism, one of |
proportion |
Target missing fraction, the mean cell probability rather
than a realized count. A single number between 0 and 1, defaulting to
|
variables |
Variables to make missing. A character vector of column
names, or |
predictor |
Fully observed predictor that drives MAR missingness. A
single string naming a column of |
seed |
Optional random seed. A single number, or |
A simulab_sim base data.frame with the columns and rows of
data, the drawn cells of the target variables replaced by NA.
Components: missingness, the cell-level mask reached with
as.data.frame(x, what = "missingness"), one row per observation and
target variable with columns observation, variable, probability,
the logical missing and mechanism; and missingness_summary, one row
per target variable with columns variable, realized_proportion and
target_proportion.
data <- data.frame(id = 1:200, x = stats::rnorm(200), y = stats::rnorm(200))
result <- inject_missingness(
data, mechanism = "MCAR", proportion = 0.2, variables = "y", seed = 1
)
head(result)
# MAR missingness in `y` driven by the observed predictor `x`.
head(inject_missingness(
data, mechanism = "MAR", proportion = 0.2,
variables = "y", predictor = "x", seed = 1
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.