pylimma.squeeze_var

pylimma.squeeze_var(var, df, covariate=None, span=None, robust=False, winsor_tail_p=(0.05, 0.1), legacy=None)[source]

Empirical Bayes posterior variances.

Squeeze sample variances towards a common prior using empirical Bayes. This is the core variance moderation step in eBayes.

Parameters:
  • var (array_like) – Sample variances.

  • df (array_like or float) – Residual degrees of freedom for each variance.

  • covariate (array_like, optional) – Covariate for mean-variance trend (e.g., average log-expression). When provided, the prior variance is allowed to vary as a smooth function of the covariate.

  • span (float, optional) – Span for lowess smoothing when fitting the mean-variance trend. Only used when legacy=False or when span is explicitly provided. If None, an appropriate span is chosen automatically.

  • robust (bool, default False) – Use robust estimation of hyperparameters.

  • winsor_tail_p (tuple of float, default (0.05, 0.1)) – Winsorization proportions for robust estimation.

  • legacy (bool, optional) – If True, use the original limma hyperparameter estimation method (fit_f_dist or fit_f_dist_robustly). If False, use the newer method (fit_f_dist_unequal_df1) which handles unequal df1 values better. If None (default), auto-detect: use legacy=True if all df are equal, legacy=False otherwise. Setting span explicitly forces legacy=False.

Returns:

var_postndarray

Posterior variances.

var_priorfloat or ndarray

Prior variance (s0^2).

df_priorfloat

Prior degrees of freedom (d0).

Return type:

dict

Notes

The posterior variance is a weighted average of the sample variance and prior variance:

var_post = (df * var + df_prior * var_prior) / (df + df_prior)

References

Smyth, G. K. (2004). Linear models and empirical Bayes methods for assessing differential expression in microarray experiments. Statistical Applications in Genetics and Molecular Biology, 3(1), Article 3.