Question: how to design the formular
0
gravatar for Emily20025322
4.4 years ago by
Emily200253220 wrote:

Hello,

I am trying to run multi factor comparison by DESeq2 and keep getting errors. My colData is a data frame, named condition, that is written like the table below.

                period          type

1                  A             3

2                  A             3

3                  B             1

4                  B             2

5                  C             1

6                  C             2

7                  D             1

8                  D             2

I want to compair any 2 periods considering type, specifically, A(3,3) vs B(1,2), B(1,2) vs C(1,2)...and C(1,2) vs D(1,2). And  I also want to compair samples belonging to type1 and samples belonging to type2 regardless of period. I am a beginner to use DESeq2, so may I trouble you to tell me how to give a correct design and the full commands to implement my goal. Thank you very much.

deseq2 • 1.0k views
ADD COMMENTlink modified 4.4 years ago • written 4.4 years ago by Emily200253220
Answer: how to design the formular
0
gravatar for Devon Ryan
4.4 years ago by
Devon Ryan200
Germany
Devon Ryan200 wrote:

Period A and type 3 are always the same, so you can't use ~period+type as a model and hope for it to work (I imagine that this is the error you're getting). There are a few steps in DESeq2 where you can manually input a model matrix, so you might have luck going that route. I'm not going to give you the exact commands, you should at least attempt to figure those out yourself, but the general idea is:

  1. m <- model.matrix(~period+type, colData(dds))
  2. Remove the column for type.3 (probably the last one). Your model matrix should now not be rank deficient.
  3. See post #29 here from Michael Love where he shows how to manually specify a model matrix in some of the DESeq2 function.
  4. You can then scroll down on to post #34 and #35 on the same page where examples are given for performing contrasts. Comparing type 1 vs. type 2 can be done simply with the coef= parameter in the results() function. See the DESeq2 vignette.

BTW, you'd probably get faster feedback if you'd put DESeq2 in the title of your post (the package authors are quite quick at answering questions...but they need to know they're there).

ADD COMMENTlink written 4.4 years ago by Devon Ryan200

Thanks Devon. 

hi Emily, Devon's right about the workaround. (in 4, use name instead of coef.) I am planning to build more support for custom design matrices this devel cycle, for the cases like these where handing a formula to model.matrix() is not sufficient.

Also, here is another post where I talk about the v1.6 workaround: 

C: DESeq2 paired and multi factor comparison

ADD REPLYlink modified 4.4 years ago • written 4.4 years ago by Michael Love23k
Answer: how to design the formular
0
gravatar for Emily20025322
4.4 years ago by
Emily200253220 wrote:

Thank you very much for your quick reply.

I find my design has something wrong. Now I have adjusted my design and it is like the table below:

sample   period    sex    individual

X2      stageP      F        1
X9      stageP      F        2
X16     stageP      F        3
X23     stageP      F        4
X3      stageP      M        1
X10     stageP      M        2
X17     stageP      M        3
X24     stageP      M        4
X4      stageG      F        1
X11     stageG      F        2
X18     stageG      F        3
X25     stageG      F        4
X5      stageG      M        1
X12     stageG      M        2
X19     stageG      M        3
X26     stageG      M        4
X6      stageM      F        1
X13     stageM      F        2
X20     stageM      F        3
X27     stageM      F        4
X7      stageM      M        1
X14     stageM      M        2
X21     stageM      M        3
X28     stageM      M        4

individuals with the same number in the same stages are paired.

I want to make comparisions below:

(1)results between different stages within one sex

(2)in the three stages respectively, results between the paired F and M

I'm sorry that I can not understand the post that you have given. Would you like to give me the formular=~?+?:?... that I should use to get my expected calculation? And may I have the content of the contrast that I would use to extract my results? Holding up too much of your time, I am so sorry and I really appreciate your selfless help.Thank you very much.

 

ADD COMMENTlink written 4.4 years ago by Emily200253220

hi Emily,

Just a note, it would have been better if you could have just posted the real table to start, as it seems the previous answers from Devon and I don't really apply to this table.

"individuals with the same number in the same stages are paired"

I'm confused how individuals with the same number in the same stages can be paired, because they have different sex. In what way do you mean they are paired?

"(2)in the three stages respectively, results between the paired F and M"

just to be clear, by this do you mean, the F vs M effect for each stage, taking into account the individual effect?

ADD REPLYlink written 4.4 years ago by Michael Love23k

You can use a design: ~ period + period:individual + period:sex 

which will allow you to test for period specific differences due to sex, while controlling for individual differences, where individuals with the same number in the same stages are paired.

You can then use the advice given in this post: DESeq2 paired multifactor test

that is, use 

dds = DESeq(dds, modelMatrixType="standard")

and then extract the stage G specific sex effect of M vs F (assuming F is the base level, see vignette)

results(dds, name="periodstageG.sexM")

Assuming F and G are the base levels, the stage P vs G difference for F would be:

results(dds, name="period_stageP_vs_stageG")

and the stage P vs G difference for M would be:

results(dds, contrast=list( c("period_stageP_vs_stageG","periodstageP.sexM") , "periodstageG.sexM" ))

The meaning of this last contrast is the sum of the P vs G effect for F (the base level) and the contrast of P vs G for M. Interactions work by adding extra effects to the base level effect.

ADD REPLYlink written 4.4 years ago by Michael Love23k
Answer: how to design the formular
0
gravatar for Emily20025322
4.4 years ago by
Emily200253220 wrote:

hi Michael,

I am sorry that I do not explain my idea correctly.I now describe them more carefully, hoping that you can get it exactly. May you spend some time read them again?

my purposes are:

(1)make paired t-test: I want to compute F vs M effect for each stage, taking into account the individual effect, because the F part and M part with the same individual numbers are come from one organism.

(2)make ANOVA: I want to compute stage effect for each sex, not taking into account the individual effect.

Thank you for your help in patience.  

                                                                            

ADD COMMENTlink written 4.4 years ago by Emily200253220
Answer: how to design the formular
0
gravatar for Emily20025322
4.4 years ago by
Emily200253220 wrote:

Hello, Michael

Thank you for your constant help and patience. I would try it again following your guide. And if there is anything else that I can not solve, sincerely hope your comment. Thank you very much.

ADD COMMENTlink written 4.4 years ago by Emily200253220
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: 152 users visited in the last hour