Learn R Programming

sjPlot (version 1.7)

sjt.glm: Show (and compare) generalized linear models as HTML table

Description

Shows (and compares multiple) generalized linear models (Odds Ratios) as HTML table, or saves them as file. The fitted glm's should have the same predictor variables and either
  • differ only in their response (dependent variable), to see the effect of a specific set of predictors on different responses, or
  • all have the same reponse variables, but differ in theirfamilyobjects and link function in order to see which model fits best to the data.
See parameter showFamily for details and section examples.

Usage

sjt.glm(..., file = NULL, labelPredictors = NULL,
  labelDependentVariables = NULL, stringPredictors = "Predictors",
  stringDependentVariables = "Dependent Variables",
  showHeaderStrings = FALSE, stringModel = "Model",
  stringIntercept = "(Intercept)", stringObservations = "Observations",
  stringOR = "OR", stringCI = "CI", stringSE = "std. Error",
  stringP = "p", digits.est = 2, digits.p = 3, digits.ci = 2,
  digits.se = 2, digits.summary = 3, exp.coef = TRUE,
  pvaluesAsNumbers = TRUE, boldpvalues = TRUE, showConfInt = TRUE,
  showStdError = FALSE, separateConfColumn = TRUE, newLineConf = TRUE,
  group.pred = TRUE, showAbbrHeadline = TRUE, showPseudoR = TRUE,
  showLogLik = FALSE, showAIC = FALSE, showChi2 = FALSE,
  showFamily = FALSE, remove.estimates = NULL, cellSpacing = 0.2,
  cellGroupIndent = 0.6, encoding = NULL, CSS = NULL, useViewer = TRUE,
  no.output = FALSE, remove.spaces = TRUE)

Arguments

Value

Invisibly returns a structure with
  • the web page style sheet (page.style),
  • the web page content (page.content),
  • the complete html-output (output.complete) and
  • the html-table with inline-css for use with knitr (knitr)
for further use.

See Also

Examples

Run this code
# 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 both 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"))

# open HTML-table in RStudio Viewer Pane or web browser
sjt.glm(fitOR1,
        fitOR2,
        labelDependentVariables = c("Fertility",
                                    "Infant Mortality"),
        labelPredictors = c("Education",
                            "Examination",
                            "Catholic"))

# open HTML-table in RStudio Viewer Pane or web browser,
# integrate CI in OR column
sjt.glm(fitOR1, fitOR2, fitOR3,
        labelDependentVariables = c("Fertility",
                                    "Infant Mortality",
                                    "Agriculture"),
        labelPredictors = c("Education", "Examination", "Catholic"),
        separateConfColumn = FALSE)

# open HTML-table in RStudio Viewer Pane or web browser,
# indicating p-values as numbers and printing CI in a separate column
sjt.glm(fitOR1, fitOR2, fitOR3,
        labelDependentVariables = c("Fertility",
                                    "Infant Mortality",
                                    "Agriculture"),
        labelPredictors = c("Education", "Examination", "Catholic"))


# --------------------------------------------
# User defined style sheet
# --------------------------------------------
sjt.glm(fitOR1, fitOR2, fitOR3,
        labelDependentVariables = c("Fertility",
                                    "Infant Mortality",
                                    "Agriculture"),
        labelPredictors = c("Education", "Examination", "Catholic"),
        showHeaderStrings = TRUE,
        CSS = list(css.table = "border: 2px solid;",
                   css.tdata = "border: 1px solid;",
                   css.depvarhead = "color:#003399;"))


# --------------------------------------------
# Compare models with different link functions,
# but same predictors and response
# --------------------------------------------
# load efc sample data
data(efc)
# dichtomozize service usage by "service usage yes/no"
efc$services <- dicho(efc$tot_sc_e, "v", 0, asNum = TRUE)
# fit 3 models with different link-functions
fit1 <- glm(services ~ neg_c_7 + c161sex + e42dep,
            data=efc,
            family=binomial(link="logit"))
fit2 <- glm(services ~ neg_c_7 + c161sex + e42dep,
            data=efc,
            family=binomial(link="probit"))
fit3 <- glm(services ~ neg_c_7 + c161sex + e42dep,
            data=efc,
            family=poisson(link="log"))

# compare models
sjt.glm(fit1, fit2, fit3,
        showAIC = TRUE,
        showFamily = TRUE,
        showPseudoR = FALSE)


# --------------------------------------------
# Change style of p-values and CI-appearance
# --------------------------------------------
# open HTML-table in RStudio Viewer Pane or web browser,
# table indicating p-values as stars
sjt.glm(fit1, fit2, fit3,
        pvaluesAsNumbers = FALSE,
        showAIC = TRUE,
        showFamily = TRUE,
        showPseudoR = FALSE)

# open HTML-table in RStudio Viewer Pane or web browser,
# indicating p-values as stars and integrate CI in OR column
sjt.glm(fit1, fit2, fit3,
        pvaluesAsNumbers = FALSE,
        separateConfColumn = FALSE,
        showAIC = TRUE,
        showFamily = TRUE,
        showPseudoR = FALSE)

# ----------------------------------
# automatic grouping of predictors
# ----------------------------------
# load efc sample data
data(efc)
# set variable labels
efc <- set_var_labels(efc, get_var_labels(efc))
# dichtomozize service usage by "service usage yes/no"
efc$services <- dicho(efc$tot_sc_e, "v", 0, asNum = TRUE)
# make dependency categorical
efc$e42dep <- to_fac(efc$e42dep)
# fit model with "grouped" predictor
fit <- glm(services ~ neg_c_7 + c161sex + e42dep, data=efc)

# automatic grouping of categorical predictors
sjt.glm(fit)


# ----------------------------------
# compare models with different predictors
# ----------------------------------
fit2 <- glm(services ~ neg_c_7 + c161sex + e42dep + c12hour, data=efc)
fit3 <- glm(services ~ neg_c_7 + c161sex + e42dep + c12hour + c172code, data=efc)

# print models with different predictors
sjt.glm(fit, fit2, fit3)

efc$c172code <- to_fac(efc$c172code)
fit2 <- glm(services ~ neg_c_7 + c161sex + c12hour, data=efc)
fit3 <- glm(services ~ neg_c_7 + c161sex + c172code, data=efc)

# print models with different predictors
sjt.glm(fit, fit2, fit3, group.pred = FALSE)

Run the code above in your browser using DataLab