GLM.jl icon indicating copy to clipboard operation
GLM.jl copied to clipboard

Plot recipes

Open irregular-rhomboid opened this issue 1 year ago • 4 comments

This PR builds on the discussion in https://github.com/JuliaStats/GLM.jl/issues/581 and provides summary plots of LinearModels for both Plots and Makie. The plots are based on those from R's plot.lm function. While one new lightweight dependency is needed for RecipesBase, the plots are implemented as extensions for StatsPlots and Makie.

Implemented features

  • Plots are implemented for the equivalent of R's Residual plot, Scale-Location plot, Q-Q plot, Residuals-Leverage plot and Cook's distance vs leverage plot. The interface for these functions is the same for both plotting packages.
  • A summary plot function lmplot displaying the residual plot, Q-Q plot, scale-location plot and residuals-leverage plot. The configurability of this function is limited, however.
  • The computation of the leverages has been factored out into a function in lm.jl.
  • For the StatsPlots extension, default values for the axis labels and title are provided. This is not available for the Makie extension, except in lmplot.
  • Basic docstrings are provided for all the new functions

Not implemented

  • Documentation in docs/. This seems like a good thing to add.
  • Tests (it is not clear how to test for both plotting packages at the same time)
  • Loess smoothing. This is a feature in the R plots which would require another dependency to implement, for unclear benefits.
  • Outlier labelling (see last image)

Examples

StatsPlots:

using GLM
using StatsPlots
using RDatasets

data = dataset("datasets", "trees")

l = lm(@formula(Height ~ Girth + Volume), data)

lmplot(l; size = (700,500))

plotlmJulia

Makie:

using GLM
using CairoMakie
using RDatasets

data = dataset("datasets", "trees")

l = lm(@formula(Height ~ Girth + Volume), data)

lmplot(l; size = (700,500))

makie

R equivalent: lmplotsR

irregular-rhomboid avatar Jan 01 '25 23:01 irregular-rhomboid

Codecov Report

Attention: Patch coverage is 95.33679% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.05%. Comparing base (89493a4) to head (ae37c1c). Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
ext/StatsPlotsExt.jl 95.76% 5 Missing :warning:
src/GLM.jl 0.00% 4 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #582      +/-   ##
==========================================
+ Coverage   90.33%   91.05%   +0.72%     
==========================================
  Files           8       11       +3     
  Lines        1107     1297     +190     
==========================================
+ Hits         1000     1181     +181     
- Misses        107      116       +9     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 01 '25 23:01 codecov[bot]

@ajinkya-k @andreasnoack It would be good to get some feedback about this PR. I finally got time to write some tests, but ultimately plot recipes are hard to test beyond "does not catastrophically crash", and I'm not sure that I can test both the StatsPlots and Makie Recipes since they override the same function.

One option would be to put the recipes into separate mini packages rather than extensions.

csimal avatar Feb 26 '25 15:02 csimal

Thanks for preparing this. It's really a great feature. Would it be possible to handle testing of both plotting frameworks by splitting the testing of them into separate CI jobs? Regarding the testing of the images then @jkrumbiegel might be able to share some ideas.

andreasnoack avatar Feb 27 '25 20:02 andreasnoack

Would it be possible to handle testing of both plotting frameworks by splitting the testing of them into separate CI jobs?

Good idea. Ii'll look into it.

irregular-rhomboid avatar Feb 27 '25 21:02 irregular-rhomboid