Hey!

 

Could you please take a quick look at what I have done? Somehow I get wrong 
results using the anova(lm()) combination compared to doing a two way ANOVA by 
hand.

 

Running:

 

Data<-read.table("Data.txt");
g<-lm(ExM~S1*S2,Data);
anova(g);

 

Gives:

 

Analysis of Variance Table

Response: ExM
           Df Sum Sq Mean Sq F value    Pr(>F)    
S1          1 4.3679  4.3679 167.045 < 2.2e-16 ***
S2          1 0.9427  0.9427  36.053 8.236e-09 ***
S1:S2       1 0.3231  0.3231  12.357 0.0005371 ***
Residuals 212 5.5434  0.0261                      


I compared it to the work done by hand, ie calculated all the different square 
sums using sum() and tapply().

So I know that anova(lm()) gets the degrees of freedom equal two 1, 1, 1 and 
212 when it should be 5, 5, 25 and 180. Also, the square sums are quite 
different ... I get 4.xx, 4.xx, 1.xx, 0.xx ... as you see, what anova(lm()) 
gets is different.

 

The data: S1 has 6 levels, so has S2. On average, each cell has 6 values, most 
cells have actually 6 values, and there are two of each: 5, 7, 4, 8 - so 
average 6.

 

Could you please help me, why it does not work with anova(lm())? I tried quite 
a few thinks found with Google, but it all gave me the same result as 
anova(lm()) ... 

 

Thanks a lot!

 

Lars

_________________________________________________________________



        S1      S2      ExO     ExM
1.000   0.000   0.000   0.819   0.830
2.000   0.000   0.000   0.835   0.846
3.000   0.000   0.000   0.891   0.902
4.000   0.000   0.000   0.905   0.916
5.000   0.000   0.000   0.839   0.850
6.000   2.500   0.000   0.863   0.874
7.000   2.500   0.000   0.898   0.909
8.000   2.500   0.000   0.887   0.898
9.000   2.500   0.000   0.909   0.920
10.000  2.500   0.000   0.892   0.903
11.000  2.500   0.000   0.886   0.897
12.000  5.000   0.000   0.841   0.852
13.000  5.000   0.000   0.881   0.892
14.000  5.000   0.000   0.874   0.885
15.000  5.000   0.000   0.873   0.884
16.000  5.000   0.000   0.886   0.897
17.000  5.000   0.000   0.858   0.869
18.000  10.000  0.000   0.709   0.720
19.000  10.000  0.000   0.702   0.713
20.000  10.000  0.000   0.727   0.738
21.000  10.000  0.000   0.737   0.748
22.000  10.000  0.000   0.762   0.773
23.000  10.000  0.000   0.716   0.727
24.000  20.000  0.000   0.381   0.392
25.000  20.000  0.000   0.437   0.448
26.000  20.000  0.000   0.443   0.454
27.000  20.000  0.000   0.412   0.423
28.000  20.000  0.000   0.414   0.425
29.000  20.000  0.000   0.362   0.373
30.000  40.000  0.000   0.034   0.045
31.000  40.000  0.000   0.030   0.041
32.000  40.000  0.000   0.036   0.047
33.000  40.000  0.000   0.062   0.073
34.000  40.000  0.000   0.063   0.074
35.000  40.000  0.000   0.085   0.096
36.000  0.000   0.039   0.573   0.584
37.000  0.000   0.039   0.337   0.348
38.000  0.000   0.039   0.557   0.568
39.000  0.000   0.039   0.422   0.433
40.000  0.000   0.039   0.542   0.553
41.000  0.000   0.039   0.428   0.439
42.000  0.000   0.078   0.293   0.304
43.000  0.000   0.078   0.346   0.357
44.000  0.000   0.078   0.241   0.252
45.000  0.000   0.078   0.261   0.272
46.000  0.000   0.078   0.298   0.309
47.000  0.000   0.156   0.223   0.234
48.000  0.000   0.156   0.215   0.226
49.000  0.000   0.156   0.196   0.207
50.000  0.000   0.156   0.238   0.249
51.000  0.000   0.156   0.276   0.287
52.000  0.000   0.156   0.294   0.305
53.000  0.000   0.156   0.291   0.302
54.000  0.000   0.313   0.194   0.205
55.000  0.000   0.313   0.186   0.197
56.000  0.000   0.313   0.204   0.215
57.000  0.000   0.313   0.336   0.347
58.000  0.000   0.313   0.315   0.326
59.000  0.000   0.313   0.251   0.262
60.000  0.000   0.625   0.211   0.222
61.000  0.000   0.625   0.203   0.214
62.000  0.000   0.625   0.182   0.193
63.000  0.000   0.625   0.336   0.347
64.000  0.000   0.625   0.383   0.394
65.000  0.000   0.625   0.364   0.375
66.000  0.000   0.625   0.255   0.266
67.000  2.500   0.039   0.519   0.530
68.000  2.500   0.039   0.503   0.514
69.000  2.500   0.039   0.491   0.502
70.000  2.500   0.039   0.490   0.501
71.000  2.500   0.039   0.509   0.520
72.000  2.500   0.039   0.546   0.557
73.000  5.000   0.039   0.483   0.494
74.000  5.000   0.039   0.462   0.473
75.000  5.000   0.039   0.449   0.460
76.000  5.000   0.039   0.422   0.433
77.000  5.000   0.039   0.418   0.429
78.000  5.000   0.039   0.428   0.439
79.000  10.000  0.039   0.321   0.332
80.000  10.000  0.039   0.296   0.307
81.000  10.000  0.039   0.273   0.284
82.000  10.000  0.039   0.275   0.286
83.000  10.000  0.039   0.308   0.319
84.000  10.000  0.039   0.325   0.336
85.000  20.000  0.039   0.146   0.157
86.000  20.000  0.039   0.129   0.140
87.000  20.000  0.039   0.122   0.133
88.000  20.000  0.039   0.096   0.107
89.000  20.000  0.039   0.113   0.124
90.000  20.000  0.039   0.119   0.130
91.000  40.000  0.039   0.031   0.042
92.000  40.000  0.039   0.035   0.046
93.000  40.000  0.039   0.034   0.045
94.000  40.000  0.039   0.035   0.046
95.000  40.000  0.039   0.072   0.083
96.000  40.000  0.039   0.075   0.086
97.000  2.500   0.078   0.305   0.316
98.000  2.500   0.078   0.337   0.348
99.000  2.500   0.078   0.371   0.382
100.000 2.500   0.078   0.363   0.374
101.000 2.500   0.078   0.351   0.362
102.000 2.500   0.078   0.332   0.343
103.000 5.000   0.078   0.283   0.294
104.000 5.000   0.078   0.318   0.329
105.000 5.000   0.078   0.325   0.336
106.000 5.000   0.078   0.310   0.321
107.000 5.000   0.078   0.324   0.335
108.000 5.000   0.078   0.263   0.274
109.000 10.000  0.078   0.209   0.220
110.000 10.000  0.078   0.227   0.238
111.000 10.000  0.078   0.236   0.247
112.000 10.000  0.078   0.244   0.255
113.000 10.000  0.078   0.237   0.248
114.000 10.000  0.078   0.229   0.240
115.000 20.000  0.078   0.110   0.121
116.000 20.000  0.078   0.111   0.122
117.000 20.000  0.078   0.113   0.124
118.000 20.000  0.078   0.114   0.125
119.000 20.000  0.078   0.103   0.114
120.000 20.000  0.078   0.104   0.115
121.000 40.000  0.078   0.032   0.043
122.000 40.000  0.078   0.029   0.040
123.000 40.000  0.078   0.035   0.046
124.000 40.000  0.078   0.032   0.043
125.000 2.500   0.156   0.286   0.297
126.000 2.500   0.156   0.259   0.270
127.000 2.500   0.156   0.255   0.266
128.000 2.500   0.156   0.282   0.293
129.000 2.500   0.156   0.303   0.314
130.000 2.500   0.156   0.307   0.318
131.000 5.000   0.156   0.273   0.284
132.000 5.000   0.156   0.255   0.266
133.000 5.000   0.156   0.249   0.260
134.000 5.000   0.156   0.235   0.246
135.000 5.000   0.156   0.254   0.265
136.000 5.000   0.156   0.268   0.279
137.000 10.000  0.156   0.212   0.223
138.000 10.000  0.156   0.191   0.202
139.000 10.000  0.156   0.176   0.187
140.000 10.000  0.156   0.181   0.192
141.000 10.000  0.156   0.204   0.215
142.000 10.000  0.156   0.184   0.195
143.000 20.000  0.156   0.105   0.116
144.000 20.000  0.156   0.097   0.108
145.000 20.000  0.156   0.093   0.104
146.000 20.000  0.156   0.075   0.086
147.000 20.000  0.156   0.101   0.112
148.000 20.000  0.156   0.101   0.112
149.000 40.000  0.156   0.031   0.042
150.000 40.000  0.156   0.035   0.046
151.000 40.000  0.156   0.033   0.044
152.000 40.000  0.156   0.034   0.045
153.000 2.500   0.313   0.286   0.297
154.000 2.500   0.313   0.308   0.319
155.000 2.500   0.313   0.299   0.310
156.000 2.500   0.313   0.336   0.347
157.000 2.500   0.313   0.331   0.342
158.000 2.500   0.313   0.318   0.329
159.000 5.000   0.313   0.286   0.297
160.000 5.000   0.313   0.322   0.333
161.000 5.000   0.313   0.326   0.337
162.000 5.000   0.313   0.326   0.337
163.000 5.000   0.313   0.340   0.351
164.000 5.000   0.313   0.293   0.304
165.000 10.000  0.313   0.227   0.238
166.000 10.000  0.313   0.241   0.252
167.000 10.000  0.313   0.260   0.271
168.000 10.000  0.313   0.259   0.270
169.000 10.000  0.313   0.256   0.267
170.000 10.000  0.313   0.259   0.270
171.000 20.000  0.313   0.106   0.117
172.000 20.000  0.313   0.132   0.143
173.000 20.000  0.313   0.131   0.142
174.000 20.000  0.313   0.123   0.134
175.000 20.000  0.313   0.120   0.131
176.000 20.000  0.313   0.121   0.132
177.000 40.000  0.313   0.038   0.049
178.000 40.000  0.313   0.036   0.047
179.000 40.000  0.313   0.039   0.050
180.000 40.000  0.313   0.033   0.044
181.000 40.000  0.313   0.028   0.039
182.000 40.000  0.313   0.029   0.040
183.000 40.000  0.313   0.059   0.070
184.000 40.000  0.313   0.037   0.048
185.000 2.500   0.625   0.351   0.362
186.000 2.500   0.625   0.345   0.356
187.000 2.500   0.625   0.342   0.353
188.000 2.500   0.625   0.372   0.383
189.000 2.500   0.625   0.379   0.390
190.000 2.500   0.625   0.396   0.407
191.000 5.000   0.625   0.377   0.388
192.000 5.000   0.625   0.364   0.375
193.000 5.000   0.625   0.339   0.350
194.000 5.000   0.625   0.341   0.352
195.000 5.000   0.625   0.369   0.380
196.000 5.000   0.625   0.400   0.411
197.000 10.000  0.625   0.296   0.307
198.000 10.000  0.625   0.311   0.322
199.000 10.000  0.625   0.277   0.288
200.000 10.000  0.625   0.275   0.286
201.000 10.000  0.625   0.283   0.294
202.000 10.000  0.625   0.271   0.282
203.000 20.000  0.625   0.166   0.177
204.000 20.000  0.625   0.132   0.143
205.000 20.000  0.625   0.128   0.139
206.000 20.000  0.625   0.128   0.139
207.000 20.000  0.625   0.136   0.147
208.000 20.000  0.625   0.143   0.154
209.000 40.000  0.625   0.035   0.046
210.000 40.000  0.625   0.033   0.044
211.000 40.000  0.625   0.039   0.050
212.000 40.000  0.625   0.031   0.042
213.000 40.000  0.625   0.037   0.048
214.000 40.000  0.625   0.032   0.043
215.000 40.000  0.625   0.028   0.039
216.000 40.000  0.625   0.031   0.042
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to