I'm relatively new to the R language, and using it to analyse my data. I am using a package called 'agricolae' and its HSD.test component to output tukeyHSD results based on the anova proceeding it. I have simplified the code below, but essentially the tukey code is run inside a for loop running through a list of factors/interactions. It works fine, however, I only want the loop to run where the anova result for the corresponding factor is significant. (i.e. <= 0.05).
f1 <- as.formula(paste(m,'~ Treatment + Genotype + GENOTYPExTREATMENT', sep = ''))
anova.result <- aov(f1, data = licor.data2)
treatment.list <- c('Treatment','Genotype', 'GENOTYPExTREATMENT')
for(t in treatment.list){
tukey.result <- HSD.test(anova.result, trt = t)$groups
}
using rownames(summary(anova.result)[[1]])
returns [1] "Treatment " "Genotype " "GENOTYPExTREATMENT" "Residuals "
and str(summary(anova.result)[[1]]) returns:
Classes ‘anova’ and 'data.frame': 4 obs. of 5 variables:
$ Df : num 4 6 24 99
$ Sum Sq : num 0.01215 0.0019 0.00255 0.00527
$ Mean Sq: num 3.04e-03 3.16e-04 1.06e-04 5.33e-05
$ F value: num 57.02 5.94 1.99 NA
$ Pr(>F) : num 7.22e-25 2.50e-05 9.68e-03 NA
Just wondering if someone knows how to construct a when or if/else statement which will only run the loop code where the $Pr(>F) value for the corresponding 't' loop factor or interaction is less than 0.05.
thanks in advance,
Luke