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:
observed (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Observed counts.expected (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Expected counts.std (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – Standard deviation of the observed counts. If None, assumed to be the square root of the expected counts.
- 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 assign(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:
k2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second data values.lam2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second model values.ratio (
float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Background ratio.seed (
int) – Random seed to use in simulation. The default is 42.minus (
bool) – Whether to calculate the PIT of the next small quantity given m1 and m2. The default is False.nsim (
int) – The number of simulations to generate. The default is 10000.
- 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:
k2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second data values.lam2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second model values.ratio (
float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Background ratio.random (
bool) – Whether to add random noise so that residuals are normally distributed.seed (
int) – Random seed to use in adding noise and simulation. The default is 42.nsim (
int) – The number of simulations to generate. The default is 10000.
- 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:
k (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The Poisson data value.lam (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The Poisson model value.v (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal data value.mu (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal model value.sigma (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal model sigma.ratio (
float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Background ratio.seed (
int) – Random seed to use in simulation. The default is 42.nsim (
int) – The number of simulations to generate. The default is 10000.
- 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:
k (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The Poisson data value.lam (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The Poisson model value.v (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal data value.mu (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal model value.sigma (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal model sigma.ratio (
float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Background ratio.seed (
int) – Random seed to use in simulation. The default is 42.nsim (
int) – The number of simulations to generate. The default is 10000.
- 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:
k2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second data value.lam2 (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first and second model value.sign (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – The sign of output residuals. The default is None.dof (
int|float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The degree of freedom of each data pair. The default is 2.
- 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:
k (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first data value.lam (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The first model value.v (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Data value.mu (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Model value.sigma (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Model sigma.sign (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – The sign of output residuals. The default is None.dof (
int|float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The degree of freedom of each data pair. The default is 2.
- 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