# Create Model
model <- (
outcome('Y')
+ within_predictor('X')
+ effect_size(icc = 0.1)
)
# Set seed
set.seed(198723)
# Create data set
model |> generate(5, 50) -> mydata
# Induce missing data with built-in function
model |> generate(50, 5, mechanism = MCAR(0.25)) -> mydata_mcar
# Induce missing data with custom function
model |> generate(50, 5, mechanism = \(data) {
# `data` will be the `mp_data` used
within(data, {
# MCAR Process
Y <- ifelse(runif(NROW(data)) < 0.5, Y, NA)
})
}) -> mydata_mcar_custom
Run the code above in your browser using DataLab