toffee_tbl: Create a nicely formatted table from a model object.

Description Usage Arguments Value Examples

Description

Given a model object (like from stats::lm(), stats::glm(), or lme4::glmer()) this function makes a table intended for interactive use or publication. The model coefficients and confidence intervals displayed in the table have had their inverse link function applied, therefore they are in the units of the response variable.

Usage

1
2
toffee_tbl(model, conf_level = 0.95, digits = 2,
  concat_signif = TRUE, odds_ratio = TRUE, ci_fmt = TRUE, ...)

Arguments

model

A model object that is compatible with broom::tidy().

conf_level

The confidence level that will be used for computing the confidence interval (for example: 0.95 or 0.99).

digits

The number of decimal places that numbers in the table should be rounded to. For no rounding use Inf. This argument is provided to base::round(). The default value is 2.

concat_signif

If TRUE the resulting data frame will append significance symbols as generated by toffee_signif(). If FALSE the significance symbols will appear in a separate column called Significant.

odds_ratio

If TRUE and the family of the model provided is logit then the model coefficients and confidence intervals returned in the resulting table will be odds ratios.

ci_fmt

If TRUE then the confidence interval will be formatted between brackets in one column called CI. If FALSE the lower and upper bounds of the confidence interval will be in their own columns called Lower_CI and Upper_CI respectfully.

...

Arguments that will be passed to toffee_signif().

Value

A tibble::tibble() with the following columns: the name of the coefficient in the model (Variable), the value of the coefficient with inverse of the link function applied (Estimate or Odds_Ratio), the confidence interval for the coefficient (CI), the p-value for the estimate, (p_value), and optionally symbols representing levels of significance (Significant).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(dplyr)
library(toffee)

linear_model <- toffee_forest %>%
  lm(Volume ~ Girth + Height + Branches, data = .)

# Basic usage
linear_model %>%
  toffee_tbl()

 # # A tibble: 4 x 4
 #   Variable    Estimate CI               p_value
 #   <chr>          <dbl> <chr>            <chr>
 # 1 (Intercept)   -67.2  [-86.81, -47.59] < 0.01***
 # 2 Girth           4.75 [4.23, 5.27]     < 0.01***
 # 3 Height          0.33 [0.08, 0.59]     0.01*
 # 4 Branches        0.46 [-0.03, 0.95]    0.07

# Using the `chars` argument from toffee_signif
linear_model %>%
  toffee_tbl(thresholds = 0.01, chars = "*")

 # # A tibble: 4 x 4
 #   Variable    Estimate CI               p_value
 #   <chr>          <dbl> <chr>            <chr>
 # 1 (Intercept)   -67.2  [-86.81, -47.59] < 0.01*
 # 2 Girth           4.75 [4.23, 5.27]     < 0.01*
 # 3 Height          0.33 [0.08, 0.59]     0.01
 # 4 Branches        0.46 [-0.03, 0.95]    0.07

# Separating the significance symbols into their own column
linear_model %>%
  toffee_tbl(concat_signif = FALSE)

 # # A tibble: 4 x 5
 #   Variable    Estimate CI               p_value Significant
 #   <chr>          <dbl> <chr>            <chr>   <chr>
 # 1 (Intercept)   -67.2  [-86.81, -47.59] < 0.01  ***
 # 2 Girth           4.75 [4.23, 5.27]     < 0.01  ***
 # 3 Height          0.33 [0.08, 0.59]     0.01    *
 # 4 Branches        0.46 [-0.03, 0.95]    0.07    ""

logistic_model <- toffee_forest %>%
  glm(Healthy ~ Girth + Height + Branches + Volume, data = .,
      family = binomial())

logistic_model %>%
  toffee_tbl()

 # # A tibble: 5 x 4
 #   Variable    Odds_Ratio CI                  p_value
 #   <chr>            <dbl> <chr>               <chr>
 # 1 (Intercept)       0.05 [0, 10626998633.06] 0.81
 # 2 Girth             0.75 [0.14, 3.65]        0.72
 # 3 Height            0.92 [0.73, 1.14]        0.45
 # 4 Branches          2    [1.31, 3.82]        0.01**
 # 5 Volume            1.03 [0.75, 1.45]        0.86

seankross/toffee documentation built on May 29, 2019, 9:33 a.m.