I'm sure this is an easy question, but I'm fairly new to using limma and R and I'd appreciate any help or guidance. I've run a paired limma analysis trying to look at differentially expressed genes in a pre-post experiment design. I'm trying to understand what direction my logFC values represent i.e. whether the gene is being up regulated or down regulated from pre to post or post to pre. My code is as follows:
write.exprs(e,file="expressionDataHFNIH5-7-14.txt") d<-read.table("expressionDataHFNIH5-7-14.txt", header=T, row.names=1) names(d)<-gsub(".CEL", "", gsub("X", "", names(d))) d<-round(d, 5) write.table(d, file="filepath.txt", quote=F, sep='\t') #create a design matrix #congestion 1=pre and 2=post design <- cbind(ID = c(1,1,2,2,7,7,8,8,9,9,10,10,11,11,14,14,16,16,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,33,33,34,34,35,35,36,36,37,37,39,39,40,40,41,41), Congestion=c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2)) ID<-factor(design[,1]) Congestion<-factor(design[,2], levels=c("1","2")) #create a design matrix design<-model.matrix(~ID+Congestion) fit <- lmFit(e, design) fit <- eBayes(fit) topTable(fit, coef = "Congestion2", adjust = "fdr") topt2<-topTable(fit, coef = "Congestion2", adjust.method = "fdr", n=Inf, sort.by="p") write.table(topt2,file="filepath.txt",quote=F,sep='\t'
Thank you!
Thank you! One more question for my understanding, is it post over pre because of the way in which I've ordered it in my levels and design matrix? So if I decided that I wanted to determine my log-fold change of my "1" samples over my "2" samples then I would need to interchange their order to derive that value?
ah never mind you just answered it. Thank you so much for your help.
Yeah,
model.matrix
will choose the first level as the "reference". You should be able to flip it around by settinglevels=c("2","1")
in the construction of theCongestion
variable, in which case you should end up withCongestion1
as the relevant coefficient to drop for your DE testing.Thank you so much! This was really helpful.