Skip to content

Instantly share code, notes, and snippets.

@marutter
Created February 25, 2011 01:11
Show Gist options
  • Select an option

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

Select an option

Save marutter/843242 to your computer and use it in GitHub Desktop.
# Example 1
data <- read.csv("chol_hair_music.csv")
attach(data)
head(data)
# Box Plots
boxplot(chol~hair)
boxplot(chol~music)
boxplot(chol~music:hair)
# Balanced?
table(music,hair)
# Means
tapply(chol,music,mean)
tapply(chol,hair,mean)
tapply(chol,hair:music,mean)
# Treatment Mean Plots/Interaction Plots
interaction.plot(hair,music,chol)
interaction.plot(music,hair,chol)
# Example 2
data <- read.csv("sulpher.csv")
attach(data)
head(data)
nitf <- factor(nitrogen)
sulf <- factor(sulpher)
# Box Plots
boxplot(yield~nitf)
boxplot(yield~sulf)
boxplot(yield~nitf:sulf)
# Balanced?
table(sulf,nitf)
# Means
tapply(yield,sulf,mean)
tapply(yield,sulf:nitf,mean)
# Treatment Mean Plots/Interaction Plots
interaction.plot(nitf,sulf,yield)
interaction.plot(sulf,nitf,yield)
#
# Two Factor ANOVA in R
#
res1 <- lm(chol~hair+music)
anova(res1)
res2 <- lm(chol~hair:music)
anova(res2)
res3 <- lm(chol~hair+music+hair:music)
anova(res3)
res3b <- lm(chol~hair*music)
anova(res3b)
model.tables(aov(res3),"means")
model.tables(aov(res3),"effects")
TukeyHSD(aov(res3),which="hair")
TukeyHSD(aov(res3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment