RGLab / MAST

Tools and methods for analysis of single cell assay data in R
224 stars 57 forks source link

Unable to calculate log-ratio test for interaction term #141

Closed jmchan88 closed 3 years ago

jmchan88 commented 3 years ago

Dear MAST team,

I'm trying to perform DEG particularly for an interaction term, but I get an error saying the interaction term is not found. For example, my code does the following:

# Prepare for MAST
o_df = data_df #counts

time = as.numeric(factor(time, levels=c(0,2,4,8)))-1
treatment = as.numeric(factor(treatment, levels=c('DHT','ENZ')))-1
mutation = as.numeric(obs_df$batch != 'CRE_0_DHT')

wellKey <- rownames(o_df)
cdata <- data.frame(cbind(wellKey=wellKey)) #, condition=time))
fdata <- data.frame(primerid=colnames(o_df))

# SCa data
sca <- FromMatrix( t(o_df), cdata, fdata)
cdr2 <-colSums(assay(sca)>0)
colData(sca)$cngeneson <- scale(cdr2)
colData(sca)$time <- time
colData(sca)$treatment <- treatment
colData(sca)$mutation <- mutation

zlmCond <- zlm(~mutation + time + cngeneson + treatment + time:treatment + mutation:time, sca)

summaryDt <- summary(zlmCond, doLRT='mutation:time')$datatable

# Significance table
fcHurdle <- merge(summaryDt[contrast=='mutation:time' & component=='H',.(primerid, `Pr(>Chisq)`)],
                summaryDt[contrast=='mutation:time' & component=='logFC', .(primerid,coef, ci.hi, ci.lo)], by='primerid')

However, I get the following error when running

summaryDt <- summary(zlmCond, doLRT='mutation:time')$datatable

Combining coefficients and standard errors Calculating log-fold changes Calculating likelihood ratio tests Error in generateHypothesis(hypothesis, colnames(object@coefD)) : Term(s) 'mutation:time ,' not found. Terms available: (Intercept) , mutation , time , cngeneson , treatment , time:treatment ,

Any help would be greatly appreciated! Thank you so much!

Joe

jmchan88 commented 3 years ago

Oh, actually as an update, I just realized I didn't see this warning message after running

zlmCond <- zlm(~mutation + time + cngeneson + treatment + mutation:time + time:treatment, sca)

Warning message: In .nextMethod(object = object, value = value) : Coefficients mutation:time are never estimible and will be dropped.

This is clearly the reason, but I wonder what is producing this warning exactly?

amcdavid commented 3 years ago

Probably one of your variables (either time or treatment) is aliased with mutation. What does

ftable(xtabs(~mutation + time + treatment, colData(sca))) say?

On Sep 17, 2020, at 4:47 PM, jmchan88 notifications@github.com wrote:

Oh, actually as an update, I just realized I didn't see this warning message after running

zlmCond <- zlm(~mutation + time + cngeneson + treatment + mutation:time + time:treatment, sca) Warning message: In .nextMethod(object = object, value = value) : Coefficients mutation:time are never estimible and will be dropped.

This is clearly the reason, but I wonder what is producing this warning exactly?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RGLab/MAST/issues/141#issuecomment-694491268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALLAHTRPFHVFBIFSYVYKNTSGJYUXANCNFSM4RQ7DOWA.

jmchan88 commented 3 years ago

As in one of the variables is collinear with mutation? In my data, only timepoint 0 is wild-type, so I guess that must be the issue? This is what that command shows:

image

amcdavid commented 3 years ago

In a nutshell, yes, you can't study an interaction between time and mutation, because there is no variation of time within the wild-type samples. The interaction measures if the time slope is different in the WT than in the mutant. But you can't fit a slope with a single data point as you have in the WT.

A second question that arises is if you want time as continuous or as a factor? However, having time as a factor still doesn't permit resolving an interaction between it and mutation.

On Sep 17, 2020, at 4:58 PM, jmchan88 notifications@github.com wrote:

As in one of the variables is collinear with mutation? In my data, only timepoint 0 is wild-type, so I guess that must be the issue? This is what that command shows:

https://user-images.githubusercontent.com/12499408/93527465-ea0c0e00-f906-11ea-958e-a2bafec80342.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RGLab/MAST/issues/141#issuecomment-694496397, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALLAHWE6XGLOQVTJ4XBAWTSGJ2A3ANCNFSM4RQ7DOWA.

jmchan88 commented 3 years ago

Ah gotcha makes perfect sense! Thank you so much! For the prompt help! Will close now!