Created
February 17, 2011 15:50
-
-
Save marutter/831958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Start with Basic ANOVA | |
| # | |
| data <- read.table("CH18TA05.txt",col.names=c("failure","loc","observation")) | |
| attach(data) | |
| locf <- factor(loc,levels=c(1:3),labels=c("Loc 1","Loc 2","Loc 3")) | |
| result <- lm(failure~locf) | |
| anova(result) | |
| boxplot(failure~locf) | |
| names(result) | |
| plot(result$fited.values,result$residuals) | |
| plot(result$fit,result$res) | |
| plot(result,1) | |
| install.packages("car") | |
| library(car) | |
| qqPlot(result) | |
| leveneTest(result,center=mean) # Levene Test | |
| leveneTest(result,center=median) # Brown-Forsythe | |
| # | |
| # Ratios: Which is the most consistent | |
| # | |
| tapply(failure,locf,var)/tapply(failure,locf,mean) # Square root | |
| tapply(failure,locf,sd)/tapply(failure,locf,mean) # Natural Log | |
| tapply(failure,locf,sd)/tapply(failure,locf,mean)^2 # 1/Y | |
| boxplot(log(failure)~locf) | |
| res2 <- lm(log(failure)~locf) | |
| anova(res2) | |
| qqPlot(res2) | |
| plot(res2,1) | |
| # Box Cox | |
| boxCox(result) | |
| res3 <- lm(failure^.1~locf) | |
| anova(res3) | |
| qqPlot(res3) | |
| # | |
| # Does this effect the Tukey Test? | |
| # | |
| TukeyHSD(aov(result),conf.level=.95) | |
| TukeyHSD(aov(res3),conf.level=.95) | |
| # | |
| # Does it effect fit.contrast? | |
| # | |
| library(gmodels) | |
| fit.contrast(result,locf,c(-1,1,0)) | |
| fit.contrast(res3,locf,c(-1,1,0)) | |
| # | |
| # Confidence interval for Location 1 | |
| # | |
| (mu.i <- tapply(failure,locf,mean)) | |
| n.i <- tapply(failure,locf,length) | |
| anova(result) | |
| mse <- 6353.2 | |
| mu.i[1] + c(-1,1)*qt(.975,12)*sqrt(mse/n.i[1]) | |
| # With transformation | |
| (mu.i <- tapply(failure^.1,locf,mean)) | |
| n.i <- tapply(failure^.1,locf,length) | |
| anova(res3) | |
| mse <- 0.028894 | |
| mu.i[1] + c(-1,1)*qt(.975,12)*sqrt(mse/n.i[1]) | |
| (mu.i[1] + c(-1,1)*qt(.975,12)*sqrt(mse/n.i[1]))^(1/.1) | |
| library(gplots) | |
| (se.i <- sqrt(mse/n.i)) | |
| barplot2(mu.i^(1/.1),plot.ci=TRUE,ci.l=(mu.i-qt(.975,24)*se.i)^(1/.1),ci.u=(mu.i+qt(.975,24)*se.i)^(1/.1)) | |
| # | |
| # Arcsin Transformation | |
| # | |
| data2 <- read.csv("seed.csv") | |
| attach(data2) | |
| boxplot(p.germ~treatment) | |
| result <- lm(p.germ~factor(treatment)) | |
| anova(result) | |
| qqPlot(result) | |
| leveneTest(result,center=mean) | |
| leveneTest(result,center=median) | |
| p.germ.t <- 2*asin(sqrt(p.germ)) | |
| boxplot(p.germ.t~treatment) | |
| result <- lm(p.germ.t~factor(treatment)) | |
| anova(result) | |
| qqPlot(result) | |
| leveneTest(result,center=mean) | |
| leveneTest(result,center=median) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment