INNER CODE UNIT · Python
_fit_MoM_dispersions
scverse/PyDESeq2 · src/pydeseq2/dds.py:1099
def _fit_MoM_dispersions(self) -> None:
"""Rough method of moments initial dispersions fit.
Estimates are the max of "robust" and "method of moments" estimates.
"""
# Check that size_factors are available. If not, compute them.
if "normed_counts" not in self.layers:
self.fit_size_factors(fit_type=self.size_factors_fit_type)
normed_counts = self.layers["normed_counts"][:, self.non_zero_idx]
rde = self.inference.fit_rough_dispersions(
normed_counts,
self.obsm["design_matrix"].values,
)
mde = self.inference.fit_moments_dispersions(
normed_counts, self.obs["size_factors"].to_numpy()
)
alpha_hat = np.minimum(rde, mde)