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

Plot Recipes

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

It just occurred to me that one feature from R that is missing from this package is the ability to get summary plots (https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/plot.lm), and I see no issues about it here.

This is totally doable without adding new dependencies via Extensions and RecipesBase/MakieCore. I'm tempted to make a small PR during the holidays.

Those would be mostly for standard OLS linear regression. Any other plots that would be nice to have?

irregular-rhomboid avatar Nov 30 '24 21:11 irregular-rhomboid

this sounds like a great idea!

ajinkya-k avatar Dec 02 '24 15:12 ajinkya-k

Alright, I've gotten started with the Plots recipes, and I'm running into some obstacles

Below is the current result from the following code snippet (code here).

using GLM
using StatsPlots
using RDatasets

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

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

plot(
    residualplot(l),
    qqplot(l),
    scalelocationplot(l),
    residualsleverageplot(l),
    layout = (2,2),
    size = (700,500)
)

plotlmJulia R equivalent: lmplotsR

The issues I'm currently facing are that I'm trying to reuse the qqplot recipe from StatsPlots, but wasn't able to find a way to dispatch it for LinearModel using Plots recipes. The only thing that worked was directly defining a method for qqplot.

Annotations also seem finnicky, so I'll probably raise an issue in the Plots repo.

Those technical details aside, how close do we want to stay to R's plots? R adds smoothed lines through the plots, which would require another dependency to implement in Julia, and it's not clear to whether that is worth it. I also haven't implemented the labelling of potential outliers, which seems more useful.

Anyway, Merry Christmas.

irregular-rhomboid avatar Dec 24 '24 23:12 irregular-rhomboid

Looks good!

ajinkya-k avatar Dec 24 '24 23:12 ajinkya-k

This would be great to have. I'd have a preference for Makie based recipes, though.

andreasnoack avatar Dec 25 '24 15:12 andreasnoack

I'd have a preference for Makie based recipes, though

Coming right up.

using GLM
using GLMakie
using RDatasets

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

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

begin
    fig = Figure()

    residualplot(fig[1,1], l)
    qqplot(fig[1,2], l)
    scalelocationplot(fig[2,1], l)
    residualsleverageplot(fig[2,2], l)
    fig
end

makie

Frustratingly, there is no clear way to specify axis labels and titles in Makie recipes. Right now, I'm using a hack that is quite brittle.

irregular-rhomboid avatar Dec 26 '24 23:12 irregular-rhomboid