### Binomial outcome
data(logan, package = "survival")
resp <- levels(logan$occupation)
n <- nrow(logan)
indx <- rep(1:n, length(resp))
logan2 <- data.frame(
logan[indx,],
id = indx,
tocc = factor(rep(resp, each=n))
)
logan2$case <- (logan2$occupation == logan2$tocc)
logan2$case <- as.factor(logan2$case)
logan2$case <- relevel(logan2$case, ref = "FALSE")
# Standard binomial logistic regression but using interaction for exposures:
func_est1 <- odds_ratio_function(
logan2,
outcomevar = "case",
expvars = c("tocc", "education", "tocc:education")
)
# \donttest{
# Conditional binomial logistic regression with some extra text added:
func_est2 <- odds_ratio_function(
logan2,
outcomevar = "case",
expvars = c("tocc", "tocc:education"),
matchgroup = "id",
textvar = "Testing function"
)
# }
# Standard binomial logistic regression as survey data with no prepared
# weights:
func_est3 <- odds_ratio_function(
logan2,
outcomevar = "case",
expvars = c("tocc", "education"),
surveydata = TRUE
)
# Example changing significance level and the number of decimals in fixed
# output and adding some text:
func_est4 <- odds_ratio_function(
logan2,
outcomevar = "case",
expvars = c("tocc", "education"),
number_decimals = 5,
alpha = 0.01,
textvar = "Testing function"
)
# Getting raw output from the regression function:
func_est5 <- odds_ratio_function(
logan2,
outcomevar = "case",
expvars = c("tocc", "education"),
model_object = TRUE
)
### Polytomous/multinomial outcome
data(api, package = "survey")
# As normal data, but using weights:
func_est6 <- odds_ratio_function(
apiclus2,
outcomevar = "stype",
expvars = c("ell", "meals", "mobility", "sch.wide"),
weightvar = "pw"
)
# As survey data with weights:
func_est7 <- odds_ratio_function(
apiclus2,
outcomevar = "stype",
expvars = c("ell", "meals", "mobility"),
weightvar = "pw", surveydata = TRUE
)
# Binomial logistic regression with same data (by removing all observations
# with a specific value of outcome):
func_est8 <- odds_ratio_function(
apiclus2,
outcomevar = "stype",
expvars = c("ell", "meals", "mobility"),
weightvar = "pw",
values_to_remove = c("E")
)
Run the code above in your browser using DataLab