Session Ready
Exercise

Confidence Interval

In the last exercise you found that there is quite a wide prediction interval. This meant that the range of possible amounts that someone from our sample would like us if we gave them 3 units of money was quite large.

Let's have a look at the range of mean predicted scores if we gave people 3 units of money in the population through calculating the confidence interval. The formula for a confidence interval is $$\hat{y} \pm margin of error$$ , where the margin of error is $$ 2 * \frac{s_{res}}{ \sqrt n} $$. Again, R provides us with a way to do this in one go! We do this in exactly the same way as our prediction interval, except instead of interval = "predict", we use interval = "confidence". For example, for a 90% confidence interval we might put: predict(model, newdata, level = 0.9, interval = "confidence").

Let's try to find the 95% confidence interval for our prediction that if you give someone 3 units of money, they will like you an amount of 3.835.

Instructions
100 XP
  • In your script, add a line of code to calculate the 95% confidence interval for the amount someone from our sample would like us if we gave them 3 units of money.