These functions are wrappers for the broom
package to directly obtain the regression results.
The naming convention is regress_*
for raw formula and tidy_*
for the model object.
regress()
returns the regression results as a list.regress_coef()
returns the coefficients.regress_stat()
returns the model statistics.regress_data()
returns the augmented data.
Arguments
- .data
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).
- formula
A formula specifying the model.
- model
A character string specifying the model to be used.
- digit
A positive integer specifying the number of digits to be displayed.
- format
A character string specifying the format of the coefficients. The default is
%.3f
, which means three decimal places.
Examples
regress(mtcars, mpg ~ wt + hp)
#> $coef
#> # A tibble: 3 × 7
#> term coef estimate std.error statistic p.value star
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) "37.227***\n(1.599)" 37.2 1.60 23.3 2.57e-20 ***
#> 2 wt "-3.878***\n(0.633)" -3.88 0.633 -6.13 1.12e- 6 ***
#> 3 hp "-0.032**\n(0.009)" -0.0318 0.00903 -3.52 1.45e- 3 **
#>
#> $stat
#> # A tibble: 1 × 12
#> r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.827 0.815 2.59 69.2 9.11e-12 2 -74.3 157. 163.
#> # ℹ 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>
#>
#> $data
#> # A tibble: 32 × 10
#> .rownames mpg wt hp .fitted .resid .hat .sigma .cooksd .std.resid
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Mazda RX4 21 2.62 110 23.6 -2.57 0.0443 2.59 1.59e-2 -1.01
#> 2 Mazda RX4 … 21 2.88 110 22.6 -1.58 0.0405 2.62 5.46e-3 -0.623
#> 3 Datsun 710 22.8 2.32 93 25.3 -2.48 0.0602 2.59 2.07e-2 -0.985
#> 4 Hornet 4 D… 21.4 3.22 110 21.3 0.135 0.0475 2.64 4.72e-5 0.0533
#> 5 Hornet Spo… 18.7 3.44 175 18.3 0.373 0.0369 2.64 2.74e-4 0.146
#> 6 Valiant 18.1 3.46 105 20.5 -2.37 0.0672 2.60 2.16e-2 -0.948
#> 7 Duster 360 14.3 3.57 245 15.6 -1.30 0.117 2.63 1.26e-2 -0.533
#> 8 Merc 240D 24.4 3.19 62 22.9 1.51 0.116 2.62 1.68e-2 0.620
#> 9 Merc 230 22.8 3.15 95 22.0 0.806 0.0600 2.63 2.19e-3 0.321
#> 10 Merc 280 19.2 3.44 123 20.0 -0.779 0.0469 2.63 1.55e-3 -0.308
#> # ℹ 22 more rows
#>
regress_coef(mtcars, mpg ~ wt + hp)
#> # A tibble: 3 × 7
#> term coef estimate std.error statistic p.value star
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) "37.227***\n(1.599)" 37.2 1.60 23.3 2.57e-20 ***
#> 2 wt "-3.878***\n(0.633)" -3.88 0.633 -6.13 1.12e- 6 ***
#> 3 hp "-0.032**\n(0.009)" -0.0318 0.00903 -3.52 1.45e- 3 **
mtcars %>%
dplyr::mutate(mpg20 = mpg > 20) %>%
regress(mpg20 ~ wt + hp, model = "logit")
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> $coef
#> # A tibble: 3 × 7
#> term coef estimate std.error statistic p.value star
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) "894.228\n(365884.162)" 894. 365884. 0.00244 0.998 ""
#> 2 wt "-202.865\n(84688.218)" -203. 84688. -0.00240 0.998 ""
#> 3 hp "-2.021\n(858.062)" -2.02 858. -0.00236 0.998 ""
#>
#> $stat
#> # A tibble: 1 × 8
#> null.deviance df.null logLik AIC BIC deviance df.residual nobs
#> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <int> <int>
#> 1 43.9 31 -5.58e-9 6.00 10.4 0.0000000112 29 32
#>
#> $data
#> # A tibble: 32 × 10
#> .rownames mpg20 wt hp .fitted .resid .hat .sigma .cooksd
#> <chr> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Mazda RX4 TRUE 2.62 110 140. 2.11e-8 7.71e-7 2.00e-5 5.70e-23
#> 2 Mazda RX4 Wag TRUE 2.88 110 88.7 2.11e-8 3.15e-7 2.00e-5 2.33e-23
#> 3 Datsun 710 TRUE 2.32 93 236. 2.11e-8 2.10e-6 2.00e-5 1.55e-22
#> 4 Hornet 4 Drive TRUE 3.22 110 19.7 7.48e-5 1.00e+0 NaN 3.12e- 1
#> 5 Hornet Sportab… FALSE 3.44 175 -157. -2.11e-8 9.55e-7 2.00e-5 7.07e-23
#> 6 Valiant FALSE 3.46 105 -19.9 -6.74e-5 1.00e+0 NaN 3.53e- 1
#> 7 Duster 360 FALSE 3.57 245 -325. -2.11e-8 4.06e-6 2.00e-5 3.00e-22
#> 8 Merc 240D TRUE 3.19 62 122. 2.11e-8 5.89e-7 2.00e-5 4.36e-23
#> 9 Merc 230 TRUE 3.15 95 63.2 2.11e-8 1.64e-7 2.00e-5 1.21e-23
#> 10 Merc 280 FALSE 3.44 123 -52.2 -2.11e-8 1.15e-7 2.00e-5 8.48e-24
#> # ℹ 22 more rows
#> # ℹ 1 more variable: .std.resid <dbl>
#>