faithful_model <- lm(waiting ~ duration, data = old_faithful_2024)putting a confidence interval on a slope
is the slope real? beta-1
get_regression_table()specify()calculate(stat = "slope")get_ci()Old Faithful: waiting time against eruption duration
A fitted slope is computed from one sample, so it would come out differently on the next one.
One Sample, One Slope
Fit the model first and give it a name. Every step after this one reads the fitted model rather than the data.
Example
the fitted model, saved for later
response ~ explanatory where those two variables live
Return the regression table: each coefficient with its standard error, test statistic, p-value, and confidence interval, all at once.
Example
# A tibble: 2 × 7
term estimate std_error statistic p_value lower_ci upper_ci
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 intercept 79.5 7.31 10.9 0 65.0 93.9
2 duration 0.371 0.032 11.4 0 0.307 0.435
the verb (function) the fitted model
Each coefficient gets a row, and each row answers a different question.
What The Columns Mean
The regression table’s standard errors are only trustworthy when the residuals behave. Check them before you quote a p-value.
LINE
Linearity, Independence, Normality of residuals, Equal variance.
Two plots do most of the work.
Residual Plots
The residuals you need for those checks, one row per observation.
Example
fitted values and residuals
faithful_points <- get_regression_points(faithful_model)
ggplot(faithful_points, aes(x = residual)) +
geom_histogram(color = "white")a histogram of the residuals
what to plot
The infer workflow again, with the slope as the statistic. Only the stat argument differs from chapter 8.
Example
the slope, not a mean this time
response ~ explanatory
The same pipeline without generate() gives the slope actually fitted to the data. The interval is centered on it.
Example
no resampling: this is your data
A confidence interval for the population slope, from the bootstrap distribution you just built.
Example
the verb (function) how confident the standard error method center it on the slope you observed
Two routes to the same conclusion.
Theory & Simulation