[R] Why do I get different results for type III anova using the drop1 or Anova command?

C. Weiner BioGrundkurs at shared-files.de
Mon Oct 8 01:37:28 CEST 2012


Dear experts,

I just noticed that I get different results conducting type III anova 
using drop1 or the Anova command from the car package. I suppose I made 
a mistake and hope you can offer me some help. I have no idea where I 
got wrong and would be very grateful for explaination as R is new 
terrain for me.
If I run the commands in line, they produce the same results. But if I 
run them in seperate windows, they produce different results.

What I did in easy words:
Opened R prompt, ran parts 0 and 1-> got result 1
Opened new R prompt, ran parts 0 and 2 ->got result 2, ran part 1 
following part 2, got result 2a

Why are the results different when they are run seperately and why do 
the commands produce the same results when running one after the other? 
Which results can I rely on? I based my script on:
http://mcfromnz.wordpress.com/2011/03/0 ... explained/ 
<http://mcfromnz.wordpress.com/2011/03/02/anova-type-iiiiii-ss-explained/> 
but I surely made mistakes.

Thanks for help.
Kind regards,
Christiane



#0
library(car)
P<-read.table("rhoPgegenrhoAgewichtet-mit Befruchtungssystem0912.txt", 
sep="\t",dec=",", header=T,encoding="latin1")
summary(P)
str(P)

#1
modD3 <- lm(P$rhoPug ~ P$rhoAg*P$dprime*P$Befruchtungssystem, data=P)

Anova(modD3,contrasts=list(rhoAg=contr.sum, dprime=contr.poly), 
type="III") ###liefert dieses Ergebnis, wenn der Befehl als erster läuft
#Response: P$rhoPug
# Sum Sq Df F value Pr(>F)
#(Intercept) 0.07719 1 4.5075 0.03530 *
#P$rhoAg 0.00687 1 0.4014 0.52730
#P$dprime 0.00176 1 0.1029 0.74882
#P$Befruchtungssystem 0.00250 1 0.1461 0.70280
#P$rhoAg:P$dprime 0.00931 1 0.5439 0.46193
#P$rhoAg:P$Befruchtungssystem 0.00001 1 0.0004 0.98343
#P$dprime:P$Befruchtungssystem 0.00108 1 0.0630 0.80214
#P$rhoAg:P$dprime:P$Befruchtungssystem 0.00206 1 0.1205 0.72893
#Residuals 2.70584 158


#2
options(contrasts = c("contr.sum","contr.poly")) #liefert ein anderes 
Ergebnis als der Befehl oben, wenn der obere Befehl NICHT gelaufen ist
modD3 <- lm(P$rhoPug ~ P$rhoAg*P$dprime*P$Befruchtungssystem, data=P)
drop1(modD3,.~.,test="F") # type III SS and F Test
P$rhoPug ~ P$rhoAg * P$dprime * P$Befruchtungssystem
Df Sum of Sq RSS AIC F value Pr(F)
<none> 2.7058 -667.35
P$rhoAg 1 0.0131973 2.7190 -668.54 0.7706 0.3814 !!
P$dprime 1 0.0002240 2.7061 -669.34 0.0131 0.9091 !!
P$Befruchtungssystem 1 0.0025022 2.7083 -669.20 0.1461 0.7028 !!
P$rhoAg:P$dprime 1 0.0283677 2.7342 -667.62 1.6565 0.2000 !!
P$rhoAg:P$Befruchtungssystem 1 0.0000074 2.7058 -669.35 0.0004 0.9834
P$dprime:P$Befruchtungssystem 1 0.0010790 2.7069 -669.29 0.0630 0.8021
P$rhoAg:P$dprime:P$Befruchtungssystem 1 0.0020641 2.7079 -669.22 0.1205 
0.7289


#2a (command is the same as in 1, but results are different if the 
command is run after the one above)
Anova(modD3,contrasts=list(Befruchtungssystem="contr.sum", 
dprime="contr.poly"), type="III") #liefert in nachstehend nach dem 
2.Befehl dieses Ergebnis
#Response: P$rhoPug #also jetzt dasselbe wie drop1, aber nicht dasselbe, 
das
#der exakt gleich Befehl alleine geliefert hätte. Was
#stimmt den nun? Wo liegt mein Fehler?
# Sum Sq Df F value Pr(>F)
#(Intercept) 0.06877 1 4.0158 0.04679 *
#P$rhoAg 0.01320 1 0.7706 0.38136
#P$dprime 0.00022 1 0.0131 0.90909
#P$Befruchtungssystem 0.00250 1 0.1461 0.70280
#P$rhoAg:P$dprime 0.02837 1 1.6565 0.19997
#P$rhoAg:P$Befruchtungssystem 0.00001 1 0.0004 0.98343
#P$dprime:P$Befruchtungssystem 0.00108 1 0.0630 0.80214
#P$rhoAg:P$dprime:P$Befruchtungssystem 0.00206 1 0.1205 0.72893
#Residuals 2.70584 158



More information about the R-help mailing list