trial <- Trial$new(
covariates = \(n) data.frame(a = rbinom(n, 1, 0.5)),
outcome = outcome_binary
)
est <- function(data) glm(y ~ a, data = data, family = binomial(logit))
trial$simulate(1e4, mean = ~ 1 + a, par = c(1, 0.5)) |> est()
# default behavior is to set all regression coefficients to 0
trial$simulate(1e4, mean = ~ 1 + a) |> est()
# intercept defaults to 0 and regression coef for a takes the provided value
trial$simulate(1e4, mean = ~ 1 + a, par = c(a = 0.5)) |> est()
# trial$simulate(1e4, mean = ~ 1 + a, par = c("(Intercept)" = 1))
# define mean model that directly works on whole covariate data, incl id and
# num columns
trial$simulate(1e4, mean = \(x) with(x, lava::expit(1 + 0.5 * a))) |>
est()
# par argument of outcome_binary is not passed on to mean function
trial$simulate(1e4,
mean = \(x, reg.par) with(x, lava::expit(reg.par[1] + reg.par[2] * a)),
reg.par = c(1, 0.8)
) |> est()
Run the code above in your browser using DataLab