https://statisticsbyjim.com/hypothesis-testing/confidence-prediction-tolerance-intervals/
Confidence Intervals vs Prediction Intervals vs Tolerance Intervals - Statistics By Jim
Confidence intervals are common in statistics but other intervals can be more useful. Learn when to use confidence, prediction, and tolerance intervals.
statisticsbyjim.com
confindence interval : 지정된 신뢰구간 내에서 예측치들의 평균값이 위치할 범위
prediction interval : 지정된 신뢰구간 내에서 예측치들이 존재할 범위
x=sort(rnorm(100))
y=sort(rnorm(100))
df=data.frame(x=x,y=y,stringsAsFactors=F)
model1=lm(y~x,data = df)
pred_interval=predict(model1,newdata=df,interval='prediction',level=0.95)
# Prediction interval
plot(x,y)
lines(x,pred_interval[,1],lwd=2)
lines(x,pred_interval[,2],lwd=2,col='red')
lines(x,pred_interval[,3],lwd=2,col='skyblue')
# Confindence interval
conf_interval=predict(model1,newdata=df,interval='confidence',level=0.95)
lines(x,conf_interval[,2],lwd=2,col='purple')
lines(x,conf_interval[,3],lwd=2,col='green')
# Legend
legend('topleft',lwd=5,col=c('red','skyblue','purple','green'),
legend = c('Pred_low','Pred_top','Conf_low','Conf_top'))