| sjt.glm {sjPlot} | R Documentation |
Summarizes (multiple) fitted generalized linear models (odds ratios, ci, p-values...) as HTML table, or saves them as file. The fitted models may have different predictors, e.g. when comparing different stepwise fitted models.
sjt.glm(..., pred.labels = NULL, depvar.labels = NULL, remove.estimates = NULL, group.pred = TRUE, exp.coef = TRUE, p.numeric = TRUE, emph.p = FALSE, p.zero = FALSE, robust = FALSE, separate.ci.col = TRUE, newline.ci = TRUE, show.ci = TRUE, show.se = FALSE, show.header = FALSE, show.col.header = TRUE, show.r2 = FALSE, show.icc = FALSE, show.re.var = FALSE, show.loglik = FALSE, show.aic = FALSE, show.aicc = FALSE, show.dev = FALSE, show.hoslem = FALSE, show.family = FALSE, show.chi2 = FALSE, string.pred = "Predictors", string.dv = "Dependent Variables", string.interc = "(Intercept)", string.obs = "Observations", string.est = NULL, string.ci = "CI", string.se = "std. Error", string.p = "p", ci.hyphen = " – ", digits.est = 2, digits.p = 3, digits.ci = 2, digits.se = 2, digits.summary = 3, cell.spacing = 0.2, cell.gpr.indent = 0.6, sep.column = TRUE, CSS = NULL, encoding = NULL, file = NULL, use.viewer = TRUE, no.output = FALSE, remove.spaces = TRUE)
... |
One or more fitted generalized linear (mixed) models. |
pred.labels |
Character vector with labels of predictor variables.
If not |
depvar.labels |
Character vector with labels of dependent variables of all fitted models. See 'Examples'. |
remove.estimates |
Numeric vector with indices (order equals to row index of |
group.pred |
Logical, if |
exp.coef |
Logical, if |
p.numeric |
Logical, if |
emph.p |
Logical, if |
p.zero |
logical, if |
robust |
Logical, if |
separate.ci.col |
Logical, if |
newline.ci |
Logical, if |
show.ci |
Logical, if |
show.se |
Logical, if |
show.header |
Logical, if |
show.col.header |
Logical, if |
show.r2 |
Logical, if |
show.icc |
Logical, if |
show.re.var |
Logical, if |
show.loglik |
Logical, if |
show.aic |
Logical, if |
show.aicc |
Logical, if |
show.dev |
Logical, if |
show.hoslem |
Logical, if |
show.family |
Logical, if |
show.chi2 |
Logical, if |
string.pred |
Character vector,used as headline for the predictor column.
Default is |
string.dv |
Character vector, used as headline for the
dependent variable columns. Default is |
string.interc |
Character vector, used as headline for the Intercept row.
Default is |
string.obs |
character vector, used in the summary row for the count of observation
(cases). Default is |
string.est |
Character vector, used for the column heading of estimates. |
string.ci |
Character vector, used for the column heading of confidence interval values. Default is |
string.se |
Character vector, used for the column heading of standard error values. Default is |
string.p |
Character vector, used for the column heading of p values. Default is |
ci.hyphen |
Character vector, indicating the hyphen for confidence interval range. May be an HTML entity. See 'Examples'. |
digits.est |
Amount of decimals for estimates |
digits.p |
Amount of decimals for p-values |
digits.ci |
Amount of decimals for confidence intervals |
digits.se |
Amount of decimals for standard error |
digits.summary |
Amount of decimals for values in model summary |
cell.spacing |
Numeric, inner padding of table cells. By default, this value is 0.2 (unit is cm), which is
suitable for viewing the table. Decrease this value (0.05 to 0.1) if you want to import the table
into Office documents. This is a convenient argument for the |
cell.gpr.indent |
Indent for table rows with grouped factor predictors. Only applies
if |
sep.column |
Logical, if |
CSS |
A |
encoding |
String, indicating the charset encoding used for variable and
value labels. Default is |
file |
Destination file, if the output should be saved as file.
If |
use.viewer |
Logical, if |
no.output |
Logical, if |
remove.spaces |
Logical, if |
See 'Details' in sjt.frq.
Invisibly returns
the web page style sheet (page.style),
the web page content (page.content),
the complete html-output (page.complete) and
the html-table with inline-css for use with knitr (knitr)
for further use.
If exp.coef = TRUE and Odds Ratios are reported, standard errors
for generalized linear (mixed) models are not on the untransformed
scale, as shown in the summary()-method. Rather, sjt.glm()
uses adjustments according to the delta method for approximating standard
errors of transformed regression parameters (see se).
If exp.coef = FALSE and log-Odds Ratios are reported, the standard
errors are untransformed.
Futhermore, see 'Notes' in sjt.frq.
# prepare dummy variables for binary logistic regression
swiss$y1 <- ifelse(swiss$Fertility < median(swiss$Fertility), 0, 1)
swiss$y2 <- ifelse(swiss$Infant.Mortality < median(swiss$Infant.Mortality), 0, 1)
swiss$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 ~ Education + Examination + Catholic, data = swiss,
family = binomial(link = "logit"))
fitOR2 <- glm(y2 ~ Education + Examination + Catholic, data = swiss,
family = binomial(link = "logit"))
fitOR3 <- glm(y3 ~ Education + Examination + Catholic, data = swiss,
family = binomial(link = "logit"))
## Not run:
# open HTML-table in RStudio Viewer Pane or web browser
sjt.glm(fitOR1, fitOR2,
depvar.labels = c("Fertility", "Infant Mortality"),
pred.labels = c("Education", "Examination", "Catholic"),
ci.hyphen = " to ")
# open HTML-table in RStudio Viewer Pane or web browser,
# integrate CI in OR column
sjt.glm(fitOR1, fitOR2, fitOR3,
pred.labels = c("Education", "Examination", "Catholic"),
separate.ci.col = 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,
depvar.labels = c("Fertility", "Infant Mortality", "Agriculture"),
pred.labels = c("Education", "Examination", "Catholic"))
# --------------------------------------------
# User defined style sheet
# --------------------------------------------
sjt.glm(fitOR1, fitOR2, fitOR3,
depvar.labels = c("Fertility", "Infant Mortality", "Agriculture"),
pred.labels = c("Education", "Examination", "Catholic"),
show.header = 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
# --------------------------------------------
library(sjmisc)
# load efc sample data
data(efc)
# dichtomozize service usage by "service usage yes/no"
efc$services <- sjmisc::dicho(efc$tot_sc_e, dich.by = 0, as.num = 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, string.est = "Estimate",
show.aic = TRUE, show.family = TRUE)
# --------------------------------------------
# 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, p.numeric = FALSE,
show.aic = TRUE, show.family = TRUE)
# 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, p.numeric = FALSE, separate.ci.col = FALSE,
show.aic = TRUE, show.family = TRUE, show.r2 = TRUE)
# ----------------------------------
# automatic grouping of predictors
# ----------------------------------
library(sjmisc)
# load efc sample data
data(efc)
# dichtomozize service usage by "service usage yes/no"
efc$services <- sjmisc::dicho(efc$tot_sc_e, dich.by = 0, as.num = TRUE)
# make dependency categorical
efc$e42dep <- to_factor(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_factor(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)
## End(Not run)