Difference between revisions of "PBP1Anovas.R"
m |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | # {{R}} | ||
# ============================================================================== | # ============================================================================== | ||
− | # Description: Insects from one line are bred at the same time. | + | # Description: Insects from one line are bred at the same time. |
# Catapillars are fed with two different treatments Esterase+Suc, or Suc | # Catapillars are fed with two different treatments Esterase+Suc, or Suc | ||
# and then at time = 0,1,3,5,7 they are killed and their RNA frozen at -80 | # and then at time = 0,1,3,5,7 they are killed and their RNA frozen at -80 |
Latest revision as of 00:43, 6 June 2007
Code snipits and programs written in R, S or S-PLUS
- ==============================================================================
- Description: Insects from one line are bred at the same time.
- Catapillars are fed with two different treatments Esterase+Suc, or Suc
- and then at time = 0,1,3,5,7 they are killed and their RNA frozen at -80
- Four real time runs are run over different days
- Three technical replicates (3 Wells) on each 384 well plate for each insect
- are measured using real time RT-PCR
- Main variability stratums of variation of concern are;
- Differences between runs, and differences between insects
- No effect of well position across the heat block over runs should exist
- ==============================================================================
- =============================== Setup ========================================
folder <- "/Volumes/HD2/Clinton/Data"
filename <- "PBPRTcompare2runs.txt"
dset <- read.table(file.path(folder,filename), header=T, sep="\t", as.is=T)
dset$Time <- factor(dset$Time) dset$Treatment <- factor(dset$Treatment, levels = sort(unique(dset$Treatment)),
labels=c("Sucrose","PBP1 dsRNA"))
dset$Run <- factor(dset[,1], levels = sort(unique(dset$Run)), labels=c("Run 2","Run 1")) dset$Insect <- factor(rep(1:(nrow(dset)/3), each=3)) dset$Well <- factor(dset$Well)
- ==============================================================================
- ============================ Normalization ===================================
- Normalization of realtime RT-PCR
dset$RE <- dset$Quantity/dset$NormFactor
- ==============================================================================
diag <- function(x, label) {
par(mfrow=c(2,2))
diag.plots <- function(x) { a <- plot(x$fit, x$res, xlab="fitted", ylab="residuals", main="residuals vs fitted") print(a) abline(h=0) qqnorm(x$res) jack <- rstudent(x) plot(jack, ylab="Jacknife residuals", main="Jackknife") cooks <- cooks.distance(x) if(!all(is.na(cooks))) { plot(cooks, ylab="Jacknife residuals") }
} if(missing(label)) { diag.plots(obj) } else { diag.plots(objlabel) } invisible()
}
- =============================== ANOVA ========================================
- Response: Quantity, RE
- Biological run: Run
- Explanatory variables; Treatment, Time
- Run:Treatment:Time = Each Insect technical replicate
- ========================= Testing Run and Insect =============================
- Insect is the same as Run:Treatment:Time
default <- options(show.signif.stars=F) obj <- aov(RE ~ Time * Treatment + Run + Error(Insect), data=dset) summary(obj) obj <- aov(RE ~ Time * Treatment + Error(Run + Insect), data=dset) summary(obj)
summary(obj, split=list(Time=list(L=1, Q=2, C=3)))
options(default)
- ==============================================================================
aovtable <- function(obj) {
library(Hmisc) Sys.putenv("DISPLAY"=":0") anova.header <- t(c("$Source$","$df$","$SS$","$MS$","$F$","$p{\;}value$")) Run <- matrix("", nc=6, nr=1) tmp <- summary(obj)$"Error: Run"1[1:3] Run[,1] <- rownames(tmp[1]) Run[1,2] <- unlist(tmp[1]) Run[1,3:4] <- round(unlist(tmp[2:3]),2) Insect <- matrix("", nc=6, nr=4) Insect[,1] <- rownames(summary(obj)$"Error: Insect"1) Insect[,2] <- summary(obj)$"Error: Insect"1[,1] Insect[,3] <- round(summary(obj)$"Error: Insect"1[,2],2) Insect[,4] <- round(summary(obj)$"Error: Insect"1[,3],2) Insect[,5] <- round(summary(obj)$"Error: Insect"1[,4],2) Insect[,6] <- signif(summary(obj)$"Error: Insect"1[,5],2) Replicates <- matrix("", nc=6, nr=1) tmp <- summary(obj)$"Error: Within"1[1:3] Replicates[,1] <- rownames(tmp[1]) Replicates[1,2] <- unlist(tmp[1]) Replicates[1,3:4] <- round(unlist(tmp[2:3]),2) aovTable <- rbind( c("$Error(Run)$", rep("",5)), Run, c("$Error(Insect)$", rep("",5)), Insect, c("$Error(Reps)$", rep("",5)), Replicates ) aovTable[is.na(aovTable)] <- "" dimnames(aovTable)2 <- anova.header latex(aovTable, file="/Volumes/HD2/Clinton/Latex/PBP11table.tex") invisible()
}
aovtable(obj)
- ============================= LSD calculation ================================
- Extracting the correct residual
MSE <- summary(obj$Insect)1[4,"Mean Sq"] resid.df <- summary(obj$Insect)1[4,"Df"] alpha <- 0.995 PBPlsd <- qt( alpha, resid.df) * sqrt(2 * MSE / resid.df)
- ==============================================================================
- =========================== Tukey LSD calculation ============================
- First principles
PBPtukeylsd <- qtukey(0.975, 4, resid.df) * sqrt(2 * MSE / resid.df)
- Not working!!!
- TukeyHSD(obj$Insect, "Time:Treatment", ordered=F)
- library(multcomp)
- simint.formula(formula = RE ~ Time * Treatment + Error(Run + Insect), data = dset,
- whichf = "time", type = "Tukey")
- ==============================================================================
- diag(obj, "(Intercept)")
diag(obj, "Insect") diag(obj, "Within")