Skip to content

Instantly share code, notes, and snippets.

@marutter
Created March 25, 2011 00:06
Show Gist options
  • Select an option

  • Save marutter/886134 to your computer and use it in GitHub Desktop.

Select an option

Save marutter/886134 to your computer and use it in GitHub Desktop.
data <- read.table("Strawberry.txt",header=TRUE)
attach(data)
boxplot(Yield~Treatment)
boxplot(Yield~Block)
res <- lm(Yield~factor(Block)*Treatment)
anova(res)
res <- lm(Yield~factor(Block)+Treatment)
anova(res)
interaction.plot(Treatment,Block,Yield)
#
# Alfalfa, Randomized Complete Block Design
#
data <- read.table("Alfalfa.txt",header=TRUE)
attach(data)
table(Block,Variety)
boxplot(Yield~Block:Variety)
blockf <- factor(Block)
res <- lm(Yield~blockf*Variety)
anova(res)
# aov command
help(aov)
res <- aov(Yield~blockf*Variety)
summary(res)
#
# Alfalfa, subsetting
# That is, they took 3 subsamples from each EU
# Way too many samples
#
# Soultion 1: Average across the subsamples
#
data
nYield <- tapply(Yield,Variety:blockf,mean)
nYield
nVar <- rep(c("DuPuits","Flamand","Ladak","Narrag"),c(4,4,4,4))
nVar
nBlock <- factor(rep(c(1,2,3,4),4))
resn <- lm(nYield~nVar+nBlock)
anova(resn)
#
# Soultion 2: Manual F-test
#
res <- aov(Yield~blockf*Variety)
summary(res)
(f.value <- 12.4003/.4757)
1-pf(f.value,3,9)
anova(resn)
#
# Solution 3:
# Creative ANOVA
#
res2 <- aov(Yield~Variety+Error(blockf/Variety))
summary(res2)
anova(res)
# Error term says that Variety should be compared to the blockf/Variery MSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment