Skip to content

Instantly share code, notes, and snippets.

@marutter
Created January 21, 2011 01:36
Show Gist options
  • Select an option

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

Select an option

Save marutter/789101 to your computer and use it in GitHub Desktop.
p16.7 <- read.table("CH16PR07.txt")
p16.7
p16.7$V1
p16.7$V2
names(p16.7) <- c("improvement","rd","observation")
p16.7$improvement
p16.7$imp
p16.7$rd
boxplot(improvement~rd,data=p16.7)
improvement
attach(p16.7)
improvement
boxplot(improvement~rd)
rd[rd==1] <- "low"
rd[rd==2] <- "moderate"
rd[rd==3] <- "high"
boxplot(improvement~rd)
mean(improvement)
sd(improvement)
tapply(improvement,rd,mean)
tapply(improvement,rd,sd)
#
# Read from a csv files
#
data2 <- read.csv("productivity.csv")
data2
#
# Finding the sums of squares
# SSTO
mu <- mean(improvement)
ssto <- sum((improvement-mu)^2)
ssto
# SSTR
table(rd)
mu.i <- tapply(improvement,rd,mean)
mu.i
(mu.i-mu)^2
table(rd)*(mu.i-mu)^2
sstr <- sum(table(rd)*(mu.i-mu)^2)
sstr
#
sse <- ssto-sstr
sse
#
# How small a SSTR is small?
#
mstr <- sstr/2
mse <- sse/24 #nt-r
# f stat
f <- mstr/mse
f
pf(f,2,24,lower=FALSE)
#
# Another Example
#
set.seed(1234)
y <- c(rnorm(25,10,5),rnorm(25,10,5),rnorm(25,10,5))
x <- rep(1:3,each=25)
boxplot(y~x)
mu <- mean(y)
ssto <- sum((y-mu)^2)
mu.i <- mu.i <- tapply(y,x,mean)
sstr <- sum(25*(mu.i-mu)^2)
ssto
sstr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment