Predictive Elicitation#
preliz.predictive#
- preliz.predictive.ppa(fmodel, draws=2000, references=0, boundaries=(-inf, inf), target=None, new_families=True, engine='preliz')[source]#
Prior predictive check assistant.
This is an experimental method under development, use with caution.
- Parameters:
model (PreliZ model)
draws (int) – Number of draws from the prior and prior predictive distribution
references (int, float, list, tuple or dictionary) – Value(s) used as reference points representing prior knowledge. For example expected values or values that are considered extreme. Use a dictionary for labeled references.
boundaries (tuple) – Hard boundaries (lower, upper). Posterior predictive samples with values outside these boundaries will be excluded from the analysis.
target (tuple or PreliZ distribtuion) – Target distribution. The first shown distributions will be selected to be as close as possible to target. Available options are, a PreliZ distribution or a 2-tuple with the first element representing the mean and the second the standard deviation.
new_families (bool) – If True, the method will return the best fitting distribution from a set of common distributions
engine (str) – Library used to define the model. Either preliz or bambi. Defaults to preliz
- preliz.predictive.ppe(model, target, engine='auto', new_families=None, random_state=0)[source]#
Prior Predictive Elicitation.
This method is experimental and under development. It does not offers guarantees of correctness. Use with caution and triple-check the results.
With the projective method we attempt to find a prior that induces a prior predictive distribution as close as possible to the target distribution
- Parameters:
model (a probabilistic model) – Currently it only works with PyMC model. More PPls coming soon.
target (a PreliZ distribution or list) – Instance of a PreliZ distribution or a list of tuples where each tuple contains a PreliZ distribution and a weight. This represents the prior predictive distribution previously elicited by the user, possibly using other PreliZ’s methods to obtain this distribution, such as maxent, roulette, quartile, etc. This should represent the domain-knowledge of the user and not any observed dataset.
engine (str) – Library used to define the model. Either “auto” (default), “pymc” or “bambi”. Ig “auto”, the library is automatically detected.
new_families ("auto", list or dict) – Defaults to None, the samples are fit to the original prior distribution. If “auto”, the method evaluates the fit to the original prior plus a set of predefined distributions. Use a list of PreliZ distribution to specify the alternative distributions you want to consider. Use a dict with variables names in
modelas keys and a list of PreliZ distributions as values. This allows to specify alternative distributions per variable.random_state ({None, int, numpy.random.Generator, numpy.random.RandomState}) – Defaults to 0. Ignored if method is “pathfinder”.
- Returns:
new_priors – A string representation of the new priors. The user can copy and paste it into the model’s code. Ideally, with none to minimal changes.
- Return type:
str
- preliz.predictive.predictive_explorer(fmodel, samples=50, kind_plot='ecdf', references=None, plot_func=None, engine='auto', group='prior_predictive', var_name=None, stats_kwargs=None)[source]#
Explore how changing parameters in the prior affects the prior predictive distribution.
Use this function to interactively explore how a prior predictive distribution changes when the priors are changed. It also allows you to visualize how one prior changes when another prior is changed, this can be useful for prior that are not set independently, but are dependent on each other.
- Parameters:
fmodel (callable) – A function with a PreliZ model, a PyMC model, or a Bambi model. See examples section below for details
samples (int, optional) – The number of samples to draw from the prior predictive distribution (default is 50).
kind_plot (str, optional) – The type of plot to display. Defaults to “kde”. Options are “hist” (histogram), “kde” (kernel density estimate), “ecdf” (empirical cumulative distribution function).
references (int, float, list, tuple or dictionary) – Value(s) used as reference points representing prior knowledge. For example expected values or values that are considered extreme. Use a dictionary for labeled references.
plot_func (function) – Custom matplotlib code. Defaults to None.
kind_plotandreferencesare ignored ifplot_funcis specified.engine (str, optional) – Library used to define the fmodel. Either preliz, pymc or bambi. Default is auto. The function will automatically select the appropriate library to use based on the fmodel provided.
group (str, optional) – Which group to use. Ignored if the model is defined in preliz. Defaults to “prior_predictive”. You can also pass “prior”.
var_name (str, optional) – The name of the variable to plot. Ignored if the model is defined in preliz. If “group=prior_predictive” it defaults to the first variable in observed_RVs. For “prior” it defaults to the last variable in free_RVs.
stats_kwargs (dict, optional) – Additional keyword arguments to pass to the statistics function. Defaults to an empty dictionary.