pass limma contrast matrix variable
1
0
Entering edit mode
@john-linux-user-4917
Last seen 9.0 years ago
United States

Hi

I tried to pass a contrast matrix as string variable, such as s=c("ab=a-b","ac=a-c") to makeContrasts(s), but it did not work. When I manually typed in ("ab=a-b","ac=a-c"), it works.  Could some experts provide any suggestions?

Thanks.

John   

contrast limma • 1.7k views
ADD COMMENT
0
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 1 hour ago
The city by the bay

The makeContrasts function accepts a variable number of arguments. When you type in "ab=a-b" and "ac=a-c" separately, each string is treated as a separate argument. A separate contrast is then constructed for each string, which is probably your desired behaviour. However, the vector s is passed into the function as a single argument. This means that only one contrast is constructed, corresponding to the first string in s.

To get back to our desired behaviour, what we need to do is to pass the contents of s as separate arguments into makeContrasts. This is done with some sleight of hand:

do.call(makeContrasts, c(s, list(levels=levels)))

The somewhat convoluted c(...) term of the above expression just makes a list where the first entry is the first string of s, the second entry is the second string, and the last entry is the levels argument (which is missing from your original post; this argument is necessary for makeContrasts, so I presume you've set it to something sensible). The do.call function then passes each entry of the list as a separate argument into makeContrasts, which gets us what we want.

ADD COMMENT
3
Entering edit mode

If you have your contrasts in a character vector, you can also do the same thing as makeContrasts(contrasts=s, levels=levels).

ADD REPLY
0
Entering edit mode

Ah, that's much better. Obviously, it seems that I like to overcomplicate things.

ADD REPLY
0
Entering edit mode

yeah! This is what I wanted.  How cute! 

ADD REPLY

Login before adding your answer.

Traffic: 563 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