Prior Predictive¶
Interactive prior predictive check functionality for SciStanPy models.
This module provides interactive widgets and visualizations for conducting prior predictive checks on SciStanPy models. Prior predictive checks allow users to examine the behavior of their models before fitting to data by sampling from prior distributions and visualizing the resulting predictions.
The module centers around the PriorPredictiveCheck
class, which creates an interactive dashboard with sliders for model hyperparameters
and dropdown menus for selecting visualization options. This enables rapid
exploration of how different prior specifications affect model behavior.
The interface automatically adapts to the structure of the provided model, exposing only relevant parameters and visualization options based on the data dimensions and available coordinates.
Note
Instances of the PriorPredictiveCheck
class will not typically be accessed directly by users. Instead, they are accessed
via the Model.prior_predictive()
method.
- class scistanpy.plotting.prior_predictive.PriorPredictiveCheck(model: ssp_model.Model, copy_model: bool = False)[source]¶
Bases:
object
Interactive dashboard for conducting prior predictive checks.
This class creates a comprehensive interface for exploring model behavior through prior predictive sampling. It automatically generates appropriate widgets based on the model structure and provides multiple visualization modes for examining parameter distributions and relationships.
- Parameters:
model (ssp_model.Model) – SciStanPy model to analyze
copy_model (bool) – Whether to create a copy of the model to avoid modifying the original. Defaults to False, meaning updates to model parameters in the interactive plot will be reflected in the original model object.
- Variables:
model – The model being analyzed (copy or reference)
float_sliders – Dictionary of parameter adjustment sliders
target_dropdown – Widget for selecting which parameter to visualize
group_dim_dropdown – Widget for selecting grouping dimension
independent_var_dropdown – Widget for selecting independent variable
plot_type_dropdown – Widget for selecting visualization type
draw_seed_entry – Widget for setting random seed
draw_entry – Widget for setting number of experiments
update_model_button – Button to update model and redraw data
update_plot_button – Button to update plot without redrawing data
fig – HoloViews pane containing the current plot
- display() Row [source]¶
Create and return the complete interactive dashboard layout.
This method assembles all widgets and the plot display into a comprehensive dashboard layout suitable for display in Jupyter notebooks, Panel applications, or web interfaces.
- Returns:
Panel layout containing all interface elements
- Return type:
pn.Row
- The layout consists of:
Left panel: Model hyperparameter sliders and viewing options
Right panel: Interactive plot display that updates based on selections
- Example:
>>> check = PriorPredictiveCheck(model) >>> dashboard = check.display() # For Jupyter notebook >>> dashboard.servable() # For web deployment
- get_ecdf_kwargs() dict [source]¶
Generate keyword arguments for empirical CDF plots.
This method constructs the parameter dictionary needed for creating ECDF visualizations using hvplot, including cumulative probability calculations and appropriate hover interactions.
- Returns:
Dictionary of hvplot parameters for ECDF plotting
- Return type:
dict
- The returned dictionary includes:
‘kind’: Set to ‘line’ for step-like ECDF appearance
‘x’: Target parameter values
‘y’: ‘Cumulative Probability’ (computed during data processing)
‘by’: Independent label for grouping multiple ECDFs
‘datashade’: Disabled (False) for ECDF plots to maintain clarity
‘hover’: Set to ‘hline’ for horizontal hover lines
- get_kde_kwargs() dict [source]¶
Generate keyword arguments for kernel density estimate plots.
This method constructs the parameter dictionary needed for creating KDE visualizations using hvplot, including appropriate grouping and styling options.
- Returns:
Dictionary of hvplot parameters for KDE plotting
- Return type:
dict
- The returned dictionary includes:
‘kind’: Set to ‘kde’ for kernel density estimation
‘x’: None for KDE plots.
‘y’: Target parameter name for the y-axis
‘by’: Independent label for grouping (if applicable)
‘datashade’: Disabled (False) for KDE plots to maintain clarity
- get_relationship_kwargs() dict [source]¶
Generate keyword arguments for relationship plots.
This method constructs the parameter dictionary for creating relationship visualizations that show how parameters vary with respect to independent variables, using datashading for performance.
- Returns:
Dictionary of hvplot parameters for relationship plotting
- Return type:
dict
- The returned dictionary includes:
kind: Set to ‘line’ for continuous relationships
x: Independent variable name
y: Target parameter name
datashade: Enabled (True) for performance with large datasets
dynamic: Disabled (False), resulting in all data being embedded in output
aggregator: Set to ‘count’ for density-based coloring
cmap: ‘inferno’ colormap
- get_violin_kwargs() dict [source]¶
Generate arguments for violin plot creation.
This method constructs the arguments needed for creating violin plots using HoloViews, handling complex grouping scenarios and determining appropriate categorization based on data structure.
- Returns:
Dictionary containing plot arguments and dimensions
- Return type:
dict
- The method handles multiple grouping scenarios:
Single grouping by dimension index
Grouping by both dimension and independent variable
Automatic determination of primary vs. secondary grouping
- The returned dictionary includes:
‘args’: Tuple of (groups…, values) for HoloViews Violin constructor
‘kdims’: List of key dimension names
‘vdims’: Value dimension name (target parameter)
- set_group_dim_options(event: Event) None [source]¶
Update grouping dimension options based on selected target parameter.
This method configures the group dimension dropdown with appropriate options based on the dimensionality of the currently selected target parameter. It ensures that grouping options are only available for multi-dimensional parameters.
- Parameters:
event (Event) – Panel event containing the new target parameter selection
The method updates both the dropdown options and the descriptive text showing dimension sizes to help users understand the data structure. If the previously selected grouping dimension is no longer valid, it automatically resets to a sensible default.
- set_independent_var_options(event: Event) None [source]¶
Update independent variable options based on grouping dimension.
This method configures the independent variable dropdown with coordinates and data variables that are compatible with the selected grouping dimension. Only variables that vary along the grouping dimension are included as options.
- Parameters:
event (Event) – Panel event containing the new grouping dimension selection
The method scans both coordinates and data variables in the xarray Dataset to find suitable independent variables, ensuring compatibility with the selected visualization approach.
- set_plot_type_options(event: Event) None [source]¶
Update available plot types based on current dimension selections.
This method determines which visualization types are appropriate given the current selections for target parameter, grouping dimension, and independent variable. It enables more sophisticated plot types as more structure is specified.
- Parameters:
event (Event) – Panel event (used for callback compatibility is not used)
- Plot Type Logic:
ECDF and KDE: Always available for any parameter
Violin: Available when grouping dimension is selected
Relationship: Available when both grouping and independent variable are selected
The method automatically selects the most sophisticated available plot type as the default when options change.