Plot odds ratios (forest plots) of multiple fitted glm's

# prepare dummy variables for binary logistic regression
y1 <- ifelse(swiss$Fertility < median(swiss$Fertility), 0, 1)
y2 <- ifelse(swiss$Infant.Mortality < median(swiss$Infant.Mortality), 0, 1)
y3 <- ifelse(swiss$Agriculture<median(swiss$Agriculture), 0, 1)

# Now fit the models. Note that all models share the same predictors
# and only differ in their dependent variable (y1, y2 and y3)
fitOR1 <- glm(y1 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))
fitOR2 <- glm(y2 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))
fitOR3 <- glm(y3 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))

# plot multiple models
sjp.glmm(fitOR1, fitOR2, fitOR3, facet.grid = TRUE)
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead

plot of chunk sjp.glmm

# plot multiple models with legend labels and point shapes instead of value  labels
sjp.glmm(fitOR1, fitOR2, fitOR3,
         labelDependentVariables = c("Fertility",
                                     "Infant Mortality",
                                     "Agriculture"),
         showValueLabels = FALSE,
         showPValueLabels = FALSE,
         fade.ns = TRUE,
         usePShapes = TRUE)
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead

plot of chunk sjp.glmm

# plot multiple models from nested lists argument
all.models <- list()
all.models[[1]] <- fitOR1
all.models[[2]] <- fitOR2
all.models[[3]] <- fitOR3

sjp.glmm(all.models)
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead

plot of chunk sjp.glmm

# -------------------------------
# Predictors for negative impact
# of care. Data from the EUROFAMCARE
# sample dataset
# -------------------------------
library(sjmisc)
data(efc)

# create binary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)
# create dummy variables for educational status
edu.mid <- ifelse(efc$c172code == 2, 1, 0)
edu.high <- ifelse(efc$c172code == 3, 1, 0)
# create data frame for fitted model
mydat <- data.frame(y = as.factor(y),
                    sex = as.factor(efc$c161sex),
                    dep = as.factor(efc$e42dep),
                    barthel = as.numeric(efc$barthtot),
                    edu.mid = as.factor(edu.mid),
                    edu.hi = as.factor(edu.high))

fit1 <- glm(y ~ sex + edu.mid + edu.hi,
            data = mydat,
            family = binomial(link = "logit"))
fit2 <- update(fit1, . ~ . + barthel)
fit3 <- update(fit2, . ~ . + dep)

sjp.glmm(fit1, fit2, fit3)
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead

plot of chunk sjp.glmm