# Simulate a small dataset with a single visit, a treatment group and a
# baseline covariate to adjust for.
set.seed(101)
dat <- data.frame(
visit = factor("visit_1"),
group = factor(rep(c("Control", "Intervention"), each = 50)),
basval = rnorm(100)
)
dat$outcome <- 5 + 2 * (dat$group == "Intervention") + dat$basval + rnorm(100)
vars <- set_vars(
outcome = "outcome",
group = "group",
visit = "visit",
covariates = "basval"
)
# Estimated treatment effect and least square means for the single visit.
# In a full `rbmi` analysis, `ancova()` is passed to `analyse()` rather than
# called directly; see [analyse()].
ancova(dat, vars)
# Multi-arm ANCOVA with a bespoke, named set of contrasts. With three groups
# the default would compare each active arm against the reference ("Placebo");
# here we additionally request the "High" vs "Low" contrast. Explicit contrasts
# must be named, and the names become the output parameter names.
set.seed(102)
dat3 <- data.frame(
visit = factor("visit_1"),
group = factor(
rep(c("Placebo", "Low", "High"), each = 50),
levels = c("Placebo", "Low", "High")
),
basval = rnorm(150)
)
dat3$outcome <- 5 +
2 * (dat3$group == "Low") +
4 * (dat3$group == "High") +
dat3$basval +
rnorm(150)
vars3 <- set_vars(
outcome = "outcome",
group = "group",
visit = "visit",
covariates = "basval",
group_contrasts = list(
low_vs_pbo = c("Low", "Placebo"),
high_vs_pbo = c("High", "Placebo"),
high_vs_low = c("High", "Low")
)
)
# Output names: `low_vs_pbo`, `high_vs_pbo`, `high_vs_low`, plus
# `lsm_ref` / `lsm_alt` / `lsm_alt2`.
names(ancova(dat3, vars3))
Run the code above in your browser using DataLab