Logo

General

  • Installation
  • Requirements
  • Contributing
  • References

API

  • PyDESeq2
    • pydeseq2.dds.DeseqDataSet
    • pydeseq2.ds.DeseqStats
    • pydeseq2.inference.Inference
    • pydeseq2.default_inference.DefaultInference
    • pydeseq2.utils
    • pydeseq2.grid_search
      • grid_fit_alpha()
      • grid_fit_beta()
      • grid_fit_shrink_beta()
      • vec_nb_nll()
    • pydeseq2.preprocessing

Tutorials

  • Getting Started
PyDESeq2
  • PyDESeq2
  • pydeseq2.grid_search

pydeseq2.grid_search

Functions

grid_fit_alpha(counts, design_matrix, mu, ...)

Find best dispersion parameter.

grid_fit_beta(counts, size_factors, ...[, ...])

Find best LFC parameter.

grid_fit_shrink_beta(counts, offset, ...[, ...])

Find best LFC parameter.

vec_nb_nll(counts, mu, alpha)

Return the negative log-likelihood of a negative binomial.

grid_fit_alpha(counts, design_matrix, mu, alpha_hat, min_disp, max_disp, prior_disp_var=None, cr_reg=True, prior_reg=False, grid_length=100)

Find best dispersion parameter.

Performs 1D grid search to maximize negative binomial log-likelihood.

Parameters:
  • counts (ndarray) – Raw counts for a given gene.

  • design_matrix (ndarray) – Design matrix.

  • mu (ndarray) – Mean estimation for the NB model.

  • alpha_hat (float) – Initial dispersion estimate.

  • min_disp (float) – Lower threshold for dispersion parameters.

  • max_disp (float) – Upper threshold for dispersion parameters.

  • prior_disp_var (float, optional) – Prior dispersion variance.

  • cr_reg (bool) – Whether to use Cox-Reid regularization. (default: True).

  • prior_reg (bool) – Whether to use prior log-residual regularization. (default: False).

  • grid_length (int) – Number of grid points. (default: 100).

Returns:

Logarithm of the fitted dispersion parameter.

Return type:

float

grid_fit_beta(counts, size_factors, design_matrix, disp, min_mu=0.5, grid_length=60, min_beta=-30, max_beta=30)

Find best LFC parameter.

Perform 2D grid search to maximize negative binomial GLM log-likelihood w.r.t. LFCs.

Parameters:
  • counts (ndarray) – Raw counts for a given gene.

  • size_factors (ndarray) – DESeq2 normalization factors.

  • design_matrix (ndarray) – Design matrix.

  • disp (float) – Gene-wise dispersion prior.

  • min_mu (float) – Lower threshold for dispersion parameters.

  • grid_length (int) – Number of grid points. (default: 100).

  • min_beta (float) – Lower-bound on LFC. (default: 30).

  • max_beta (float) – Upper-bound on LFC. (default: 30).

Returns:

Fitted LFC parameter.

Return type:

ndarray

grid_fit_shrink_beta(counts, offset, design_matrix, size, prior_no_shrink_scale, prior_scale, scale_cnst, grid_length=60, min_beta=-30, max_beta=30)

Find best LFC parameter.

Performs 2D grid search to maximize MAP negative binomial GLM log-likelihood w.r.t. LFCs, with apeGLM prior.

Parameters:
  • counts (ndarray) – Raw counts for a given gene.

  • offset (ndarray) – Natural logarithm of size factor.

  • design_matrix (ndarray) – Design matrix.

  • size (ndarray) – Size parameter of NB family (inverse of dispersion).

  • prior_no_shrink_scale (float) – Prior variance for the intercept.

  • prior_scale (float) – Prior variance for the LFC coefficient.

  • scale_cnst (float) – Scaling factor for the optimization.

  • grid_length (int) – Number of grid points. (default: 100).

  • min_beta (int) – Lower-bound on LFC. (default: 30).

  • max_beta (int) – Upper-bound on LFC. (default: 30).

Returns:

Fitted MAP LFC parameter.

Return type:

ndarray

vec_nb_nll(counts, mu, alpha)

Return the negative log-likelihood of a negative binomial.

Vectorized version.

Parameters:
  • counts (ndarray) – Observations.

  • mu (ndarray) – Mean of the distribution.

  • alpha (ndarray or float) – Dispersion of the distribution, s.t. the variance is \(\mu + \alpha \mu^2\).

Returns:

Negative log likelihood of the observations counts following \(NB(\mu, \alpha)\).

Return type:

ndarray

Previous Next

© Copyright 2026, OWKIN.

Built with Sphinx using a theme provided by Read the Docs.