Learn R Programming

pubh (version 1.1.3)

glm_coef: Table of coefficients from generalised linear models.

Description

glm_coef displays estimates with confidence intervals and p-values from generalised linear models (see Details).

Usage

glm_coef(
  model,
  digits = 2,
  alpha = 0.05,
  labels = NULL,
  se_rob = TRUE,
  type = "cond",
  exp_norm = FALSE
)

Arguments

model

A model from any of the classes listed in the details section.

digits

A scalar, number of digits for rounding the results (default = 2).

alpha

Significant level (default = 0.05) used to calculate confidence intervals.

labels

An optional character vector with the names of the coefficients (including intercept).

se_rob

Logical, should robust errors be used to calculate confidence intervals? (default = TRUE).

type

Character, either "cond" (condensed) or "ext" (extended). See details.

exp_norm

Logical, should estimates and confidence intervals should be exponentiated? (for family == "gaussian").

Value

A data frame with estimates, confidence intervals and p-values from glm objects.

Details

glm_coef recognises objects (models) from the following classes: clm, clogit, coxph, gee, glm, glmerMod, lm, lme, multinom, negbin, polr and surveg

For models from logistic regression (including conditional logistic, ordinal and multinomial), Poisson or survival analysis, coefficient estimates and corresponding confidence intervals are automatically exponentiated (back-transformed).

By default, glm_coef uses robust standard errors for calculating confidence intervals.

glm_coef can display two different data frames depending on the option of type, for type type = "cond" (the default), glm_coef displays the standard table of coefficients with confidence intervals and p-values; for type = "ext", glm_coef displays each number in a different column and includes standard errors.

Please read the Vignette on Regression for more details.

Examples

Run this code
# NOT RUN {
## Continuous outcome.
data(birthwt, package = "MASS")
require(dplyr)
birthwt <- mutate(birthwt,
  smoke = factor(smoke, labels = c("Non-smoker", "Smoker")),
  Race = factor(race > 1, labels = c("White", "Non-white")))

model_norm <- glm(bwt ~ smoke + race, data = birthwt)
glm_coef(model_norm)

model_norm %>%
  glm_coef(labels=c("Constant", "Smoker vs Non-smoker", "Non-white vs White"))

## Logistic regression.
data(diet, package = "Epi")
model_binom <- glm(chd ~ fibre, data = diet, family = binomial)
model_binom %>%
  glm_coef(labels = c("Constant", "Fibre intake (g/day)"))

model_binom %>%
glm_coef(labels = c("Constant", "Fibre intake (g/day)"), type = "ext")

## Poisson regression.
library(MASS)
data(quine)
levels(quine$Eth) <- list(White = "N", Aboriginal = "A")
levels(quine$Sex) <- list(Male = "M", Female = "F")
model_pois <- glm(Days ~ Eth + Sex + Age, family = poisson, data = quine)

model_pois %>%
  glm_coef()

deviance(model_pois) / df.residual(model_pois) # to check for overdispersion

model_negbin <- glm.nb(Days ~ Eth + Sex + Age, data = quine)
unadj <- glm_coef(model_negbin,
                  labels=c("Constant",
                  "Race: Aboriginal/White",
                  "Sex: Female/Male",
                  "F1/Primary",
                  "F2/Primary",
                  "F3/Primary"))
unadj # Not-adjusted for multiple comparisons

## For more examples, please read the Vignette on Regression.
# }

Run the code above in your browser using DataLab