# \donttest{
trial <- Trial$new(
covariates = function(n) data.frame(a = rbinom(n, 1, 0.5), x = rnorm(n)),
outcome = setargs(outcome_count,
mean = ~ 1 + a*x,
par = c(1, -0.1, 0.5, 0.2),
overdispersion = 2)
)
dd <- trial$simulate(3e2)
# crude mean comparison between arms (default behavior; y ~ a)
est <- est_glm(family = poisson)
est(dd)
# linear adjustment with one covariate (y ~ a + x)
est <- est_glm(family = poisson, covariates = "x")
est(dd)
# return estimates of all linear coefficients (useful for debugging)
est <- est_glm(family = poisson, covariates = "x", target.parameter = NULL)
est(dd)
# comparing robust and non-robust standard errors of poisson estimator by
# passing robust argument via ... to lava::estimate
estimators <- list(
robust = est_glm(family = poisson),
non.robust = est_glm(family = poisson, robust = FALSE)
)
res <- do.call(rbind, lapply(estimators, \(est) est(dd)$coefmat))
rownames(res) <- names(estimators)
res
dd_factor <- dd
dd_factor$a <- as.factor(dd_factor$a)
# target parameter needs to be changed because the name of the estimated
# regression coefficient changes when encoding the treatment variable as a
# factor
est_glm(family = poisson, target.parameter = "a1")(dd_factor)
# }
Run the code above in your browser using DataLab