H:\public_html\sta6208\rpd>C:\R-2.9.0\bin\Rterm
--vanilla
R version 2.9.0
(2009-04-17)
Copyright (C)
2009 The R Foundation for Statistical Computing
ISBN
3-900051-07-0
R is free
software and comes with ABSOLUTELY NO WARRANTY.
You are welcome
to redistribute it under certain conditions.
Type 'license()'
or 'licence()' for distribution details.
Natural language support but running in an
English locale
R is a
collaborative project with many contributors.
Type
'contributors()' for more information and
'citation()' on
how to cite R or R packages in publications.
Type 'demo()' for
some demos, 'help()' for on-line help, or
'help.start()'
for an HTML browser interface to help.
Type 'q()' to
quit R.
>
pdf("rpd07_01r.pdf")
>
>
> alldata
<- matrix(
+
c(1,676,33,5,1441.67,35184.5,16.4524,
+
2,516,35,4.75,1299.19,28170.4,13.9852,
+
3,1052,32,4.2,1154.27,26455,15.3276,
+
4,868,30,4.4,1045.15,25072.9,17.3128,
+
5,1008,33,5.55,521.62,31664.2,22.3312,
+
6,436,33,5.05,1273.02,25491.7,12.2778,
+
7,544,36,4.25,1346.35,20877.3,17.8225,
+
8,680,30,4.45,1253.88,25621.3,14.3516,
+
9,640,38,4.75,1242.65,27587.3,13.6826,
+
10,492,30,4.6,1281.95,26511.7,11.7566,
+
11,984,30,4.1,553.69,7886.5,9.882,
+
12,1400,37,3.45,494.74,14596,16.6752,
+
13,1276,33,3.45,525.97,9826.8,12.373,
+
14,1736,36,4.1,571.14,11978.4,9.4058,
+
15,1004,30,3.5,408.64,10368.6,14.9302,
+
16,396,30,3.25,646.65,17307.4,31.2865,
+
17,352,27,3.35,514.03,12822,30.1652,
+
18,328,29,3.2,350.73,8582.6,28.5901,
+ 19,392,34,3.35,496.29,12369.5,19.8795,
+
20,236,36,3.3,580.92,14731.9,18.5056,
+
21,392,30,3.25,535.82,15060.6,22.1344,
+
22,268,28,3.25,490.34,11056.3,28.6101,
+
23,252,31,3.2,552.39,8118.9,23.1908,
+
24,236,31,3.2,661.32,13009.5,24.6917,
+
25,340,35,3.35,672.15,15003.7,22.6758,
+
26,2436,29,7.1,528.65,10225,0.3729,
+
27,2216,35,7.35,563.13,8024.2,0.2703,
+
28,2096,35,7.45,497.96,10393,0.3205,
+
29,1660,30,7.45,458.38,8711.6,0.2648,
+
30,2272,30,7.4,498.25,10239.6,0.2105,
+
31,824,26,4.85,936.26,20436,18.9875,
+
32,1196,29,4.6,894.79,12519.9,20.9687,
+
33,1960,25,5.2,941.36,18979,23.9841,
+
34,2080,26,4.75,1038.79,22986.1,19.9727,
+
35,1764,26,5.2,898.05,11704.5,21.3864,
+
36,412,25,4.55,989.87,17721,23.7063,
+
37,416,26,3.95,951.28,16485.2,30.5589,
+
38,504,26,3.7,939.83,17101.3,26.8415,
+
39,492,27,3.75,925.42,17849,27.7292,
+
40,636,27,4.15,954.11,16949.6,21.5699,
+
41,1756,24,5.6,720.72,11344.6,19.6531,
+
42,1232,27,5.35,782.09,14752.4,20.3295,
+
43,1400,26,5.5,773.3,13649.8,19.588,
+ 44,1620,28,5.5,829.26,14533,20.1328,
+
45,1560,28,5.4,856.96,16892.2,19.242),byrow=T,ncol=7)
>
>
>
> bio <-
alldata[,2]
> sal <-
alldata[,3]
> ph <-
alldata[,4]
> k <-
alldata[,5]
> na <-
alldata[,6]
> zn <-
alldata[,7]
>
>
>
> linth5 <-
data.frame(bio,sal,ph,k,na,zn)
>
>
attach(linth5)
The following object(s) are masked _by_
.GlobalEnv :
bio
k na ph sal zn
>
>
library(leaps)
>
> allpossreg <- regsubsets(bio ~
sal+ph+k+na+zn,nbest=5,data=linth5)
> aprout <- summary(allpossreg)
>
> with(aprout,round(cbind(which,rsq,adjr2,cp,bic),3))
(Intercept) sal ph k na zn rsq
adjr2 cp bic
1 1 0 1
0 0
0 0.599 0.590 7.421 -33.548
1 1 0 0
0 0
1 0.390 0.376 32.738
-14.622
1 1 0 0 0 1 0
0.074 0.052 70.913 4.153
1 1 0 0
1 0
0 0.042 0.020 74.798 5.688
1 1 1 0
0 0
0 0.011 -0.012 78.573
7.132
2 1 0 1
0 1
0 0.658 0.642 2.282 -36.919
2 1 0 1
1 0
0 0.648 0.631 3.594 -35.511
2 1 0 1
0 0
1 0.608 0.590 8.343 -30.754
2 1 1 1
0 0
0 0.603 0.585 8.933 -30.197
2 1 1 0
0 0
1 0.553 0.531 15.070
-24.775
3 1 0 1
0 1
1 0.662 0.638 3.796 -33.645
3 1 0 1
1 1
0 0.660 0.636 4.049 -33.367
3 1 1 1
0 1
0 0.659 0.634 4.207 -33.194
3 1 1 1
1 0
0 0.652 0.627 5.037 -32.296
3 1 0 1
1 0
1 0.652 0.627 5.048 -32.285
4 1 1 1
1 0
1 0.675 0.642 4.296 -31.524
4 1 1 1
0 1
1 0.672 0.639 4.670 -31.099
4 1 0 1
1 1
1 0.664 0.631 5.588 -30.068
4 1 1 1
1 1
0 0.662 0.628 5.886 -29.739
4 1 1 0
1 1
1 0.577 0.535 16.087
-19.716
5 1 1 1
1 1
1 0.677 0.636 6.000 -28.058
>
>
> # These Stepwise Methods are based on Model Criteria, not individual
regression coefficients
> # direction="both" begins like backward and works down
> # Criteria: k=2 uses AIC
(default) k=log(length(y)) uses BIC
>
> reg.full <- lm(bio ~ sal+ph+k+na+zn)
> reg.null <- lm(bio ~ 1)
>
> summary(reg.full)
Call:
lm(formula = bio
~ sal + ph + k + na + zn)
Residuals:
Min
1Q Median 3Q Max
-748.2
-223.7 -85.2 139.9 1072.4
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept) 1.252e+03
1.235e+03 1.014 0.31674
sal -3.029e+01 2.403e+01
-1.260 0.21507
ph 3.055e+02 8.788e+01
3.477 0.00126 **
k -2.851e-01 3.484e-01 -0.818
0.41817
na -8.673e-03 1.593e-02
-0.544 0.58927
zn -2.068e+01 1.505e+01
-1.373 0.17746
---
Signif.
codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Residual standard
error: 398.3 on 39 degrees of freedom
Multiple
R-squared: 0.6773, Adjusted R-squared:
0.6359
F-statistic:
16.37 on 5 and 39 DF, p-value: 1.082e-08
>
> forward.reg
<-
step(reg.null,direction="forward",scope=list(upper=reg.full,lower=reg.null))
Start: AIC=585.3
bio ~ 1
Df Sum of Sq RSS
AIC
+ ph 1
11490388 7680575 546
+ zn 1
7474474 11696489 565
+ na 1
1419069 17751894 584
<none> 19170963 585
+ k 1
802872 18368091 585
+ sal 1
204048 18966915 587
Step: AIC=546.14
bio ~ ph
Df Sum of Sq RSS
AIC
+ na 1
1132401 6548174 541
+ k 1
924266 6756309 542
<none> 7680575 546
+ zn 1
170933 7509642 547
+ sal 1
77327 7603247 548
Step: AIC=540.96
bio ~ ph + na
Df Sum of Sq RSS
AIC
<none> 6548174 541
+ zn 1
77026 6471149 542
+ k 1
36938 6511236 543
+ sal 1
11778 6536396 543
>
>
summary(forward.reg)
Call:
lm(formula = bio
~ ph + na)
Residuals:
Min
1Q Median 3Q
Max
-677.93
-229.76 -97.47 207.51 1168.40
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept)
-4.757e+02 2.735e+02 -1.739
0.0893 .
ph 4.049e+02 4.777e+01
8.477 1.22e-10 ***
na -2.333e-02 8.655e-03
-2.695 0.0101 *
---
Signif.
codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Residual standard
error: 394.9 on 42 degrees of freedom
Multiple
R-squared: 0.6584, Adjusted R-squared:
0.6422
F-statistic:
40.48 on 2 and 42 DF, p-value: 1.596e-10
>
> backward.reg
<- step(reg.full,direction="backward",k=log(length(bio)))
Start: AIC=555.24
bio ~ sal + ph +
k + na + zn
Df Sum of Sq RSS
AIC
- na 1
47011 6233274 552
- k 1
106211 6292475 552
- sal 1
251921 6438184 553
- zn 1
299209 6485473 554
<none> 6186263 555
- ph 1
1917306 8103569 564
Step: AIC=551.78
bio ~ sal + ph +
k + zn
Df Sum of Sq RSS
AIC
- zn 1
434796 6668070 551
- sal 1
436496 6669770 551
<none> 6233274 552
- k 1
732606 6965880 553
- ph 1
1885805 8119079 560
Step: AIC=551
bio ~ sal + ph +
k
Df Sum of Sq RSS
AIC
- sal 1
88239 6756309 548
<none> 6668070 551
- k 1
935178 7603247 553
- ph 1
11478835 18146905 592
Step: AIC=547.79
bio ~ ph + k
Df Sum of Sq RSS
AIC
<none> 6756309 548
- k 1
924266 7680575 550
- ph 1
11611782 18368091 589
>
>
summary(backward.reg)
Call:
lm(formula = bio
~ ph + k)
Residuals:
Min
1Q Median 3Q Max
-679.4
-253.4 -95.4 259.4 1135.8
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept)
-506.9774 279.7714 -1.812
0.0771 .
ph 412.0395 48.4975
8.496 1.15e-10 ***
k -0.4871 0.2032
-2.397 0.0211 *
---
Signif.
codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Residual standard
error: 401.1 on 42 degrees of freedom
Multiple
R-squared: 0.6476, Adjusted R-squared:
0.6308
F-statistic: 38.59
on 2 and 42 DF, p-value: 3.079e-10
>
> stepwise.reg
<- step(reg.full,direction="both")
Start: AIC=544.4
bio ~ sal + ph +
k + na + zn
Df Sum of Sq RSS
AIC
- na 1
47011 6233274 543
- k 1
106211 6292475 543
- sal 1
251921 6438184 544
<none> 6186263 544
- zn 1
299209 6485473 545
- ph 1
1917306 8103569 555
Step: AIC=542.74
bio ~ sal + ph +
k + zn
Df Sum of Sq RSS
AIC
<none> 6233274
543
- zn 1
434796 6668070 544
- sal 1
436496 6669770 544
+ na 1
47011 6186263 544
- k 1
732606 6965880 546
- ph 1
1885805 8119079 553
>
>
summary(stepwise.reg)
Call:
lm(formula = bio
~ sal + ph + k + zn)
Residuals:
Min
1Q Median 3Q Max
-749.1
-229.2 -94.2 127.2 1037.4
Coefficients:
Estimate Std. Error t value
Pr(>|t|)
(Intercept)
1505.4882 1133.6940 1.328
0.19172
sal -35.9433 21.4761
-1.674 0.10201
ph 293.8611 84.4738
3.479 0.00123 **
k -0.4388 0.2024
-2.168 0.03615 *
zn -23.4519 14.0399
-1.670 0.10265
---
Signif.
codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Residual standard
error: 394.8 on 40 degrees of freedom
Multiple
R-squared: 0.6749, Adjusted R-squared:
0.6423
F-statistic:
20.76 on 4 and 40 DF, p-value: 2.528e-09
>
> dev.off()
null device
1
>
>
>