###################################################################### # Factorial analysis code ###################################################################### # # Version 1 by Sohela Shah and Saunak Sen # Date 11 September 2009 # ####################################################################### # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.gnu.org/licenses/. ####################################################################### # This code is meant to accompany the paper entitled Strain Background # Modifies Phenotypes in the Atp8b1-Deficient Mouse # by S. Shah, U.R. Sanford, J. Vargas, H. Xu, A. Groen, # C.C. Paulusma, L. Pawlikowska, S. Sen, R.P.J. Oude Elferink, # L.N. Bull ######################################################################## # Our objective is to analyze the pup weight (at toe clip and weaning) to # discover differences between strains (C57BL/6, 129S, and F1), genotype # (mutant or wild type), and sex. The initial (base) analysis focused on # these factors and their interaction. Two 129S sub-strains (129S1 and 129S4) # were used. These were combined into one group for both pure strains # and F1 mice. # We entered data from two sheets saved as CSV files in MS Excel and # then combine them into a single table. The column names were consistent # across sheets, which was checked. # input data files wt <- read.delim("/Users/sohelashah/Documents/Cholestasis/Mouse data/Pup-record/WT weights norm.txt") mut <- read.delim("/Users/sohelashah/Documents/Cholestasis/Mouse data/Pup-record/Mutant weights norm.txt") # keep subset to rows with meaningful data, remove rows with no data idx <- complete.cases(wt[,2]) wt <-wt[idx,] idx <- complete.cases(mut[,2]) mut <-mut[idx,] idx.c <- c(1:8) #combine data files into one matrix pupwt <- rbind(wt[,idx.c],mut[,idx.c]) # assign column names names(pupwt)<-c("mouse","sex","strain","genotype","wt1","n.wt1","wt2","n.wt2") # set strain, genotype, and sex as factors pupwt$strain <- as.factor(as.character(pupwt$strain)) pupwt$sex <- as.factor(as.character(pupwt$sex)) pupwt$genotype <- as.factor(as.character(pupwt$genotype)) # combine the 2 S129 strains pupwt$strain2 <- pupwt$strain idx <- grep("S",as.character(pupwt$strain)) pupwt $strain2 <- as.character(pupwt$strain2) pupwt$strain2[idx] <- "S129" pupwt$strain2 <- as.factor(pupwt$strain2) # combine the 2 F1 strains pupwt$strainC <- pupwt$strain2 idx <- grep("F",as.character(pupwt$strain2)) pupwt$strainC <- as.character(pupwt$strainC) pupwt$strainC[idx] <- "F1" pupwt$strainC <- as.factor(pupwt$strainC) contrasts(pupwt$strainC) <- contr.treatment(3) pupwt$genotype <- relevel(pupwt$genotype,2) # Generalized linear mode for stepwise regression fitbic <- function(formula,data,...) { git <- glm(as.formula(formula),data=data,...) # hit <- step(git,k=log(nrow(git$qr$qr)),trace=0) hit <- step(git,k=log(length(git$residuals)),trace=0) # print(summary(hit)$call) # print(summary(hit)$coefficients,digits=3) print(summary(hit),sign=FALSE,digits=2) hit } plotpheno <- function(x,y,z,xlab="",ylab="",fac=0,cex=0.7) { xylim <- range(c(x,fac+y),na.rm=T) plot(x,y,xlim=xylim,ylim=xylim-fac,xlab=xlab,ylab=ylab,type="n") # open circles points(x[z],y[z],pch=21,cex=cex) # solid circles points(x[!z],y[!z],pch=19,cex=cex) lines(xylim,xylim-fac) } form.a <- "strainC*genotype*sex" pupwt$n.wt1<-as.numeric(pupwt$n.wt1) pupwt$n.wt2<-as.numeric(pupwt$n.wt2) form.start <- "log(n.wt1) ~" form.end <- "log(n.wt2) ~" idx.se <- complete.cases(pupwt$n.wt1,pupwt$n.wt2) idx <- which(!is.na(log(pupwt$n.wt1))&!is.na(log(pupwt$n.wt2))&(pupwt$n.wt1!=0)&(pupwt$n.wt2!=0)) pupwt.comp<-pupwt[idx,] # Fit toe clip weight data using fitbit function hit0 <- fitbic( as.formula(paste(form.start,form.a)), data=pupwt.comp) # Fit wean weight data using fitbit function hit1 <- fitbic( as.formula(paste(form.end,form.a)), data=pupwt.comp)