Question: pass limma contrast matrix variable
0
gravatar for John linux-user
3.8 years ago by
United States
John linux-user210 wrote:

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   

limma contrast • 736 views
ADD COMMENTlink modified 3.8 years ago by Gordon Smyth38k • written 3.8 years ago by John linux-user210
Answer: pass limma contrast matrix variable
0
gravatar for Aaron Lun
3.8 years ago by
Aaron Lun24k
Cambridge, United Kingdom
Aaron Lun24k wrote:

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 COMMENTlink modified 3.8 years ago • written 3.8 years ago by Aaron Lun24k
3

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

ADD REPLYlink written 3.8 years ago by Ryan C. Thompson7.3k

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

ADD REPLYlink written 3.8 years ago by Aaron Lun24k

yeah! This is what I wanted.  How cute! 

ADD REPLYlink written 3.8 years ago by John linux-user210
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 216 users visited in the last hour