# Data to use
data("infert", package = "datasets")
infert2 <- infert |>
dplyr::mutate(
Age_grp = relevel(as.factor(dplyr::case_when(
age < 25 ~ "<25",
25 <= age & age < 35 ~ "25-<35",
age >= 35 ~ "35+"
)), ref="25-<35"),
Parity_grp = relevel(as.factor(dplyr::case_when(
parity == 1 ~ "1",
parity >= 2 & parity <= 3 ~ "2-3",
parity > 3 ~ "4+"
)), ref="2-3"),
induced = relevel(as.factor(induced), ref="0"),
case = relevel(as.factor(case), ref="0"),
spontaneous = relevel(as.factor(spontaneous), ref="0")
)
# Two outcomes (Parity_grp, case) with their own set of models, three
# variables included in separate models (spontaneous,induced and education)
# and one variable that is included in all models (Age_grp)
test <- odds_ratio_function_repeated(
normaldata = infert2,
outcomevar = c("Parity_grp","case"),
expvars = c("spontaneous","induced","education"),
adjustment_fixed = c("Age_grp")
)
# One outcome (case), two variables included in separate models
# (spontaneous and induced), one variable included in all models (Age_grp)
# and all analyses made for each level of another variable (Parity_grp)
test2 <- odds_ratio_function_repeated(
normaldata = infert2,
outcomevar = c("case"),
expvars = c("spontaneous","induced"),
adjustment_fixed = c("Age_grp"),
by_var = "Parity_grp"
)
Run the code above in your browser using DataLab