automating makeContrasts call in limm
1
0
Entering edit mode
@gordon-smyth
Last seen 3 hours ago
WEHI, Melbourne, Australia
> Date: Sat, 11 Mar 2006 15:16:38 -0500 > From: Francois Pepin <fpepin at="" cs.mcgill.ca=""> > Subject: [BioC] automating makeContrasts call in limma > To: bioconductor at stat.math.ethz.ch > > Hi everyone, > > is there a way to automate calls to makeContrasts? Right now, all the > contrasts have to be typed in or hard-coded. We're dealing with a couple > of hundreds of samples and it would make my life a lot easier if we > could generate everything automatically. I've looked briefly in the > archives but didn't find anything. > > Ideally, I would want to have a way to do: > > myContrasts<-c("t1-t2","t1-3","t2-t3") > contrast.matrix<-makeContrasts(myContrasts,levels=design) Your question isn't clear, at least not to me. What is wrong with the code you've just given? Is your question that you'd like to compute all pairwise comparisons between hundreds of different treatments or patients? If that is your real question, it might be best to tell us a little more about your experiment. It is easily done, but it doesn't sound necessarily very sensible. Gordon > I haven't found a way to properly go around the 'substitute(list(...))' > call inside of makeContrasts. > > Right now, I'm writing code to output the proper call and copy/paste it > back in the console. > > Another alternative would be to create the contrast matrix myself. That > would be a more elegant way of doing it, but I don't quite feel > comfortable enough (yet) with design matrices for that. > > Francois
GO GO • 1.3k views
ADD COMMENT
0
Entering edit mode
Francois Pepin ★ 1.3k
@francois-pepin-1012
Last seen 9.6 years ago
> > Ideally, I would want to have a way to do: > > > > myContrasts<-c("t1-t2","t1-3","t2-t3") > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > > Your question isn't clear, at least not to me. What is wrong with the code you've just given? Sorry, I thought this was a well-known "feature" of the makeContrasts function, so I didn't go into the details. So to complete the toy example with 3 treatments and dye swaps of each: > design t1 t2 t3 [1,] -1 0 0 [2,] 1 0 0 [3,] 0 -1 0 [4,] 0 1 0 [5,] 0 0 -1 [6,] 0 0 1 > myContrasts [1] "t1-t2" "t1-3" "t2-t3" > contrast.matrix<-makeContrasts(myContrasts,levels=design) > contrast.matrix myContrasts t1 "t1-t2" t2 "t1-3" t3 "t2-t3" Which doesn't make for a usable design matrix. The expected behavior is: > contrast.matrix<-makeContrasts("t1-t2","t1-t3","t2-t3",levels=design) > contrast.matrix t1-t2 t1-t3 t2-t3 t1 1 1 0 t2 -1 0 1 t3 0 -1 -1 > sessionInfo() R version 2.1.0, 2005-04-18, x86_64-unknown-linux-gnu attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" other attached packages: limma "1.9.6" > Is your question that you'd like to compute all pairwise comparisons between hundreds of different > treatments or patients? No. I have tumors and normal samples for each patient. One of the things I'd like to do is tumor vs normal for all each of the patients. Another would be to automate the comparisons between clinical variables. It's just cumbersome (and error-prone) to do by hand when there are over 50 patients. Francois
ADD COMMENT
0
Entering edit mode
Hi Gordon, I should mention that the behavior is different with R 2.2, but it still doesn't work. > myContrasts<-c("t1-t2","t1-3","t2-t3") > contrast.matrix<-makeContrasts(myContrasts,levels=design) Error in eval(expr, envir, enclos) : object "myContrasts" not found > traceback() 3: eval(expr, envir, enclos) 2: eval(ej, envir = levelsenv) 1: makeContrasts(myContrasts, levels = design) > sessionInfo() R version 2.2.0, 2005-10-06, x86_64-redhat-linux-gnu attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" other attached packages: limma "2.3.7" I don't have any machine with R 2.3, but I could install it. Francois On Mon, 2006-03-13 at 11:31 -0500, Francois Pepin wrote: > > > Ideally, I would want to have a way to do: > > > > > > myContrasts<-c("t1-t2","t1-3","t2-t3") > > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > > > > Your question isn't clear, at least not to me. What is wrong with the code you've just given? > > Sorry, I thought this was a well-known "feature" of the makeContrasts > function, so I didn't go into the details. > > So to complete the toy example with 3 treatments and dye swaps of each: > > > design > t1 t2 t3 > [1,] -1 0 0 > [2,] 1 0 0 > [3,] 0 -1 0 > [4,] 0 1 0 > [5,] 0 0 -1 > [6,] 0 0 1 > > > myContrasts > [1] "t1-t2" "t1-3" "t2-t3" > > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > > contrast.matrix > myContrasts > t1 "t1-t2" > t2 "t1-3" > t3 "t2-t3" > > Which doesn't make for a usable design matrix. The expected behavior is: > > > contrast.matrix<-makeContrasts("t1-t2","t1-t3","t2-t3",levels=design) > > contrast.matrix > t1-t2 t1-t3 t2-t3 > t1 1 1 0 > t2 -1 0 1 > t3 0 -1 -1 > > > sessionInfo() > R version 2.1.0, 2005-04-18, x86_64-unknown-linux-gnu > > attached base packages: > [1] "methods" "stats" "graphics" "grDevices" "utils" > "datasets" > [7] "base" > > other attached packages: > limma > "1.9.6" > > > > > Is your question that you'd like to compute all pairwise comparisons between hundreds of different > > treatments or patients? > > No. I have tumors and normal samples for each patient. One of the things > I'd like to do is tumor vs normal for all each of the patients. Another > would be to automate the comparisons between clinical variables. It's > just cumbersome (and error-prone) to do by hand when there are over 50 > patients. > > Francois > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor >
ADD REPLY
0
Entering edit mode
Hi eveyrone, Thanks to Carolyn Fitzsimmons for pointing out that there was indeed a bug in that code. The behavior on R 2.2 is indeed the same as with R 2.1. Sorry about that. Francois On Mon, 2006-03-13 at 11:53 -0500, Francois Pepin wrote: > Hi Gordon, > > I should mention that the behavior is different with R 2.2, but it still > doesn't work. > > > myContrasts<-c("t1-t2","t1-3","t2-t3") > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > Error in eval(expr, envir, enclos) : object "myContrasts" not found > > traceback() > 3: eval(expr, envir, enclos) > 2: eval(ej, envir = levelsenv) > 1: makeContrasts(myContrasts, levels = design) > > > sessionInfo() > R version 2.2.0, 2005-10-06, x86_64-redhat-linux-gnu > > attached base packages: > [1] "methods" "stats" "graphics" "grDevices" "utils" > "datasets" > [7] "base" > > other attached packages: > limma > "2.3.7" > > I don't have any machine with R 2.3, but I could install it. > > Francois > > On Mon, 2006-03-13 at 11:31 -0500, Francois Pepin wrote: > > > > Ideally, I would want to have a way to do: > > > > > > > > myContrasts<-c("t1-t2","t1-3","t2-t3") > > > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > > > > > > Your question isn't clear, at least not to me. What is wrong with the code you've just given? > > > > Sorry, I thought this was a well-known "feature" of the makeContrasts > > function, so I didn't go into the details. > > > > So to complete the toy example with 3 treatments and dye swaps of each: > > > > > design > > t1 t2 t3 > > [1,] -1 0 0 > > [2,] 1 0 0 > > [3,] 0 -1 0 > > [4,] 0 1 0 > > [5,] 0 0 -1 > > [6,] 0 0 1 > > > > > myContrasts > > [1] "t1-t2" "t1-3" "t2-t3" > > > > > contrast.matrix<-makeContrasts(myContrasts,levels=design) > > > contrast.matrix > > myContrasts > > t1 "t1-t2" > > t2 "t1-3" > > t3 "t2-t3" > > > > Which doesn't make for a usable design matrix. The expected behavior is: > > > > > contrast.matrix<-makeContrasts("t1-t2","t1-t3","t2-t3",levels=design) > > > contrast.matrix > > t1-t2 t1-t3 t2-t3 > > t1 1 1 0 > > t2 -1 0 1 > > t3 0 -1 -1 > > > > > sessionInfo() > > R version 2.1.0, 2005-04-18, x86_64-unknown-linux-gnu > > > > attached base packages: > > [1] "methods" "stats" "graphics" "grDevices" "utils" > > "datasets" > > [7] "base" > > > > other attached packages: > > limma > > "1.9.6" > > > > > > > > > Is your question that you'd like to compute all pairwise comparisons between hundreds of different > > > treatments or patients? > > > > No. I have tumors and normal samples for each patient. One of the things > > I'd like to do is tumor vs normal for all each of the patients. Another > > would be to automate the comparisons between clinical variables. It's > > just cumbersome (and error-prone) to do by hand when there are over 50 > > patients. > > > > Francois > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor at stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > >
ADD REPLY
0
Entering edit mode
Hi Francois, I think that you are asking for makeContrasts() to accept a character vector of contrasts. At the moment, it expects contrasts to be specified via expressions, character strings or character vectors of length 1. In fact, even the treatment of character vectors of length 1 has been somewhat unstable, partly because of changes to what is permissible for new.env() calls in R 2.3. I will look into making the makeContrasts() more predictable in terms of character variable arguments. Once that is done a solution to your problem should be simple. In the meantime, you might consider using paste() to assemble your makeContrasts() call as a character string, and then evaluate it using eval(). This would allow you to program it (entirely in R) instead of entering it at the interactive prompt. Best Gordon Francois Pepin wrote: >Hi Gordon, > >I should mention that the behavior is different with R 2.2, but it still >doesn't work. > > > >> myContrasts<-c("t1-t2","t1-3","t2-t3") >>contrast.matrix<-makeContrasts(myContrasts,levels=design) >> >> >Error in eval(expr, envir, enclos) : object "myContrasts" not found > > >>traceback() >> >> >3: eval(expr, envir, enclos) >2: eval(ej, envir = levelsenv) >1: makeContrasts(myContrasts, levels = design) > > > >>sessionInfo() >> >> >R version 2.2.0, 2005-10-06, x86_64-redhat-linux-gnu > >attached base packages: >[1] "methods" "stats" "graphics" "grDevices" "utils" >"datasets" >[7] "base" > >other attached packages: > limma >"2.3.7" > >I don't have any machine with R 2.3, but I could install it. > >Francois > >On Mon, 2006-03-13 at 11:31 -0500, Francois Pepin wrote: > > >>>>Ideally, I would want to have a way to do: >>>> >>>>myContrasts<-c("t1-t2","t1-3","t2-t3") >>>>contrast.matrix<-makeContrasts(myContrasts,levels=design) >>>> >>>> >>>Your question isn't clear, at least not to me. What is wrong with the code you've just given? >>> >>> >>Sorry, I thought this was a well-known "feature" of the makeContrasts >>function, so I didn't go into the details. >> >>So to complete the toy example with 3 treatments and dye swaps of each: >> >> >> >>>design >>> >>> >> t1 t2 t3 >>[1,] -1 0 0 >>[2,] 1 0 0 >>[3,] 0 -1 0 >>[4,] 0 1 0 >>[5,] 0 0 -1 >>[6,] 0 0 1 >> >> >> >>>myContrasts >>> >>> >>[1] "t1-t2" "t1-3" "t2-t3" >> >> >> >>>contrast.matrix<-makeContrasts(myContrasts,levels=design) >>>contrast.matrix >>> >>> >> myContrasts >>t1 "t1-t2" >>t2 "t1-3" >>t3 "t2-t3" >> >>Which doesn't make for a usable design matrix. The expected behavior is: >> >> >> >>>contrast.matrix<-makeContrasts("t1-t2","t1-t3","t2-t3",levels=desig n) >>>contrast.matrix >>> >>> >> t1-t2 t1-t3 t2-t3 >>t1 1 1 0 >>t2 -1 0 1 >>t3 0 -1 -1 >> >> >> >>>sessionInfo() >>> >>> >>R version 2.1.0, 2005-04-18, x86_64-unknown-linux-gnu >> >>attached base packages: >>[1] "methods" "stats" "graphics" "grDevices" "utils" >>"datasets" >>[7] "base" >> >>other attached packages: >> limma >>"1.9.6" >> >> >> >> >> >>>Is your question that you'd like to compute all pairwise comparisons between hundreds of different >>>treatments or patients? >>> >>> >>No. I have tumors and normal samples for each patient. One of the things >>I'd like to do is tumor vs normal for all each of the patients. Another >>would be to automate the comparisons between clinical variables. It's >>just cumbersome (and error-prone) to do by hand when there are over 50 >>patients. >> >>Francois >> >>
ADD REPLY

Login before adding your answer.

Traffic: 841 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6