Learn R Programming

sjPlot (version 2.1.0)

sjt.glm: Summary of generalized linear models as HTML table

Description

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.

Usage

sjt.glm(..., pred.labels = NULL, depvar.labels = NULL, remove.estimates = NULL, group.pred = TRUE, exp.coef = TRUE, p.numeric = TRUE, emph.p = TRUE, p.zero = 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 = "OR", 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)

Arguments

...
one or more fitted generalized linear (mixed) models.
pred.labels
character vector with labels of predictor variables. If not NULL, pred.labels will be used in the first table column with the predictors' names. If NULL, variable labels are set based on label attributes (see get_label). If pred.labels = "", column names (vector names) are used as predictor labels. See 'Examples'.
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 coef(fit)) or character vector with coefficient names that indicate which estimates should be removed from the table output. The first estimate is the intercept, followed by the model predictors. The intercept cannot be removed from the table output! remove.estimates = c(2:4) would remove the 2nd to the 4th estimate (1st to 3rd predictor after intercept) from the output. remove.estimates = "est_name" would remove the estimate est_name. Default is NULL, i.e. all estimates are printed.
group.pred
logical, if TRUE (default), automatically groups table rows with factor levels of same factor, i.e. predictors of type factor will be grouped, if the factor has more than two levels. Grouping means that a separate headline row is inserted to the table just before the predictor values.
exp.coef
logical, if TRUE (default), regression coefficients and confidence intervals are exponentiated. Use FALSE for non-exponentiated coefficients (log-odds) as provided by the summary function.
p.numeric
logical, if TRUE, the p-values are printed as numbers. If FALSE (default), asterisks are used.
emph.p
logical, if TRUE (default), significant p-values are shown bold faced.
p.zero
logical, if TRUE, p-values have a leading 0 before the period (e.g. 0.002), else p-values start with a period and without a zero (e.g. .002).
separate.ci.col
if TRUE, the CI values are shown in a separate table column. Default is FALSE.
newline.ci
logical, if TRUE and separate.ci.col = FALSE, inserts a line break between estimate and CI values. If FALSE, CI values are printed in the same line as estimate values.
show.ci
logical, if TRUE (default), the confidence intervall is also printed to the table. Use FALSE to omit the CI in the table.
show.se
logical, if TRUE, the standard errors are also printed. Default is FALSE.
show.header
logical, if TRUE, the header strings string.pred and string.dv are shown. By default, they're hidden.
show.col.header
logical, if TRUE (default), the table data columns have a headline with abbreviations for estimates, std. beta-values, confidence interval and p-values.
show.r2
logical, if TRUE (default), the pseudo R2 values for each model are printed in the model summary. R2cs is the Cox-Snell-pseudo R-squared value, R2n is Nagelkerke's pseudo R-squared value and D is Tjur's Coefficient of Discrimination (see cod).
show.icc
logical, if TRUE, the intra-class-correlation for each model is printed in the model summary. Only applies to mixed models.
show.re.var
logical, if TRUE, the variance parameters for the random effects for each model are printed in the model summary. Only applies to mixed models. For details output, see 'Note' in icc.
show.loglik
logical, if TRUE, the Log-Likelihood for each model is printed in the model summary. Default is FALSE.
show.aic
logical, if TRUE, the AIC value for each model is printed in the model summary. Default is FALSE.
show.aicc
logical, if TRUE, the second-order AIC value for each model is printed in the model summary. Default is FALSE.
show.dev
logical, if TRUE, the deviance for each model is printed in the model summary.
show.hoslem
logical, if TRUE, a Hosmer-Lemeshow-Goodness-of-fit-test is performed. A well-fitting model shows no significant difference between the model and the observed data, i.e. the reported p-values should be greater than 0.05.
show.family
logical, if TRUE, the family object and link function for each fitted model are printed. Can be used in case you want to compare models with different link functions and same predictors and response, to decide which model fits best. See family for more details. It is recommended to inspect the model AIC (see show.aic) to get a decision help for which model to choose.
show.chi2
logical, if TRUE, the p-value of the chi-squared value for each model's residual deviance against the null deviance is printed in the model summary. Default is FALSE. A well-fitting model with predictors should significantly differ from the null-model (without predictors), thus, a p-value less than 0.05 indicates a good model-fit.
string.pred
character vector,used as headline for the predictor column. Default is "Predictors".
string.dv
character vector, used as headline for the dependent variable columns. Default is "Dependent Variables".
string.interc
character vector, used as headline for the Intercept row. Default is "Intercept".
string.obs
character vector, used in the summary row for the count of observation (cases). Default is "Observations".
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 "CI".
string.se
character vector, used for the column heading of standard error values. Default is "std. Error".
string.p
character vector, used for the column heading of p values. Default is "p".
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 CSS argument for changing cell spacing, which would be: CSS = list(css.thead = "padding:0.2cm;", css.tdata = "padding:0.2cm;").
cell.gpr.indent
indent for table rows with grouped factor predictors. Only applies if group.pred = TRUE.
sep.column
logical, if TRUE, an empty table column is added after each model column, to add margins between model columns. By default, this column will be added to the output; however, when copying tables to office applications, it might be helpful not to add this separator column when modifying the table layout.
CSS
list-object with user-defined style-sheet-definitions, according to the official CSS syntax. See 'Details'.
encoding
string, indicating the charset encoding used for variable and value labels. Default is NULL, so encoding will be auto-detected depending on your platform (e.g., "UTF-8" for Unix and "Windows-1252" for Windows OS). Change encoding if specific chars are not properly displayed (e.g. German umlauts).
file
destination file, if the output should be saved as file. If NULL (default), the output will be saved as temporary file and openend either in the IDE's viewer pane or the default web browser.
use.viewer
If TRUE, the HTML table is shown in the IDE's viewer pane. If FALSE or no viewer available, the HTML table is opened in a web browser.
no.output
logical, if TRUE, the html-output is neither opened in a browser nor shown in the viewer pane and not even saved to file. This option is useful when the html output should be used in knitr documents. The html output can be accessed via the return value.
remove.spaces
logical, if TRUE, leading spaces are removed from all lines in the final string that contains the html-data. Use this, if you want to remove parantheses for html-tags. The html-source may look less pretty, but it may help when exporting html-tables to office tools.

Value

Invisibly returns
  • 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.

Details

See 'Details' in sjt.frq.

Examples

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

Run the code above in your browser using DataLab