multiple_inference.bayes.base#
Base classes for Bayesian analysis.
Classes
|
Mixin for Bayesian models. |
|
Results of Bayesian analysis. |
- class multiple_inference.bayes.base.BayesBase(mean: Sequence[float], cov: ndarray, X: ndarray | None = None, endog_names: str | None = None, exog_names: Sequence[str] | None = None, columns: Sequence[int] | Sequence[str] | Sequence[bool] | None = None, sort: bool = False, random_state: int = 0)[source]#
Mixin for Bayesian models.
Subclasses
multiple_inference.base.ModelBase.- get_joint_distribution(columns: Sequence[int] | Sequence[str] | Sequence[bool] | None = None)[source]#
Get the joint posterior distribution.
- Parameters:
columns (ColumnsType, optional) – Selected columns. Defaults to None.
- Returns:
Joint distribution.
- Return type:
rv_like
- get_joint_prior(columns: Sequence[int] | Sequence[str] | Sequence[bool] | None = None)[source]#
Get the joint prior distribution.
- Parameters:
columns (ColumnsType, optional) – Selected columns. Defaults to None.
- Returns:
Joint distribution.
- Return type:
rv_like
- class multiple_inference.bayes.base.BayesResults(*args: Any, n_samples: int = 10000, **kwargs: Any)[source]#
Results of Bayesian analysis.
Inherits from
multiple_inference.base.ResultsBase.- Parameters:
*args (Any) – Passed to
multiple_inference.base.ResultsBase.n_samples (int) – Number of samples used for approximations (ranking, likelihood and Wasserstein distance). Defaults to 10000.
**kwargs (Any) – Passed to
multiple_inference.base.ResultsBase.
- distributions#
Marginal posterior distributions.
- Type:
List[scipy.stats.norm]
- multivariate_distribution#
Joint posterior distribution.
- Type:
scipy.stats.multivariate_normal
- rank_df#
(n, n) dataframe of probabilities that column i has rank j.
- Type:
pd.DataFrame
- compute_best_params(n_best_params: int = 1, alpha: float = 0.05, superset: bool = True, criterion: str = 'fwer') Series[source]#
Compute the set of best (largest) parameters.
- Parameters:
n_best_params (int, optional) – Number of best parameters. Defaults to 1.
alpha (float, optional) – Significance level. If the criterion is “fwer”, alpha is the family-wise error rate. If the criterion is “fdr”, alpha is the false discovery rate. Defaults to 0.05.
superset (bool, optional) – Indicates that the returned set should be a superset of the truly best parameters. If False, the returned set should be a subset of the truly best parameters. Defaults to True.
criterion (str, optional) – “fwer” to control the family-wise error rate, “fdr” to control the false discovery rate. Defaults to “fwer”.
- Raises:
ValueError –
criterionmust be either “fwer” or “fdr”.- Returns:
Indicates which parameters are in the selected set.
- Return type:
pd.Series
- expected_wasserstein_distance(mean: Sequence[float] | None = None, cov: ndarray | None = None, **kwargs: Any) float[source]#
Compute the Wasserstein distance metric.
This method estimates the Wasserstein distance between the observed distribution (a joint normal characterized by
meanandcov) and the distribution you would expect to observe according to this model.- Parameters:
mean (Numeric1DArray, optional) – (# params,) array of sample conventionally estimated means. If None, use the model’s estimated means. Defaults to None.
cov (np.ndarray, optional) – (# params, # params) covaraince matrix for conventionally estimated means. If None, use the model’s estimated covariance matrix. Defaults to None.
**kwargs (Any) – Keyword arguments for
scipy.stats.wasserstein_distance.
- Returns:
Expected Wasserstein distance.
- Return type:
float
- likelihood(mean: Sequence[float] | None = None, cov: ndarray | None = None) float[source]#
- Parameters:
mean (Numeric1DArray, optional) – (# params,) array of sample conventionally estimated means. If None, use the model’s estimated means. Defaults to None.
cov (np.ndarray, optional) – (# params, # params) covaraince matrix for conventionally estimated means. If None, use the model’s estimated covariance matrix. Defaults to None.
- Returns:
Likelihood.
- Return type:
float
- 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
- rank_conf_int(alpha: float = 0.05, columns: Sequence[int] | Sequence[str] | Sequence[bool] | None = None, simultaneous: bool = True) ndarray[source]#
Compute rank confidence intervals.
- Parameters:
alpha (float, optional) – Significance level. Defaults to 0.05.
columns (ColumnsType, optional) – Selected columns. Defaults to None.
simultaneous (bool, optional) – Indicates that rank confidence intervals should have correct simultaneous coverage. If False, the rank confidence intervals will have correct marginal coverage. Defaults to True.
- Returns:
(# params, 2) array of rank confidence intervals.
- Return type:
np.ndarray
- rank_matrix_plot(title: str | None = None, **kwargs: Any)[source]#
Plot a heatmap of the rank matrix.
- Parameters:
title (str, optional) – Plot title. Defaults to None.
**kwargs (Any) – Passed to
sns.heatmap.
- Returns:
Heatmap.
- Return type:
AxesSubplot
- rank_point_plot(yname: str | None = None, xname: Sequence[str] | None = None, title: str | None = None, columns: Sequence[int] | Sequence[str] | Sequence[bool] | None = None, ax=None, **kwargs: Any)[source]#
Create a point plot.
- Parameters:
yname (str, optional) – Name of the endogenous variable. Defaults to None.
xname (Sequence[str], optional) – (# params,) sequence of parameter names. Defaults to None.
title (str, optional) – Plot title. Defaults to None.
columns (ColumnsType, optional) – Selected columns. Defaults to None.
ax (AxesSubplot, optional) – Axis to write on.
**kwargs (Any) – Passed to
ResultsBase.conf_int().
- Returns:
Plot.
- Return type:
AxesSubplot
- reconstruction_point_plot(yname: str | None = None, xname: Sequence[str] | None = None, title: str | None = None, alpha: float = 0.05, ax=None)[source]#
Create point plot of the reconstructed sample means.
Plots the distribution of sample means you would expect to see if this model were correct.
- Parameters:
yname (str, optional) – Name of the endogenous variable. Defaults to None.
xname (Sequence[str], optional) – Names of x-ticks. Defaults to None.
title (str, optional) – Plot title. Defaults to None.
alpha – (float, optional): Plot the 1-alpha CI. Defaults to 0.05.
ax – (AxesSubplot, optional): Axis to write on.
- Returns:
Plot.
- Return type:
plt.axes._subplots.AxesSubplot