# Generate some data to showcase example
n <- 100
exp_prob <- .5
dat_gaus <- glm_data(
Y ~ 1+1.5*X1+2*A,
X1 = rnorm(n),
A = rbinom(n, 1, exp_prob),
family = gaussian()
)
# Fit the model
ate <- rctglm(formula = Y ~ .,
exposure_indicator = A,
exposure_prob = exp_prob,
data = dat_gaus,
family = gaussian)
# Pull information on estimand
estimand(ate)
## Another example with different family and specification of estimand_fun
dat_binom <- glm_data(
Y ~ 1+1.5*X1+2*A,
X1 = rnorm(n),
A = rbinom(n, 1, exp_prob),
family = binomial()
)
rr <- rctglm(formula = Y ~ .,
exposure_indicator = A,
exposure_prob = exp_prob,
data = dat_binom,
family = binomial(),
estimand_fun = "rate_ratio")
odds_ratio <- function(psi1, psi0) (psi1*(1-psi0))/(psi0*(1-psi1))
or <- rctglm(formula = Y ~ .,
exposure_indicator = A,
exposure_prob = exp_prob,
data = dat_binom,
family = binomial,
estimand_fun = odds_ratio)
Run the code above in your browser using DataLab