theislab / diffxpy

Differential expression analysis for single-cell RNA-seq data.
https://diffxpy.rtfd.io
BSD 3-Clause "New" or "Revised" License
179 stars 23 forks source link

Extracting fitted mean and dispersion parameters #183

Closed ilibarra closed 3 years ago

ilibarra commented 3 years ago

Hi,

After running

test = de.model.test(...)

the object contains global mean estimates in test.mean.

I am interested in extracting mean and dispersion estimates by covariate. Perhaps those can be extracted by using test.model_estim (e.g. test.model_estim.a_var, test.model_estim.b_var, etc)

If there a model ~1 + condition1 + condition2 with nb noise, Is there a way to extract the mean/standard deviation estimates per gene, grouped by condition1/2 pairs?

Thank you,

davidsebfischer commented 3 years ago

In a standard setting, you would not model dispersion as function of condition and as ~1 insteady. In that case, variance still depends on condition because variance = f(modelled mean, dispersion). Note that this also depends on size factors! I find it most useful to look at cell-wise model output in these cases as this avoids errors. You can always group cells by condition and check whether they are the same. To look at cell-wise model fits, just use model.loc (mean prediction for cell and gene) or model.scale (dispersion for NB, prediction for cell and gene), see also https://github.com/theislab/batchglm/blob/master/batchglm/models/glm_nb/model.py. We don't have standard deviation implemented if I remeber correctly, I ll comment on that later, you can compute this easily from mean and dispersion per cell.

ilibarra commented 3 years ago

Hey @davidsebfischer ,

Thanks for the input! Now it's subsetting by dataset and cell-type before calling de.model.fit running using ~1 with nb noise.

I have a follow up but I'll point it to another repo now.

Cheers,