Loading [MathJax]/jax/output/CommonHTML/jax.js
+ - 0:00:00
Notes for current slide
Notes for next slide

Prediction intervals

1 / 11

confidence intervals

If we use the same sampling method to select different samples and computed an interval estimate for each sample, we would expect the true population parameter ( β1 ) to fall within the interval estimates 95% of the time.

2 / 11

Confidence interval for β1

How do we calculate the confidence interval for the slope?

3 / 11

Confidence interval for β1

How do we calculate the confidence interval for the slope?

ˆβ1±tSEˆβ1

3 / 11

How do we calculate it in R?

  • using the broom package
lm(Weight ~ WingLength, Sparrows) %>%
tidy(conf.int = TRUE)
## # A tibble: 2 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 1.37 0.957 1.43 1.56e- 1 -0.531 3.26
## 2 WingLength 0.467 0.0347 13.5 2.62e-25 0.399 0.536
4 / 11

How do we calculate it in R?

  • using the broom package
lm(Weight ~ WingLength, Sparrows) %>%
tidy(conf.int = TRUE)
## # A tibble: 2 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 1.37 0.957 1.43 1.56e- 1 -0.531 3.26
## 2 WingLength 0.467 0.0347 13.5 2.62e-25 0.399 0.536
  • "by hand"
t_star <- qt(0.025, df = 116 - 2, lower.tail = FALSE)
# or
t_star <- qt(0.975, df = 116 - 2)
0.467 - t_star * 0.0347
## [1] 0.3982596
0.467 + t_star * 0.0347
## [1] 0.5357404
4 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

5 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value
5 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value
  • The confidence interval for an individual response y for a given x value
5 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value: confidence interval for μy
  • The confidence interval for an individual response y for a given x value: prediction interval
6 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value: confidence interval for μy
  • The confidence interval for an individual response y for a given x value: prediction interval
  • Why are these different? Which do you think is easier to estimate?
6 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value: confidence interval for μy
  • The confidence interval for an individual response y for a given x value: prediction interval
  • Why are these different? Which do you think is easier to estimate?
  • It is harder to predict one response than to predict a mean response. What does this mean in terms of the standard error?
6 / 11

Confidence intervals

There are ✌️ other types of confidence intervals we may want to calculate

  • The confidence interval for the mean response in y for a given x value: confidence interval for μy
  • The confidence interval for an individual response y for a given x value: prediction interval
  • Why are these different? Which do you think is easier to estimate?
  • It is harder to predict one response than to predict a mean response. What does this mean in terms of the standard error?
  • The SE of the prediction interval is going to be larger
6 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
7 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ
7 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ
  • SEˆy
7 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ
  • SEˆy
  • Which will be larger?
7 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ=ˆσϵ1n+(xˉx)2Σ(xˉx)2
  • SEˆy=ˆσϵ1+1n+(xˉx)2Σ(xˉx)2
  • Which will be larger?
8 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ=ˆσϵ1n+(xˉx)2Σ(xˉx)2
  • SEˆy=ˆσϵ1+1n+(xˉx)2Σ(xˉx)2
  • Which will be larger?
  • What is the difference between these two equations?
8 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ=ˆσϵ1n+(xˉx)2Σ(xˉx)2
  • SEˆy=ˆσϵ1+1n+(xˉx)2Σ(xˉx)2
9 / 11

Confidence intervals

confidence interval for μy and prediction interval

ˆy±tSE

  • ˆy is the predicted y for a given x
  • t is the critical value for the tn2 density curve
  • SE takes ✌️ different values depending on which interval you're interested in
  • SEˆμ=ˆσϵ1n+(xˉx)2Σ(xˉx)2
  • SEˆy=ˆσϵ1+1n+(xˉx)2Σ(xˉx)2
  • an individual response will vary from the mean response μy with a standard deviation of σϵ
9 / 11

Let's do it in R!

lm(Weight ~ WingLength, data = Sparrows) %>%
predict()
## 1 2 3
## 14.92020 15.85501 13.05059
10 / 11

Let's do it in R!

lm(Weight ~ WingLength, data = Sparrows) %>%
predict()
## 1 2 3
## 14.92020 15.85501 13.05059
lm(Weight ~ WingLength, data = Sparrows) %>%
predict(interval = "confidence")
## fit lwr upr
## 1 14.92020 14.63801 15.20240
## 2 15.85501 15.49396 16.21607
## 3 13.05059 12.74776 13.35342
10 / 11

Let's do it in R!

lm(Weight ~ WingLength, data = Sparrows) %>%
predict()
## 1 2 3
## 14.92020 15.85501 13.05059
lm(Weight ~ WingLength, data = Sparrows) %>%
predict(interval = "confidence")
## fit lwr upr
## 1 14.92020 14.63801 15.20240
## 2 15.85501 15.49396 16.21607
## 3 13.05059 12.74776 13.35342
lm(Weight ~ WingLength, data = Sparrows) %>%
predict(interval = "prediction")

## WARNING predictions on current data refer to _future_ responses

## fit lwr upr
## 1 14.92020 12.13329 17.70712
## 2 15.85501 13.05902 18.65101
## 3 13.05059 10.26151 15.83966
10 / 11

Let's do it in R!

What if we have new data?

new_sparrows <- data.frame(
WingLength = c(30, 28, 25)
)
new_sparrows
## WingLength
## 1 30
## 2 28
## 3 25
11 / 11

Let's do it in R!

What if we have new data?

new_sparrows <- data.frame(
WingLength = c(30, 28, 25)
)
new_sparrows
## WingLength
## 1 30
## 2 28
## 3 25
lm(Weight ~ WingLength, data = Sparrows) %>%
predict(newdata = new_sparrows, interval = "prediction")
## fit lwr upr
## 1 15.38761 12.59700 18.17822
## 2 14.45280 11.66790 17.23771
## 3 13.05059 10.26151 15.83966
11 / 11

confidence intervals

If we use the same sampling method to select different samples and computed an interval estimate for each sample, we would expect the true population parameter ( β1 ) to fall within the interval estimates 95% of the time.

2 / 11
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow