Description Usage Arguments Value Examples
Takes a data frame, and a model to fit to the data and each bootstrap replicate. Bootstrapping is by default resampling cases, but if you set boot_resid=TRUE then resampling residuals will be performed. If you pass a null model formula that includes a subset of the variables in the full model (i.e. it is a nested model) then the bootstrap statistics will come from the bootstrapped null data and can be used for a hypothesis test.
1 | slipper_lm(df, formula, null_formula = NULL, B = 100, boot_resid = FALSE)
|
df |
A data frame |
formula |
A bare formula to pass to the lm command |
null_formula |
(optional) If NULL, standard bootstrapping is performed. If a bare nested null formula is passed the bootstrapped statistics come from the null. |
B |
the number of bootstrap samples to draw |
boot_resid |
If TRUE then bootstrapping residuals is performed. |
out A data frame with the values, whether they come from the observed data or the bootstrapped data, and the coefficient name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Bootstrap a regression model
slipper_lm(mtcars,mpg ~ cyl,B=100)
# Bootstrap a regression model with piping
mtcars %>% slipper_lm(mpg ~ cyl,B=100)
# Bootstrap residuals for a regression model
mtcars %>% slipper_lm(mpg ~ cyl,B=100,boot_resid=TRUE)
# Bootsrap confidence intervals
mtcars %>% slipper_lm(mpg ~ cyl,B=100) %>%
filter(type=="bootstrap",term=="cyl") %>%
summarize(ci_low = quantile(value,0.025),
ci_high = quantile(value,0.975))
# Bootstrap hypothesis test - here I've added one to the numerator
# and denominator because bootstrap p-values should never be zero.
boot = mtcars %>% slipper_lm(mpg ~ cyl, null_formula = mpg ~ 1,B=1000) %>%
filter(term=="cyl") %>%
summarize(num = sum(abs(value) >= abs(value[1])),
den = n(),
pval = num/den)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.