Skip to content

Instantly share code, notes, and snippets.

@marutter
Created April 22, 2011 01:08
Show Gist options
  • Save marutter/935816 to your computer and use it in GitHub Desktop.
Save marutter/935816 to your computer and use it in GitHub Desktop.
# Bottling Plant Example
# Factor A: Machines - 3 levels
# Factor B: Operators nested withing machines - 4 each
# Response: Cases produced
data <- read.csv("nested.csv")
attach(data)
machf <- factor(machine)
operf <- factor(operator)
library(lattice)
xyplot(cases~operf|machf)
#
# Bad
#
res.1 <- lm(cases~machf)
anova(res.1)
res.2 <- lm(cases~machf*operf)
anova(res.2)
#
# Correct
#
res.n <- lm(cases~machf/operf)
anova(res.n)
#
TukeyHSD(aov(res.n),conf.leve=1-.05/2) # Both factors are significant
model.tables(aov(res.n),type="means")
# 4*3/2 comparions within each machine
# 3 machines
# 18 total
qt(1-.05/(2*18*2),48) # extra 2 since both factors are significant
qt(1-.05/(2*18*2),48)*sqrt(23.60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment