interpret.plot_slopes
interpret.plot_slopes(model, idata, wrt, conditional=None, average_by=None, eps=0.0001, slope='dydx', sample_new_groups=False, use_hdi=True, prob=None, transforms=None, legend=True, ax=None, fig_kwargs=None, subplot_kwargs=None)
Plot Conditional Adjusted Slopes
Parameters
model |
bambi.Model |
The model for which we want to plot the predictions. |
required |
idata |
arviz.InferenceData |
The InferenceData object that contains the samples from the posterior distribution of the model. |
required |
wrt |
(str, dict) |
The slope of the regression with respect to (wrt) this predictor will be computed. If ‘wrt’ is numeric, the derivative is computed, else if string or categorical, ‘comparisons’ is called to compute difference in group means. |
required |
conditional |
(str, dict, list) |
The covariates we would like to condition on. If dict, keys are the covariate names and values are the values to condition on. |
None |
average_by |
Union[str, list] |
The covariates we would like to average by. The passed covariate(s) will marginalize over the other covariates in the model. If True, it averages over all covariates in the model to obtain the average estimate. Defaults to None . |
None |
eps |
float |
To compute the slope, ‘wrt’ is evaluated at wrt +/- ‘eps’. The rate of change is then computed as the difference between the two values divided by ‘eps’. Defaults to 1e-4. |
0.0001 |
slope |
str |
The type of slope to compute. Defaults to ‘dydx’. ‘dydx’ represents a unit increase in ‘wrt’ is associated with an n-unit change in the response. ‘eyex’ represents a percentage increase in ‘wrt’ is associated with an n-percent change in the response. ‘eydx’ represents a unit increase in ‘wrt’ is associated with an n-percent change in the response. ‘dyex’ represents a percent change in ‘wrt’ is associated with a unit increase in the response. |
'dydx' |
sample_new_groups |
bool |
If the model contains group-level effects, and data is passed for unseen groups, whether to sample from the new groups. Defaults to False . |
False |
use_hdi |
bool |
Whether to compute the highest density interval (defaults to True) or the quantiles. |
True |
prob |
float |
The probability for the credibility intervals. Must be between 0 and 1. Defaults to 0.94. Changing the global variable az.rcParam["stats.hdi_prob"] affects this default. |
None |
transforms |
dict |
Transformations that are applied to each of the variables being plotted. The keys are the name of the variables, and the values are functions to be applied. Defaults to None . |
None |
legend |
bool |
Whether to automatically include a legend in the plot. Defaults to True . |
True |
ax |
matplotlib.axes._subplots.AxesSubplot |
A matplotlib axes object or a sequence of them. If None, this function instantiates a new axes object. Defaults to None . |
None |
fig_kwargs |
optional |
Keyword arguments passed to the matplotlib figure function as a dict. For example, fig_kwargs=dict(figsize=(11, 8)), sharey=True would make the figure 11 inches wide by 8 inches high and would share the y-axis values. |
None |
subplot_kwargs |
optional |
Keyword arguments used to determine the covariates used for the horizontal, group, and panel axes. For example, subplot_kwargs=dict(main="x", group="y", panel="z") would plot the horizontal axis as x , the color (hue) as y , and the panel axis as z . |
None |
Returns
(matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot) |
A tuple with the figure and the axes. |
Raises
ValueError |
If the number of wrt values is greater than 2 and average_by is None . If conditional and average_by are both None . If length of conditional is greater than 3 and average_by is None . If average_by is True . If slope is not one of (‘dydx’, ‘dyex’, ‘eyex’, ‘eydx’). If main covariate is not numeric or categoric. |