depictr.binned_residual_plot#

depictr.binned_residual_plot(model, n_bins=None, title=None)#

Binned residual plot for a binomial GLM (Gelman & Hill, 2007).

Raw residuals from a logistic model are uninformative point by point, so the fitted probabilities are split into equal-count bins and the mean residual is plotted against the mean fitted value in each bin. The grey band is plus or minus two standard errors of the bin mean; under a well-fitting model about 95% of the points fall inside it. A run of points outside the band, or a clear trend in them, points to a missing predictor or the wrong functional form.

Parameters:
  • model (statsmodels results object) – A fitted binomial GLM (logistic regression).

  • n_bins (int, optional) – Number of bins. Defaults to the square root of the sample size, rounded, the rule of thumb in Gelman & Hill.

  • title (str, optional) – Plot title.

Return type:

plotnine.ggplot

References

Gelman, A., & Hill, J. (2007). Data analysis using regression and multilevel/hierarchical models. Cambridge University Press.