Skip to content

penalized_negbin

Regularied negative-binomial marginal model.

PenalizedNegBin(formula, *, penalties=(), device=None)

:class:NegBin with penalty P added to the training loss

This is a regularized form of the NegBin marginal model. By default, this does not use Poisson IRLS during initialization, since regularized settings typically have high-dimensional covariates, which are unstable in an ordinary linear model. These initial Poisson IRLS steps can be added back by passing max_iter to fit.

Parameters:

Name Type Description Default
formula dict of str to str, or str
required
penalties sequence of CoefficientPenalty

See :mod:scdesigner.distributions.penalties.

()
device device or str
None

Examples:

>>> from scdesigner.distributions.penalties import CoefficientPenalty, QuadraticPenalty
>>> penalty = CoefficientPenalty("mean", ["x"], [1.0], QuadraticPenalty(lam=0.1))
>>> model = PenalizedNegBin({"mean": "~ x", "dispersion": "~ 1"}, penalties=[penalty])
>>> type(model).__name__
'NegBin'
Source code in scdesigner/src/scdesigner/distributions/penalized_negbin.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def PenalizedNegBin(
    formula: Union[Dict[str, str], str],
    *,
    penalties: Sequence[CoefficientPenalty] = (),
    device=None,
) -> NegBin:
    """:class:`NegBin` with penalty ``P`` added to the training loss

    This is a regularized form of the NegBin marginal model.  By default, this
    does not use Poisson IRLS during initialization, since regularized settings
    typically have high-dimensional covariates, which are unstable in an
    ordinary linear model. These initial Poisson IRLS steps can be added back by
    passing ``max_iter`` to ``fit``.

    Parameters
    ----------
    formula : dict of str to str, or str
    penalties : sequence of CoefficientPenalty
        See :mod:`scdesigner.distributions.penalties`.
    device : torch.device or str, optional

    Examples
    --------
    >>> from scdesigner.distributions.penalties import CoefficientPenalty, QuadraticPenalty
    >>> penalty = CoefficientPenalty("mean", ["x"], [1.0], QuadraticPenalty(lam=0.1))
    >>> model = PenalizedNegBin({"mean": "~ x", "dispersion": "~ 1"}, penalties=[penalty])
    >>> type(model).__name__
    'NegBin'
    """
    return NegBin(formula, penalties=penalties, device=device)