multiple_inference.bayes.nonparametric#
Nonparametric empirical Bayes.
References
@article{cai2021nonparametric,
title={Nonparametric empirical bayes estimation and testing for sparse and heteroscedastic signals},
author={Cai, Junhui and Han, Xu and Ritov, Ya'acov and Zhao, Linda},
journal={arXiv preprint arXiv:2106.08881},
year={2021}
}
Notes
This implementation is based on Cai et al.’s nonparametric Dirac delta prior. Future work should also implement their mixture model with a Laplace prior.
Classes
|
Bayesian model with a nonparametric Dirac delta prior. |
- class multiple_inference.bayes.nonparametric.Nonparametric(*args: Any, num_fit: str | int = 'auto', num_interp: int = 1000, lr: float = 0.001, betas: tuple[float, float] = (0.9, 0.99), eps: float = 1e-08, train_iter: int = 1000, **kwargs: Any)[source]#
Bayesian model with a nonparametric Dirac delta prior.
- Parameters:
num_fit (Union[str, int], optional) – Number of PMF parameters to fit in the Dirac-Delta prior. Defaults to “auto”.
num_interp (int, optional) – Number of PMF parameters to interpolate for the Dirac-Delta prior. Defaults to 1_000.
lr (float, optional) – Learning rate for the Adam optimizer. Defaults to 1e-3.
betas (tuple[float, float], optional) – Beta parameters for Adam. Defaults to (0.9, 0.99).
eps (float, optional) – Epsilon parameter for Adam. Defaults to 1e-8.
train_iter (int, optional) – Number of iterations of gradient descent. Defaults to 1_000.
Examples
import numpy as np from multiple_inference.bayes import Nonparametric np.random.seed(0) model = Nonparametric(np.arange(10), np.identity(10)) results = model.fit() print(results.summary())
Bayesian estimates ======================================= coef pvalue (1-sided) [0.025 0.975] --------------------------------------- x0 0.535 0.284 -1.068 2.295 x1 1.340 0.073 -0.433 3.136 x2 2.191 0.009 0.367 4.039 x3 3.073 0.001 1.229 4.982 x4 4.013 0.000 2.111 5.946 x5 4.987 0.000 3.054 6.889 x6 5.927 0.000 4.018 7.771 x7 6.809 0.000 4.961 8.633 x8 7.660 0.000 5.864 9.433 x9 8.465 0.000 6.705 10.068 =============== Dep. Variable y ---------------
- class multiple_inference.bayes.nonparametric.NonparametricResults(*args: Any, n_samples: int = 10000, **kwargs: Any)[source]#
- line_plot(column: int | str | None = None, alpha: float = 0.05, title: str | None = None, yname: str | None = None, ax=None)[source]#
Create a line plot of the prior, conventional, and posterior estimates.
- Parameters:
column (ColumnType, optional) – Selected parameter. Defaults to None.
alpha (float, optional) – Sets the plot width. 0 is as wide as possible, 1 is as narrow as possible. Defaults to .05.
title (str, optional) – Plot title. Defaults to None.
yname (str, optional) – Name of the dependent variable. Defaults to None.
ax (AxesSubplot, optional) – Axis to write on.
- Returns:
Plot.
- Return type:
AxesSubplot