# NOT RUN {
library(sjmisc)
library(lme4)
# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dich.by = "median")
# fit model
fit <- glmer(Reaction.dicho ~ Days + (Days | Subject),
data = sleepstudy, family = binomial("logit"))
# convert to relative risks
odds_to_rr(fit)
data(efc)
# create binary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)
# create data frame for fitted model
mydf <- data.frame(
y = as.factor(y),
sex = to_factor(efc$c161sex),
dep = to_factor(efc$e42dep),
barthel = efc$barthtot,
education = to_factor(efc$c172code)
)
# fit model
fit <- glm(y ~., data = mydf, family = binomial(link = "logit"))
# convert to relative risks
odds_to_rr(fit)
# replicate OR/RR for coefficient "sex" from above regression
# p0 ~ .44, or ~ 1.914
prop.table(table(mydf$y, mydf$sex))
or_to_rr(1.914, 0.1055 / (.1324 + .1055))
# }
Run the code above in your browser using DataLab