# Note everything is wrapped in dontrun to avoid long runtimes of examples (tests are
# still in place). Reduce the number of sample sizes and/or iterations to avoid long
# runtimes
if (FALSE) {
# A simple use case with default models and test data (we run only with a few sample
# sizes to reduce runtime of examples)
rpm <- repeat_power_marginaleffect(
target_effect = 0.9,
exposure_prob = 0.5
)
plot(rpm)
################################
# Create model from a poisson family and estimate the power of rate ratio with
# several arguments passed to power_marginaleffect
################################
b1 <- 0.9
b2 <- 0.2
b3 <- -0.4
b4 <- -0.6
train_pois <- glm_data(
Y ~ b1*log(X1)+b2*X2+b3*X3+b4*X2*X3,
X1 = runif(1e3, min = 1, max = 10),
X2 = rnorm(1e3),
X3 = rgamma(1e3, shape = 1),
family = poisson()
)
# Define models to compare fit to training data
ancova_prog_list <- list(
ANCOVA = glm(Y ~ X1 + X2 + X3, data = train_pois, family = poisson),
"ANCOVA with prognostic score" = fit_best_learner(list(mod = Y ~ X1 + X2 + X3), data = train_pois)
)
# Create a function that produces data to predict on
test_pois_fun <- function(n) {
glm_data(
Y ~ b1*log(X1)+b2*X2+b3*X3+b4*X2*X3,
X1 = runif(n, min = 1, max = 10),
X2 = rnorm(n),
X3 = rgamma(n, shape = 1),
family = poisson()
)
}
# Specify a bunch of different arguments that are passed to power_marginaleffect()
## Run for 2 sample sizes to reduce runtime
rpm_rr <- repeat_power_marginaleffect(
model_list = ancova_prog_list,
test_data_fun = test_pois_fun,
ns = seq(100, 200), n_iter = 1,
var1 = function(var0) 1.1 * var0,
kappa1_squared = function(kap0) 1.1 * kap0,
estimand_fun = "rate_ratio",
target_effect = 1.4,
exposure_prob = 1/2,
margin = 0.8
)
plot(rpm_rr2)
}
Run the code above in your browser using DataLab