[BioC] automating makeContrasts call in limm
Gordon Smyth
smyth at wehi.edu.au
Tue Mar 14 23:50:40 CET 2006
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=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
>>
>>
More information about the Bioconductor
mailing list