Create MCAR or MAR missingness on the predictor matrix x. Missingness is
generated column-wise so that each predictor receives approximately the same
missing-data proportion, matching the simulation strategy used in the
original work.
Usage
add_missingness(
x,
y,
mechanism = c("MCAR", "MAR"),
missing_prop,
seed = NULL,
mar_y_bias = 0.8
)Arguments
- x
Predictor matrix or data frame.
- y
Numeric response vector.
- mechanism
Missingness mechanism:
"MCAR"or"MAR".- missing_prop
Missing-data proportion as a fraction (
0.05) or a percentage (5).- seed
Optional random seed. If supplied, it is used only for this call.
- mar_y_bias
Proportion of missing values assigned to the upper half of the observed
yvalues under the MAR mechanism.
Examples
sim <- simulate_pls_data(n = 20, p = 10, true_ncomp = 2, seed = 1)
miss <- add_missingness(sim$x, sim$y, mechanism = "MCAR", missing_prop = 10, seed = 2)
mean(is.na(miss$x_incomplete))
#> [1] 0.1