elisa.plot.residuals#

Residual calculation.

combine_residuals(r1: ndarray[tuple[Any, ...], dtype[_ScalarT]], r2: ndarray[tuple[Any, ...], dtype[_ScalarT]], dof: int | float | ndarray[tuple[Any, ...], dtype[_ScalarT]], sign: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#
pearson_residuals(observed: ndarray[tuple[Any, ...], dtype[_ScalarT]], expected: ndarray[tuple[Any, ...], dtype[_ScalarT]], std: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Calculate Pearson residuals.

Parameters:
Returns:

Pearson residuals.

pit_poisson(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]], minus: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Probability integral transform of poisson data fit.

Parameters:
Returns:

The probability integral transform values.

quantile_residuals_poisson(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]], keep_sign: bool = False, random: bool = True, seed: int = 42) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Normalized quantile residuals for fit of Poisson data.

Parameters:
  • k (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – Data value.

  • lam (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – Model value.

  • keep_sign (bool) – Whether to keep sign of the residuals as sign(k - lam). The default is False.

  • random (bool) – Whether to add random noise so that residuals are normally distributed.

  • seed (int) – Random seed to use in adding noise. The default is 42.

Returns:

The quantile residuals.

Notes

When random is True, the residuals are theoretically guaranteed to be normally distributed. If keep_sign is also True, then the normality of the residuals may not be preserved. The recommended use is only random or keep_sign being True.

References

[1]

doi:10.2307/1390802

[2]

doi:10.1371/journal.pone.0181790

[3]

doi:10.1111/j.1541-0420.2009.01191.x

[4]

doi:10.1186/s12874-020-01055-2

pit_poisson_poisson(k1: ndarray[tuple[Any, ...], dtype[_ScalarT]], k2: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam1: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam2: ndarray[tuple[Any, ...], dtype[_ScalarT]], ratio: float | ndarray[tuple[Any, ...], dtype[_ScalarT]], seed: int = 42, minus: bool = False, nsim: int = 10000) ndarray[tuple[Any, ...], dtype[_ScalarT]] | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Probability integral transform of two poisson data fit.

Parameters:
Returns:

The probability integral transform values.

quantile_residuals_poisson_poisson(k1: ndarray[tuple[Any, ...], dtype[_ScalarT]], k2: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam1: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam2: ndarray[tuple[Any, ...], dtype[_ScalarT]], ratio: float | ndarray[tuple[Any, ...], dtype[_ScalarT]], random: bool = True, seed: int = 42, nsim: int = 10000) tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Normalized quantile residuals for joint fit of two Poisson data.

Note

The calculation is based on Monte Carlo simulation. It is also possible to calculate the quantile residuals by inverting the Cornish-Fisher expansion. See the following link for more details:

Parameters:
Returns:

The quantile residuals, and flags to mark if the residuals are lower or upper limit.

pit_poisson_normal(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]], v: ndarray[tuple[Any, ...], dtype[_ScalarT]], mu: ndarray[tuple[Any, ...], dtype[_ScalarT]], sigma: ndarray[tuple[Any, ...], dtype[_ScalarT]], ratio: float | ndarray[tuple[Any, ...], dtype[_ScalarT]], seed: int = 42, nsim: int = 10000) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Probability integral transform of poisson and normal data fit.

Parameters:
Returns:

The probability integral transform values.

quantile_residuals_poisson_normal(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]], v: ndarray[tuple[Any, ...], dtype[_ScalarT]], mu: ndarray[tuple[Any, ...], dtype[_ScalarT]], sigma: ndarray[tuple[Any, ...], dtype[_ScalarT]], ratio: float | ndarray[tuple[Any, ...], dtype[_ScalarT]], seed: int = 42, nsim: int = 10000) tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Normalized quantile residuals for joint fit of Poisson and normal data.

Note

The calculation is based on Monte Carlo simulation. It is also possible to calculate the quantile residuals by inverting the Cornish-Fisher expansion. See the following link for more details:

Parameters:
Returns:

The quantile residuals, and flags to mark if the residuals are lower or upper limit.

deviance_residuals_poisson(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Deviance residuals for fit of Poisson data.

Parameters:
Returns:

The deviance residuals.

References

[1]

McCullagh P, Nelder JA. Generalized Linear Models, 2nd ed., pp. 39

[2]

Spiegelhalter et al., https://doi.org/10.1111/1467-9868.00353

deviance_residuals_poisson_poisson(k1: ndarray[tuple[Any, ...], dtype[_ScalarT]], k2: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam1: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam2: ndarray[tuple[Any, ...], dtype[_ScalarT]], sign: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None, dof: int | float | ndarray[tuple[Any, ...], dtype[_ScalarT]] = 2.0) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Deviance residuals [1] [2] for joint fit of two Poisson data.

Parameters:
Returns:

The deviance residuals.

References

[1]

McCullagh P, Nelder JA. Generalized Linear Models, 2nd ed., pp. 39

[2]

Spiegelhalter et al., https://doi.org/10.1111/1467-9868.00353

deviance_residuals_poisson_normal(k: ndarray[tuple[Any, ...], dtype[_ScalarT]], lam: ndarray[tuple[Any, ...], dtype[_ScalarT]], v: ndarray[tuple[Any, ...], dtype[_ScalarT]], mu: ndarray[tuple[Any, ...], dtype[_ScalarT]], sigma: ndarray[tuple[Any, ...], dtype[_ScalarT]], sign: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None, dof: int | float | ndarray[tuple[Any, ...], dtype[_ScalarT]] = 2.0) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Deviance residuals [1] [2] for joint fit of Poisson and normal data.

Parameters:
Returns:

The deviance residuals.

References

[1]

McCullagh P, Nelder JA. Generalized Linear Models, 2nd ed., pp. 39

[2]

Spiegelhalter et al., https://doi.org/10.1111/1467-9868.00353