# R Analysis of a Two-Factor Study (Case II: Interaction Present) # We examine the Melon data used for the example from class. # Save the data file into a directory and # use the full path name: melon.data <- read.table(file = "z:/My Documents/teaching/stat_705/melondata.txt", header=FALSE, col.names = c('fung', 'concen', 'percent')) # attaching the data frame: attach(melon.data) # Making "fung" and "concen" factors: fung <- factor(fung) concen <- factor(concen) # Fitting the ANOVA model and producing the ANOVA table: melon.fit <- lm(percent ~ fung + concen + fung:concen); anova(melon.fit) # We see that a significant FUNG*CONCEN interaction is present (P-value=0.0163). # ###############################################################* # Tukey simultaneous CIs and hypothesis tests # The TukeyHSD function does the Tukey multiple comparison procedure in R. # The last column gives the ADJUSTED P-values. Using alpha=0.05 for the # experimentwise error rate, any pair of means with P-value LESS THAN 0.05 # in that column are judged to be significantly different by Tukey. # WITH interaction, the pairwise differences in mean response are calculated for all # pairs of factor level combinations: tapply(percent, fung:concen, mean) # This produces pairwise differences in mean response for all factor level combinations. # Assuming significant interaction between fung and concen, we can use familiar code but # we may look at the output marked $fung:concen for comparing ALL factor level combinations using Tukey: TukeyHSD(aov(melon.fit),conf.level=0.95) # The table shows the P-values for comparison among all factor level pairs. # These P-values below each t statistic are adjusted for the Tukey procedure. # conf.level=0.95 is actually the default level. We could choose # another level if desired. # ##################################################################* # Estimating and Testing about Constrasts in the Presence of Interaction my.interaction <- fung:concen # The different combinations are B:100, B:1000, C:100, C:1000, T:100, T:1000 # This can be seen by looking at: levels(my.interaction) # This will affect how we specify the interaction effects of interest. # This is our example from class: Is the difference between fungicides # B and C the same regardless of the concentration? contrasts(my.interaction) <- matrix(c(1, -1, -1, 1, 0, 0), nrow=6, ncol=1) summary(lm(percent ~ my.interaction)) # Look on line labeled 'my.interaction1' for P-value of t-test about this contrast. contrasts(my.interaction) <- matrix(c(1, 0, -1, 0, 0, 0), nrow=6, ncol=1) summary(lm(percent ~ my.interaction)) # Look on line labeled 'my.interaction1' for P-value of t-test about this contrast.