In r, how do I run a two-way ANOVA that uses type III errors and looks at pairwise comparisons?

I have a dataset with which I would like to compare the influence of species and habitat on the size of homerange - when using type III errors and pairwise comparisons within species and habitat.
Here is a subset of the data:

species<- c("a","b","c","c","b","c","b","b","a","b","c","c","a","a","b","b","a","a","b","c") habitat<- c("x","x","x","y","y","y","x","x","y","z","y","y","z","z","x","x","y","y","z","z") homerange<-c(6,5,7,8,9,4,3,5,6,9,3,6,6,7,8,9,5,6,7,8) data1<-data.frame(cbind(species, habitat, homerange)) data1$homerange<-as.numeric(as.character(data1$homerange)) 

I currently split the data into three species, then run separate ANOVA for each, but I think it makes sense to ask about the species and habitat at the same time as one ANOVA. Here is an example of ANOVA I for one view:

 data.species.a<-subset(data1, species=="a") fit<-aov(homerange ~ habitat, data=data.species.a) summary(fit) TukeyHSD(fit) 

aov () seems to be using type I. errors, which I find inappropriate; plus I believe that the Tukey test may be too conservative for pairwise comparisons. Can someone help me with an approach that allows me to run one ANOVA that takes into account both the influence of species and the habitat on the homerange, with type III errors, which also allows for less conservative pairing comparisons of species and habitat?

+4
source share
1 answer

You can configure Anova in the "car" package to report the sum of squares of type III, and there is HSD.test in the "agricolae" package, which should be able to take this model object as input. I don’t think you can legitimately use aov () when your data is unbalanced, so I do this with lm () matching.

 fit<-lm(homerange ~ habitat, data=data.species.a) require(car) Anova(fit, type="III") require(agricolae) comparison <- HSD.test(fit, "habitat", group=TRUE, main="Yield of sweetpotato\nDealt with different virus") 

Note that by default, SAS values ​​of sums of type III squares are considered with contempt (and sometimes openly ridiculed) by the authors of the basic package R ( read this for more details). The presentation of this method in the "car" package is intended mainly for comparison purposes, and not for recommendations regarding statistical correctness.

To add links to the reasons for the very cautious adoption of the SAS standard: Frank Harrell comments on re: power loss and Comments on later comments by Bill Venables the same thread on r-help

+3
source

Source: https://habr.com/ru/post/1432562/


All Articles