Intervals in regression

Inference for Linear Regression in R

Jo Hardin

Professor, Pomona College

Inference for Linear Regression in R

Inference for Linear Regression in R
alpha = 0.05
crit_val <- qt((1-alpha/2), df = nrow(starbucks) - 2)
lm(Calories ~ Fat, data=starbucks) %>% 
  tidy(conf.int = TRUE, conf.level = 1-alpha)
        term   estimate  std.error statistic   p.value     conf.low conf.high
1 (Intercept)  147.9833 14.9719851  9.884013 6.630009e-17 118.31530 177.65128
2         Fat   12.7586  0.8171655 15.613236 8.937367e-30 11.13933   14.37787
lm(Calories ~ Fat, data=starbucks) %>% tidy() %>%
   mutate(lower = estimate - crit_val*std.error,
          upper = estimate + crit_val*std.error)
        term  estimate  std.error statistic      p.value     lower     upper
1 (Intercept) 147.9833 14.9719851  9.884013 6.630009e-17 118.31530 177.65128
2         Fat  12.7586  0.8171655 15.613236 8.937367e-30 11.13933  14.37787
Inference for Linear Regression in R

Confidence interval for intercept parameter

tidy_mod <- lm(Calories ~ Fat,
               data = starbucks) %>% 
  tidy(conf.int = TRUE,
       conf.level = 1-alpha)
tidy_mod
term estimate  std.error
1 (Intercept) 147.9833 14.9719851
2         Fat  12.7586  0.8171655
statistic      p.value  conf.low
1  9.884013 6.630009e-17 118.31530
2 15.613236 8.937367e-30  11.13933
conf.high
1 177.65128
2  14.37787
tidy_mod %>% 
  filter(term == "(Intercept)") %>% 
  select(conf.low, conf.high)
  conf.low conf.high
1 118.3153  177.6513
Inference for Linear Regression in R

Confidence interval for slope parameter

tidy_mod <- lm(Calories ~ Fat,
               data = starbucks) %>% 
  tidy(conf.int = TRUE,
       conf.level = 1-alpha)
tidy_mod
term estimate  std.error
1 (Intercept) 147.9833 14.9719851
2         Fat  12.7586  0.8171655
statistic      p.value  conf.low
1  9.884013 6.630009e-17 118.31530
2 15.613236 8.937367e-30  11.13933
conf.high
1 177.65128
2  14.37787
tidy_mod %>% 
  filter(term == "Fat") %>% 
  select(conf.low, conf.high)
  conf.low conf.high
1 11.13933  14.37787
Inference for Linear Regression in R

Bootstrap interval for slope

BS_slope <- starbucks %>%
   specify(Calories ~ Fat) %>%
   generate(reps = 1000, type = "bootstrap") %>%
   calculate(stat = "slope")
BS_slope %>% 
   summarize(low = quantile(stat, alpha / 2), 
             high = quantile(stat, 1 - alpha / 2))
 A tibble: 1 x 2
       low     high
     <dbl>    <dbl>
1 11.16712 14.34817
Inference for Linear Regression in R

Let's practice!

Inference for Linear Regression in R

Preparing Video For Download...