lhe17 / nebula

GNU General Public License v2.0
26 stars 6 forks source link

Multilevel variables, multiple contrasts and logFC interpretation #29

Closed CDSchuster closed 11 months ago

CDSchuster commented 11 months ago

Hello!

I've been reading some of the other issues here but I still want to make sure I get it right. Sorry if my question is a bit obvious in advance or I'm already answering myself.

If I have a subject-level variable that has 3 levels: Control, Treatment1 and Treatment2, the summary of the nebula result returns me 3 logFCs: logFC_intercept, logFC_Treatment1 and logFC_Treatment2.

If I understand correctly, logFC_Treatment1 and logFC_Treatment2 are Treatment1/Control and Treatment2/Control, right?

But my doubt is actually how do I get a logFC between Treatment1 and Treatment2, or at least, how to get DEGs between both treatments. For the treatments vs control I suppose I can just use the logFC_treatment1 and logFC_treatment2, but to get the DEGs between the 2 treatments do I use the chi-square test between logFC_Treatment1 and logFC_Treatment2 as in the example in the vignette?

I suppose all this applies as well for the different p-values reported in the summary? (p_intercept, p_treatment1 and p_treatment2)

Thanks a lot in advance! And congratulations on this library, it's wonderful.

lhe17 commented 11 months ago

Dear CDSchuster,

Thank you for your question, and sorry for the late reply due to my sickness.

"If I understand correctly, logFC_Treatment1 and logFC_Treatment2 are Treatment1/Control and Treatment2/Control, right?" Yes, your understanding is correct.

''But my doubt is actually how do I get a logFC between Treatment1 and Treatment2, or at least, how to get DEGs between both treatments. For the treatments vs control I suppose I can just use the logFC_treatment1 and logFC_treatment2, but to get the DEGs between the 2 treatments do I use the chi-square test between logFC_Treatment1 and logFC_Treatment2 as in the example in the vignette?" There are multiple ways to do that. As you mentioned, one way is to test contrast as illustrated in the example in the vignette. The logFC between Treatment1 and Treatment2 will then be (logFC_treatment2 - logFC_treatment1). To get the p-value, you can follow the same chisq test given in the example. If this sounds complicated, a simpler way in your case is to set Treatment1 as the reference level before you run model.matrix. Assume that your data frame is called df and there is a column called tr, which has three levels, 'Control', 'Treatment1', and 'Treatment2'. You could run the following to set Treatment1 as the reference level. df$tr <- relevel(df$tr, ref = 'Treatment1') m = model.matrix(~tr,df) Now, the intercept term in the design matrix m corresponds to Treatment1. Then, logFC_treatment2 in the output will be Treatment2/Treatment1.

Best regards, Liang

On Wed, Jul 12, 2023 at 4:52 PM CDSchuster @.***> wrote:

Hello!

I've been reading some of the other issues here but I still want to make sure I get it right. Sorry if my question is a bit obvious in advance or I'm already answering myself.

If I have a subject-level variable that has 3 levels: Control, Treatment1 and Treatment2, the summary of the nebula result returns me 3 logFCs: logFC_intercept, logFC_Treatment1 and logFC_Treatment2.

If I understand correctly, logFC_Treatment1 and logFC_Treatment2 are Treatment1/Control and Treatment2/Control, right?

But my doubt is actually how do I get a logFC between Treatment1 and Treatment2, or at least, how to get DEGs between both treatments. For the treatments vs control I suppose I can just use the logFC_treatment1 and logFC_treatment2, but to get the DEGs between the 2 treatments do I use the chi-square test between logFC_Treatment1 and logFC_Treatment2 as in the example in the vignette?

I suppose all this applies as well for the different p-values reported in the summary? (p_intercept, p_treatment1 and p_treatment2)

Thanks a lot in advance! And congratulations on this library, it's wonderful.

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/29, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUVMCPMS4YOT35ZXPBDXP4FCJANCNFSM6AAAAAA2IAOM4Y . You are receiving this because you are subscribed to this thread.Message ID: @.***>

CDSchuster commented 11 months ago

Dear Liang,

Thanks a lot for the reply! I hope you're recovering well from your sickness.

One more question only.

"a simpler way in your case is to set Treatment1 as the reference level before you run model.matrix. Assume that your data frame is called df and there is a column called tr, which has three levels, 'Control', 'Treatment1', and 'Treatment2'." So I would be running nebula two times. the first time I would set the reference in "control" so that I can get the logFCs for control-treatment1 and control-treatment2, and then a second time setting the reference on treatment1 so that I can get the logFC for treatment1-treatment2.

Best regards,

Claudio Schuster

lhe17 commented 11 months ago

Dear Claudio,

"So I would be running nebula two times. the first time I would set the reference in "control" so that I can get the logFCs for control-treatment1 and control-treatment2, and then a second time setting the reference on treatment1 so that I can get the logFC for treatment1-treatment2." Yes, exactly.

Best regards, Liang

On Thu, Jul 27, 2023 at 10:35 AM CDSchuster @.***> wrote:

Dear Liang,

Thanks a lot for the reply! I hope you're recovering well from your sickness.

One more question only.

"a simpler way in your case is to set Treatment1 as the reference level before you run model.matrix. Assume that your data frame is called df and there is a column called tr, which has three levels, 'Control', 'Treatment1', and 'Treatment2'." So I would be running nebula two times. the first time I would set the reference in "control" so that I can get the logFCs for control-treatment1 and control-treatment2, and then a second time setting the reference on treatment1 so that I can get the logFC for treatment1-treatment2.

Best regards,

Claudio Schuster

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/29#issuecomment-1653751271, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUWD7LEQTOQMYITGWILXSJ4EPANCNFSM6AAAAAA2IAOM4Y . You are receiving this because you commented.Message ID: @.***>