Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple function to compute bootstrap intervals for commonly used regression models #206

merged 7 commits into from Jan 26, 2021


Copy link

@topepo topepo commented Jan 13, 2021

Based on some thoughts that @mine-cetinkaya-rundel gave us from her teaching.

Works for lm(), glm(), survreg(), and coxph() models


reg_intervals(mpg ~ ., data = mtcars)
#> # A tibble: 10 x 6
#>    term   .lower .estimate .upper .alpha .method  
#>    <chr>   <dbl>     <dbl>  <dbl>  <dbl> <chr>    
#>  1 am    -3.92      2.15   9.68     0.05 student-t
#>  2 carb  -2.35     -0.495  2.86     0.05 student-t
#>  3 cyl   -3.47      0.162  2.98     0.05 student-t
#>  4 disp  -0.0345    0.0150 0.0649   0.05 student-t
#>  5 drat  -5.15      1.87   4.22     0.05 student-t
#>  6 gear  -4.85      1.47   4.22     0.05 student-t
#>  7 hp    -0.104    -0.0130 0.0316   0.05 student-t
#>  8 qsec  -1.95      1.33   2.70     0.05 student-t
#>  9 vs    -4.42     -0.584  6.66     0.05 student-t
#> 10 wt    -9.41     -3.98   2.15     0.05 student-t

Created on 2021-01-12 by the reprex package (v0.3.0)

R/reg_intervals.R Outdated Show resolved Hide resolved
R/reg_intervals.R Outdated Show resolved Hide resolved
R/reg_intervals.R Outdated Show resolved Hide resolved
R/reg_intervals.R Show resolved Hide resolved
topepo and others added 4 commits January 26, 2021 11:43
Co-authored-by: Davis Vaughan <>
Co-authored-by: Davis Vaughan <>
Copy link

mattwarkentin commented Jan 26, 2021

Hey @topepo and @DavisVaughan,

Just poking my head in here to ask about whether or not this function could be more general and thus have more widespread application. It seems to me that following the same logic already contained in the current code, this function could be made to work for any model that has a formula method for model fitting and a tidy() method, which is quite a large and growing number of models.

I am thinking the function API could look something like:

# Default args
reg_intervals(formula, data, model_fn = stats::lm, tidier = generics::tidy, ...)
# A simple lm() example would look the same
reg_interval(mpg ~ ., mtcars)

# A more "unconventional" model example would still work
reg_interval(y ~ x, df, model_fn = mlogit::mlogit)

# Could even work for models without formal tidiers by supplying your own tidier
  mpg ~ ., data = mtcars, 
  model_fn = mypkg::very_special_model, 
  tidier = function(x) {some code that returns a tibble of model coefficients}

The suggested API could piggy-back on all of the existing tidy() methods which would be nice, while still remaining somewhat agnostic to how the model results get tidy.

This type of usage may be beyond the scope of what this function is supposed to be, but I'm just thinking out loud. Perhaps it deserves to be its own function, which I'd be happy to work on, if desired.

Copy link
Member Author

topepo commented Jan 26, 2021

It could but I'm wary of supporting everything.

For example, right now, we will need to add some kind of filter for models to check to see if they converged or not. That is very difficult to do with survival models (as an example) and might lead to some issues.

@topepo topepo merged commit 68b6c57 into master Jan 26, 2021
@topepo topepo deleted the reg-int branch January 26, 2021 21:39
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants