Confidence Intervals in R

I have to calculate different confidence intervals, and I found out that in R I can do this with the prediction command. But I have problems understanding what I should actually do. I have to calculate 3 different confidence intervals: 1) for a point on the regression line 2) for the predicted (future) value of y 3) for the entire regression line. Good thing I have done so far:

fm <- lm(alcohol~beers) 

So, to get the confidence interval for the entire regression line, I would try: predict(fm,data.frame(beers = newbeers), level = 0.9, interval = "confidence") But I really don't know what data.frame does. Well, I know that the confidence interval keeps the actual value in 90% of cases (here, because 0.9). Does this now mean that it has the best regression line of 90%? I cannot understand the meaning for anything but a point and a predicted value. Also, I only know this way to calculate it, so how can I calculate it in two other ways? Also, the output I get gives a few upper and lower values ​​for the interval. What does it mean?

+4
source share
1 answer

You used data.frame(beers = newbeers) in your predict function, which means it is a prediction interval . Note that newbeers is a data frame consisting of new data, not your original data (used to fit the linear model).

For the confidence interval, simply use the confint function, which gives you (by default) 95% CI for each regression coefficient (in this case, intercept and slope).

For a point on the regression line, please see the last two slides here . The confidence interval for an individual point should be greater than for the regression line.

Hope this helps!

+3
source

Source: https://habr.com/ru/post/1435352/


All Articles