[R] use abline() for regression model in the plot

Swanton0822 iverson0822 at hotmail.com
Tue Nov 4 23:47:30 CET 2008


http://www.nabble.com/file/p20332968/spe.dat spe.dat 

Hi,
i have a problem in sorting out some command in R and i am really hoping
some expert can help me out please!
i have the spe.dat file which i upload here, and when u read into R u got
something like this:

A5 <- read.table('spe.dat' ,header=TRUE)
A5

 EXPEND  ECAB  MET GROW YOUNG  OLD WEST STATE
1     256  85.5 19.7  6.9  29.6 11.0    0    ME
2     275  94.3 17.7 14.7  26.4 11.2    0    NH
3     327  87.0  0.0  3.7  28.5 11.2    0    VT
4     297 107.5 85.2 10.2  25.1 11.1    0    MA
5     256  94.9 86.2  1.0  25.3 10.4    0    RI
6     312 121.6 77.6 25.4  25.2  9.6    0    CT
7     374 111.5 85.5 12.9  24.0 10.1    0    NY
8     257 117.9 78.9 25.5  24.8  9.2    0    NJ
9     257 103.1 77.9  7.8  25.7 10.0    0    PA
10    336 116.1 68.8 39.9  26.4  8.0    0    DE
11    269  93.4 78.2 31.1  27.5  7.3    0    MD
12    213  77.2 50.9 21.9  28.8  7.3    0    VA
13    308 108.4 73.1 22.2  28.0  8.2    0    MI
14    273 111.8 69.5 21.8  26.9  9.2    0    OH
15    256 110.8 48.1 18.3  27.5  9.6    0    IN
16    287 120.9 76.9 15.5  25.4  9.7    0    IL
17    290 104.3 46.3 14.9  27.4 10.2    0    WI
18    217  85.1 30.9 -7.4  30.0  9.3    0    WV
19    198  76.8 34.1  0.3  29.4  9.6    0    KY
20    217  75.1 45.8  8.1  28.9  8.7    0    TE
21    195  78.7 24.6 12.4  30.8  6.9    0    NC
22    183  65.2 32.2 12.9  32.9  6.3    0    SC
23    222  73.0 46.0 14.4  30.0  7.4    0    GA
24    283  80.9 65.6 77.2  25.5 11.2    0    FL
25    217  69.4 45.6  7.0  30.5  8.0    1    AL
26    231  57.4  8.6  0.5  32.1  8.7    1    MS
27    329  95.7 51.3 14.4  28.8 10.4    1    MN
28    294 100.2 33.2  5.3  27.3 11.9    1    IA
29    232  99.1 57.9  9.8  25.6 11.7    1    MO
30    369  93.4 10.6  2.9  30.2  9.3    1    ND
31    302  88.2 12.7  4.6  28.9 10.5    1    SD
32    269  99.1 37.6  6.8  26.6 11.6    1    NB
33    291 102.2 37.4 13.7  26.8 11.0    1    KS
34    323  86.0  5.0 21.9  30.3  7.4    1    LA
35    198  68.6 19.1 -6.2  29.4 10.9    1    AR
36    282  84.9 43.9  6.4  27.4 10.7    1    OK
37    246  98.8 63.4 24.1  28.8  7.8    1    TX
38    309  86.2 27.6 39.4  31.5  5.4    1    NM
39    309  90.2 71.4 74.3  29.7  6.9    1    AZ
40    334  97.6 22.6 13.4  28.9  9.7    1    MT
41    284  93.9  0.0 13.3  30.7  8.7    1    ID
42    454 125.8  0.0 13.7  29.1  7.8    1    WY
43    344  98.0  6.8 31.5  28.0  9.0    1    CO
44    307  92.5 67.5 28.7  31.9  6.7    1    UT
45    333 100.4 63.1 19.9  27.5  9.8    1    WA
46    343  98.0 50.4 15.7  27.7 10.4    1    OR
47    421 205.0 74.2 77.8  25.6  6.4    1    NV
48    380 112.6 86.5 48.5  26.2  8.8    1    CA

and using the following command i plot two graph, which the first one is
with two outliners (row 42 and 47)
and the second command, first we created a new set of data frame and use it
for the plot and is without the outliners:

1)plot(A5$ECAB,A5$EXPEND,type='p',main='Per capita expenditure against
economic ability index',
xlab='ECAB',ylab='EXPEND',xlim=c(0,250),ylim=c(100,500),col='red',col.axis='blue')

2)A5e <- A5[c(1:41,43:46,48),c(1,2)]
A5e
plot(A5e$ECAB,A5e$EXPEND,type='p',main='Per capita expenditure against
economic ability index without
outliners',xlab='ECAB',ylab='EXPEND',xlim=c(0,150),ylim=c(150,400),col='red',col.axis='blue')

after that i have been ask to do the following:
'The regression equation for EXPEND depending on ECAB is 
E(EXPEND)=119.0+1.73xECAB when there is outliners and
E(EXPEND)=97.8+1.94xECAB when the outliners are omitted from the regression
model. To the plot in 2) without the outliners, use abline() to add a fitted
line for the full regression model, and a coloured, dashed regression line
for the non-outliner regression model.'

Can anyone please help me to look at it and try to sort out the command for
this question for me please?

many thanks. 

-- 
View this message in context: http://www.nabble.com/use-abline%28%29-for-regression-model-in-the-plot-tp20332968p20332968.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list