Skip to content

hssm.plotting

Plotting functionalities for HSSM.

hssm.plotting.plot_posterior_predictive

plot_posterior_predictive(model, idata: InferenceData | None = None, data: DataFrame | None = None, plot_data: bool = True, n_samples: int | float | None = 20, row: str | None = None, col: str | None = None, col_wrap: int | None = None, groups: str | Iterable[str] | None = None, groups_order: Iterable[str] | dict[str, Iterable[str]] | None = None, bins: int | ndarray | str | None = 100, range: tuple[float, float] | None = None, step: bool = False, interval: tuple[float, float] | None = None, colors: str | list[str] | None = None, linestyles: str | list[str] = '-', linewidths: float | list[float] = 1.25, title: str | None = 'Posterior Predictive Distribution', xlabel: str | None = 'Response Time', ylabel: str | None = 'Density', grid_kwargs: dict | None = None, **kwargs) -> Axes | FacetGrid | list[FacetGrid]

Plot the posterior predictive distribution against the observed data.

Parameters:

  • model (HSSM) –

    A fitted HSSM model.

  • idata (optional, default: None ) –

    The InferenceData object with posterior samples. If not provided, will use the traces object stored inside the model. If posterior predictive samples are not present in this object, will generate posterior predictive samples using the this InferenceData object and the original data.

  • data (optional, default: None ) –

    The observed data.

    • If data is provided and the idata object does not contain a "posterior_predictive" group, will generate posterior predictive samples using covariate provided in this object. If the group does exist, it is assumed that the posterior predictive samples are generated with the covariates provided in this DataFrame.
    • If data is not provided (i.e., data=None), the behavior depends on whether "plot_data" is true or not. If plot_data=True, the plotting function will use the data stored in the model object and proceed as the case above. If plot_data=False, if posterior predictive samples are not present in the idata object, the plotting function will generate posterior predictive samples using the data stored in the model object. If posterior predictive samples exist in the idata object, these samples will be used for plotting, but a ValueError will be thrown if any of col or row is not None.
  • plot_data (optional, default: True ) –

    Whether to plot the observed data, by default True.

  • n_samples (optional, default: 20 ) –

    When idata is provided, the number or proportion of posterior predictive samples randomly drawn to be used from each chain for plotting. When idata is not provided, the number or proportion of posterior samples to be used to generate posterior predictive samples. The number or proportion are defined as follows:

    • When an integer >= 1, the number of samples to be extracted from the draw dimension.
    • When a float between 0 and 1, the proportion of samples to be extracted from the draw dimension.
    • When None, all samples are extracted.
  • row (optional, default: None ) –

    Variables that define subsets of the data, which will be drawn on the row dimension of the facets in the grid. When both row and col are None, one single plot will be produced, by default None.

  • col (optional, default: None ) –

    Variables that define subsets of the data, which will be drawn on the column dimension of the facets in the grid. When both row and col are None, one single plot will be produced, by default None.

  • col_wrap (optional, default: None ) –

    “Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a row facet., by default None.

  • groups (optional, default: None ) –

    Additional dimensions along which to plot different groups. This is useful when there are 3 or more dimensions of covariates to plot against, by default None.

  • groups_order (optional, default: None ) –

    The order to plot the groups, by default None, in which case the order is the order in which the groups appear in the data. Only when groups is a string, this can be an iterable of strings. Otherwise, this is a dictionary mapping the dimension name to the order of the groups in that dimension.

  • bins (optional, default: 100 ) –

    Specification of hist bins, by default 100. There are three options: - A string describing the binning strategy (passed to np.histogram_bin_edges). - A list-like defining the bin edges. - An integer defining the number of bins to be used.

  • range (optional, default: None ) –

    The lower and upper range of the bins. Lower and upper outliers are ignored. If not provided, range is simply the minimum and the maximum of the data, by default None.

  • step (optional, default: False ) –

    Whether to plot the distributions as a step function or a smooth density plot, by default False.

  • interval (optional, default: None ) –

    A two-tuple of floats indicating the interval of uncertainty, by default None. The values in the tuple should be between 0 and 1, indicating the percentiles used to compute the interval. For example, (0.05, 0.95) will compute the 90% interval. There should be at least 50 posterior predictive samples for each chain for this to work properly. A warning message will be displayed if there are fewer than 50 posterior samples. If None, no interval is plotted.

  • colors (optional, default: None ) –

    Colors to use for the different levels of the hue variable. When a str, the color of posterior predictives, in which case an error will be thrown if plot_data is True. When a length-2 iterable, indicates the colors in the order of posterior predictives and observed data. The values must be interpretable by matplotlib. When None, use default color palette, by default None.

  • linestyles (optional, default: '-' ) –

    Linestyles to use for the different levels of the hue variable. When a str, the linestyle of both distributions. When a length-2 iterable, indicates the linestyles in the order of posterior predictives and observed data. The values must be interpretable by matplotlib. When None, use solid lines, by default "-".

  • linewidths (optional, default: 1.25 ) –

    Linewidths to use for the different levels of the hue variable. When a float, the linewidth of both distributions. When a length-2 iterable, indicates the linewidths in the order of posterior predictives and observed data, by default 1.25.

  • title (optional, default: 'Posterior Predictive Distribution' ) –

    The title of the plot, by default "Posterior Predictive Distribution". Ignored when groups is provided.

  • xlabel (optional, default: 'Response Time' ) –

    The label for the x-axis, by default "Response Time".

  • ylabel (optional, default: 'Density' ) –

    The label for the y-axis, by default "Density".

  • grid_kwargs (optional, default: None ) –

    Additional keyword arguments are passed to the [sns.FacetGrid constructor] (https://seaborn.pydata.org/generated/seaborn.FacetGrid.html#seaborn.FacetGrid.init) when any of row or col is provided. When producing a single plot, these arguments are ignored.

  • kwargs (optional, default: {} ) –

    Additional keyword arguments passed to ax.plot() functions.

Returns:

  • Axes | FacetGrid

    The matplotlib axis or seaborn FacetGrid object containing the plot.

hssm.plotting.plot_quantile_probability

plot_quantile_probability(model, cond: str, data: DataFrame | None = None, idata: InferenceData | None = None, n_samples: int = 20, x: str = 'proportion', y: str = 'rt', hue: str = 'quantile', row: str | None = None, col: str | None = None, col_wrap: int | None = None, groups: str | Iterable[str] | None = None, groups_order: Iterable[str] | dict[str, Iterable[str]] | None = None, plot_posterior: bool = True, correct: str | None = None, q: int | Iterable[float] = 5, title: str | None = 'Quantile Probability Plot', xlabel: str | None = 'Proportion', ylabel: str | None = None, xticklabels: Iterable[str] | None = None, grid_kwargs: dict[str, Any] | None = None, data_kwargs: dict[str, Any] | None = None, pps_kwargs: dict[str, Any] | None = None, **kwargs) -> FacetGrid

Plot the quantile probabilities against the observed data.

Parameters:

  • model

    A model object that has a plot_quantile_probability method.

  • cond (str) –

    The column in data that indicates the conditions.

  • data (optional, default: None ) –

    A pandas DataFrame containing the observed data. If None, the data from idata.observed_data will be used.

  • idata (optional, default: None ) –

    An arviz InferenceData object. If None, the model's trace will be used. If the model's trace does not contain posterior predictive samples, and "plot_posterior" is True, will use the model and data to produce posterior predictive samples.

  • n_samples (optional, default: 20 ) –

    When idata is provided, the number or proportion of posterior predictive samples randomly drawn to be used from each chain for plotting. When idata is not provided, the number or proportion of posterior samples to be used to generate posterior predictive samples. The number or proportion are defined as follows:

    • When an integer >= 1, the number of samples to be extracted from the draw dimension.
    • When a float between 0 and 1, the proportion of samples to be extracted from the draw dimension.
    • When None, all samples are extracted.
  • x (optional, default: 'proportion' ) –

    The column in data that indicates the x-axis variable. By default, this is "proportion", which is the proportion of (in)correct responses in each group in cond.

  • y (optional, default: 'rt' ) –

    The column in data that indicates the y-axis variable. By default, this is "rt", which is the response time.

  • hue (optional, default: 'quantile' ) –

    The column in data that indicates the hue variable. By default, this is "quantile", which is the quantile of the response time.

  • row (optional, default: None ) –

    Variables that define subsets of the data, which will be drawn on the row dimension of the facets in the grid. When both row and col are None, one single plot will be produced, by default None.

  • col (optional, default: None ) –

    Variables that define subsets of the data, which will be drawn on the column dimension of the facets in the grid. When both row and col are None, one single plot will be produced, by default None.

  • col_wrap (optional, default: None ) –

    “Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a row facet., by default None.

  • groups (optional, default: None ) –

    Additional dimensions along which to plot different groups. This is useful when there are 3 or more dimensions of covariates to plot against, by default None.

  • groups_order (optional, default: None ) –

    The order to plot the groups, by default None, in which case the order is the order in which the groups appear in the data. Only when groups is a string, this can be an iterable of strings. Otherwise, this is a dictionary mapping the dimension name to the order of the groups in that dimension.

  • plot_posterior (optional, default: True ) –

    Whether to plot the posterior predictive distribution. By default True.

  • correct (optional, default: None ) –

    The column in data that indicates the correct responses. If None, response column from data indicates whether the response is correct or not. By default None.

  • q (optional, default: 5 ) –

    If an int, quantiles will be determined using np.linspace(0, 1, q) (0 and 1 will be excluded. If an iterable, will generate quantiles according to this iterable.

  • title (optional, default: 'Quantile Probability Plot' ) –

    The title of the plot, by default "Quantile Predictive Plot". Ignored when groups is provided.

  • xlabel (optional, default: 'Proportion' ) –

    The label for the x-axis, by default "Proportion".

  • ylabel (optional, default: None ) –

    The label for the y-axis, by default None.

  • xticklabels (optional, default: None ) –

    The labels for groups on the top x-axis, by default None, which will be inferred from the data.

  • grid_kwargs (optional, default: None ) –

    Keyword arguments passed to seaborn.FacetGrid.

  • data_kwargs (optional, default: None ) –

    Keyword arguments passed to seaborn.lineplot.

  • pps_kwargs (optional, default: None ) –

    Keyword arguments passed to seaborn.scatterplot.

  • kwargs (optional, default: {} ) –

    Keyword arguments passed to both seaborn.lineplot and seaborn.scatterplot.

Returns:

  • Axes | FacetGrid | list[FacetGrid]

    A seaborn FacetGrid object containing the plot.