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.
- 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.
- 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 Data value.
- lam
ndarray Model value.
- keep_signbool, optional
Whether to keep sign of the residuals as
sign(k - lam). The default is False.- randombool, optional
Whether to add random noise so that residuals are normally distributed.
- seed
int, optional Random seed to use in adding noise. The default is 42.
- k
- Returns:
ndarrayThe 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:
- k1, k2
ndarray The first and second data values.
- lam1, lam2
ndarray The first and second model values.
- ratio
floatorndarray Background ratio.
- seed
int, optional Random seed to use in simulation. The default is 42.
- minusbool, optional
Whether to calculate the PIT of the next small quantity given m1 and m2. The default is False.
- nsim
int, optional The number of simulations to generate. The default is 10000.
- k1, k2
- Returns:
- 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:
- k1, k2
ndarray The first and second data values.
- lam1, lam2
ndarray The first and second model values.
- ratio
floatorndarray Background ratio.
- randombool, optional
Whether to add random noise so that residuals are normally distributed.
- seed
int, optional Random seed to use in adding noise and simulation. The default is 42.
- nsim
int, optional The number of simulations to generate. The default is 10000.
- k1, k2
- Returns:
- 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 The Poisson data value.
- lam
ndarray The Poisson model value.
- v
ndarray The normal data value.
- mu
ndarray The normal model value.
- sigma
ndarray The normal model sigma.
- ratio
floatorndarray Background ratio.
- seed
int, optional Random seed to use in simulation. The default is 42.
- nsim
int, optional The number of simulations to generate. The default is 10000.
- k
- Returns:
- 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 The Poisson data value.
- lam
ndarray The Poisson model value.
- v
ndarray The normal data value.
- mu
ndarray The normal model value.
- sigma
ndarray The normal model sigma.
- ratio
floatorndarray Background ratio.
- seed
int, optional Random seed to use in simulation. The default is 42.
- nsim
int, optional The number of simulations to generate. The default is 10000.
- k
- Returns:
- 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.
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:
ndarrayThe 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:
ndarrayThe 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