### R code for Lazic SE (2008). Statistical evaluation of methods ### for quantifying gene expression by autoradiography in histological ### sections. BMC Neuroscience. # load up required packages library(lattice); library(Hmisc); library(nlme) # read in the data. "Int" are the integrated values. MR.dat <- read.csv("MR-data.csv") # convert rat ID into a factor MR.dat$rat <- as.factor(MR.dat$rat) #reorders rats based on mean GL value MR.dat$rat <- reorder.factor(MR.dat$rat, MR.dat$line, max) # Figure 2: Variability of grey level values at different levels of the sampling hierarchy trellis.device(x11, theme="col.whitebg", height=5, width=5) dotplot(factor(rat)~line, groups=section, data=MR.dat, auto.key=list(columns=3), xlab="Grey level", ylab="Rat", xlim=c(42,70)) ## Variance Components Analysis #fits a linear mixed model to the data for each method mod.line <- lme(line~1, random=~1|rat/section, data=MR.dat) mod.outline <- lme(outline~1, random=~1|rat/section, data=MR.dat) mod.sd.thresh <- lme(sd.thresh~1, random=~1|rat/section, data=MR.dat) mod.mix.mod <- lme(mix.mod~1, random=~1|rat/section, data=MR.dat) mod.int.outline <- lme(int.outline~1, random=~1|rat/section, data=MR.dat) mod.int.sd.thresh <- lme(int.sd.thresh~1, random=~1|rat/section, data=MR.dat) mod.int.mix.mod <- lme(int.mix.mod~1, random=~1|rat/section, data=MR.dat) var.calc <- function(mod){ ## a function to extract the variance components and display as percentages vars <- VarCorr(mod) #calculates the variances ex.vars <- as.numeric(c(vars[,1][[2]],vars[,1][[4]],vars[,1][[5]])) #extracts the variances values <- round(100*(ex.vars/sum(ex.vars)), 1) #calculates percentages cat("\n\n Percent variability at each level\n") cat("Rats\t", "Sections\t", "Side+error\n") cat(values[1], "\t", values[2], "\t\t", values[3], "\n\n") } var.calc(mod.line) var.calc(mod.outline) var.calc(mod.sd.thresh) var.calc(mod.mix.mod) var.calc(mod.int.outline) var.calc(mod.int.sd.thresh) var.calc(mod.int.mix.mod) ## Averaging values for each rat and looking for floor effects avg.line <- summarize(MR.dat$line, MR.dat$rat, mean) #summarise line method for each rat avg.sd.thresh <- summarize(MR.dat$sd.thresh, MR.dat$rat, mean) #summarise SD threshold method for each rat all.equal(avg.line[,1], avg.sd.thresh[,1]) # a check to make sure order of rats is the same # (should return "TRUE") md <- function(x,y){ ## a function to compare two methods and look for a floor-effect d <- y - x # calculates difference m <- (x + y)/2 # calculates mean mod <- lm(d~m) # fits a model to the mean and difference values x11(width=7,height=4) par(mfrow=c(1,2), las=1) lims <- range(x,y) # calculates range of data for axes plot(x,y, xlim=lims, ylim=lims, pty="s"); abline(0,1) # plots method1 vs. method2 plot(d~m, type="n", pty="s") # mean-difference plot abline(h=0, col="darkgrey", lty=2); abline(mod) points(d~m) summary(mod) # output of regression to test for trend in mean-difference plot } md(avg.line[,2], avg.sd.thresh[,2]) # run the function to compare the SD threhold and line methods