[R] Drawing the regression line and the 95% confidence intervals

varin sacha varinsacha at yahoo.fr
Wed May 6 00:01:27 CEST 2015


Hi, Dear R-helpers,

Here below you will find a reproducible fictitious example working except the "abline" function.

First thing : I try to draw the regression line (multiple linear regression). I try the "abline" function but it does not work. I don't get any error message but the straight line does not appear on the scatterplot.

Second thing : I try to draw the 95% confidence intervals on the regression line. How could I do ?

Using abline(0,1), I can of course add a line 45 degrees angle passing through the origin (intercept=0 and slope=1), but it is not what I am looking for.

GDP.per.head=c(600,560,340,560,580,300,570,900,680,290,590,340)
Quality.score=c(4.5,6.5,6,4.5,7,3,9,10,12.5,6.5,7,9)
Competitivness.score=c(1000,1200,1400,700,680,1010,340,560,690,500,690,460)
LinearModel.1=lm(GDP.per.head ~ Quality.score + Competitivness.score)
plot(GDP.per.head, fitted(LinearModel.1))
abline(GDP.per.head, fitted(LinearModel.1))

Thanks for your help. Looking forward to reading you.

Sacha



More information about the R-help mailing list