# \donttest{
generate_test_data <- function(
n_rows = 500,
n_cols = 1,
case = 1,
x_var = 0.5,
eps_var = 0.9,
a = 0.8,
b = -0.2
) {
# Generate X variables - fixed to match comparison
X <- as.data.frame(replicate(n_cols, rnorm(n_rows, 0, sqrt(x_var))))
colnames(X) <- paste0("x", 1:n_cols)
# Generate Y - fixed coefficients to match comparison
eps <- rnorm(n_rows, 0, sqrt(eps_var))
if (case == 1) {
# Use fixed coefficient of 1 for all x variables to match: y = -1 + x1 + epsilon
X$Y <- as.vector(-1 + as.matrix(X) %*% rep(1, n_cols) + eps)
}
else if (case == 2) {
X$Y <- -2 + 0.5 * exp(as.matrix(X) %*% rep(1, n_cols)) + eps
}
else if (case == 3) {
X$Y <- -1 + sin(2 * as.matrix(X) %*% rep(1, n_cols)) + eps
}
else if (case == 4) {
X$Y <- -1 + 0.4 * as.matrix(X)^3 %*% rep(1, n_cols) + eps
}
Y_original <- X$Y
# Missingness mechanism - identical to comparison
pi_obs <- 1 / (1 + exp(-(a + b * X$Y)))
# Create missing values
mask <- runif(nrow(X)) > pi_obs
mask[1] <- FALSE # Ensure at least one observation is not missing
X$Y[mask] <- NA
return(list(X = X, Y_original = Y_original))
}
res_test_data <- generate_test_data(n_rows = 500, n_cols = 1, case = 1)
x <- res_test_data$X
exptilt_config <- exptilt_engine(
y_dens = 'normal',
control = list(maxit = 10),
stopping_threshold = 0.1,
standardize = FALSE,
family = 'logit',
bootstrap_reps = 5
)
formula = Y ~ x1
res <- nmar(formula = formula, data = x, engine = exptilt_config, trace_level = 1)
summary(res)
# }
Run the code above in your browser using DataLab