Professional Documents
Culture Documents
> wash=c(4,5,6,5,7,9,8,12,10,12,11,9,6,6,4,4,13,15,12,12,12,13,10,13)
> mean(wash)
[1] 9.083333
>
> deter=factor(c(rep(1,12), rep(2,12)))
> deter
[1] 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2
Levels: 1 2
> water=factor(c(rep(1,4), rep(2,4), rep(3,4), rep(1,4), rep(2,4), rep(3,4)))
> water
[1] 1 1 1 1 2 2 2 2 3 3 3 3 1 1 1 1 2 2 2 2 3 3 3 3
Levels: 1 2 3
> water=factor(rep(gl(3,4),2))
> water
[1] 1 1 1 1 2 2 2 2 3 3 3 3 1 1 1 1 2 2 2 2 3 3 3 3
Levels: 1 2 3
>
> ?tapply
starting httpd help server ... done
>
> tapply(wash, water, mean)
1
2
3
5.00 11.00 11.25
>
> tapply(wash, deter, mean)
1
2
8.166667 10.000000
>
> tapply(wash, water:deter, mean)
1:1 1:2 2:1 2:2 3:1 3:2
5.0 5.0 9.0 13.0 10.5 12.0
>
> lm.deter=lm(wash~deter+water+deter*water)
> lm.deter
Call:
lm(formula = wash ~ deter + water + deter * water)
Coefficients:
(Intercept)
2:water3
5.000e+00
.500e+00
deter2
water2
-1.201e-15
4.000e+00
4.000e+00
> anova(lm.deter)
Analysis of Variance Table
Response: wash
Df
deter
1
water
2
deter:water 2
Residuals 18
--Signif. codes:
>
>
>
Sum Sq Mean Sq
20.167 20.167
200.333 100.167
16.333 8.167
37.000 2.056
0 ***
0.001
F value Pr(>F)
9.8108 0.005758 **
48.7297 5.44e-08 ***
3.9730 0.037224 *
**
0.01
* 0.05
0.1
>
>
> summary(lm.deter)
Call:
lm(formula = wash ~ deter + water + deter * water)
Residuals:
Min
1Q Median
-2
-1
0
3Q
1
Max
3
Coefficients:
Estimate Std. Error t value
(Intercept)
5.000e+00 7.169e-01 6.975
deter2
-1.201e-15 1.014e+00 0.000
water2
4.000e+00 1.014e+00 3.946
water3
5.500e+00 1.014e+00 5.425
deter2:water2 4.000e+00 1.434e+00 2.790
deter2:water3 1.500e+00 1.434e+00 1.046
--Signif. codes: 0 *** 0.001 ** 0.01 *
Pr(>|t|)
1.63e-06
1.000000
0.000948
3.73e-05
0.012094
0.309302
0.05
***
***
***
*
0.1
0.1
0.1
In file(file, "rt") :
cannot open file 'C:\Users\Sitanshu\Desktop\test.csv': No such file or directo
ry
>
> new=read.csv("C:\\Users\\Sitanshu\\Desktop\\Test.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'C:\Users\Sitanshu\Desktop\Test.csv': No such file or directo
ry
>
>
>
> new=read.csv("C:\\Users\\Sitanshu\\Desktop\\Test.csv")
> new
EX 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
>
>
>
> y=new[,2]
> y
[1] 85.5 94.3 87.0 107.5 94.9 121.6 111.5 117.9 103.1 116.1 93.4 77.2 108
.4 111.8 110.8 120.9 104.3 85.1
>
> y=new[,1]
> x1=new[,2]
> x2=new[,3]
> x3=new[,4]
> x4=new[.5]
> x5=new[,6]
> x4=new[,5]
> x6=new[,7]]
Error: unexpected ']' in "x6=new[,7]]"
> x6=new[,7]
> x6
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>
>
> new=read.csv("C:\\Users\\Sitanshu\\Desktop\\Test.csv")
> x1=new[,2]
> y=new[,1]
> x2=new[,3]
>
>
>
>
>
>
x3=new[,4]
x4=new[,5]
x5=new[,6]
x6=new[,7]
x6
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
>
>
>
> cor(cbind(y,x1,x2,x3,x4,x5,x6))
y
x1
x2
x6
y 1.00000000 0.65586251 0.04523511
48726
x1 0.65586251 1.00000000 0.40892636
92617
x2 0.04523511 0.40892636 1.00000000
82668
x3 0.40528659 0.46007220 0.40402333
55095
x4 -0.29319692 -0.58946801 -0.62627957
07582
x5 -0.02339611 -0.04449636 -0.04105316
09663
x6 0.37348726 0.03992617 -0.33082668
00000
>
>
> reg=lm(y~x1+x2+x3+x4+x5+x6)
> summary(reg)
x3
x4
x5
Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6)
Residuals:
Min
1Q Median
3Q
Max
-75.031 -26.226 0.296 23.256 87.653
Coefficients:
Estimate Std. Error t value
(Intercept) 356.1818 306.4862 1.162
x1
1.4185
0.4300 3.298
x2
-0.6602
0.3526 -1.872
x3
0.5716
0.4251 1.345
x4
-6.6747
7.4806 -0.892
x5
-1.8551
7.1368 -0.260
x6
35.4723
13.7711 2.576
--Signif. codes: 0 *** 0.001 ** 0.01
Pr(>|t|)
0.25190
0.00202 **
0.06832 .
0.18615
0.37746
0.79622
0.01370 *
* 0.05
0.1
lm(formula = y ~ x1 + x6)
Residuals:
Min
1Q Median
3Q
Max
-78.863 -26.251 -0.334 22.355 97.849
Coefficients:
Estimate Std. Error t
(Intercept) 102.2957
26.6247
x1
1.6962
0.2641
x6
40.4759
11.6326
--Signif. codes: 0 *** 0.001 **
value
3.842
6.422
3.480
0.01
Pr(>|t|)
0.00038 ***
7.38e-08 ***
0.00113 **
* 0.05
0.1
n
-0.8857
> annova(fit)
Error: could not find function "annova"
> anova(fit)
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
n
1 10.983 10.9829 8.3514 0.009385 **
Residuals 19 24.987 1.3151
0.1
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
n1
2 11.007 5.5033 3.9683 0.03735 *
Residuals 18 24.963 1.3868
--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1
> save.image("C:\\Users\\Sitanshu\\Desktop\\anova")
>