Skip to content

Conversation

@icweaver
Copy link
Contributor

@icweaver icweaver commented Dec 7, 2025

Howdy, GLM.jl has this in the works. After some discussion on slack, it sounded like this would be a good thing to fold into AoG if it's ever merged. Will keep this as a draft for now.

Below are some brief usage examples on the following sample data:

julia> using AlgebraOfGraphics, CairoMakie, GLM

julia> colors = Makie.wong_colors()

julia> using Random

julia> Random.seed!(111)

julia> df = let
           x = 1:5
           y_err = randn(length(x))
           y = x .+ y_err
           y_unc = abs.(y_err)
           (; x, y, y_unc)
       end
julia> data(df) * mapping(:x, :y) * (
           (visual(Scatter) + mapping(:y_unc) * visual(Errorbars)) * visual(; label = "data") +
           mapping(; weights = :y_unc) * linear() * visual(; color = colors[1], label = "model")
       ) |> draw

Before

display

After

display

This uses fweights by default to match current behavior, but different weights can be passed via the new weightkinds keyword, along with an optional new weighttransform keyword to perform any needed transformations before passing to the GLM machinery:

julia> specs = data(df) * mapping(:x, :y) * (
           (visual(Scatter) + mapping(:y_unc) * visual(Errorbars)) * visual(; label = "data") +
           mapping(; weights = :y_unc) * (
               linear(; weightkind = :aweights, weighttransform = x -> inv.(x .^ 2)) * visual(; color = colors[1], label = "aweights") +
               linear(; weightkind = :fweights) * visual(; color = colors[2], label = "fweights") +
               linear(; weightkind = :pweights) * visual(; color = colors[3], label = "pweights")
           )
       ) |> draw
display

Still playing around with the design. Comments welcome!

Related

@icweaver icweaver changed the title Confidence interval bands + GLM.jl [Feauture] Confidence interval bands + errorbars Dec 7, 2025
@icweaver
Copy link
Contributor Author

Whoo, JuliaStats/GLM.jl#487 is in now! I've updated the PR here to match current functionality. Once the design looks ok to y'all, could I have some help with adding any additional docs + desired tests?

@icweaver icweaver marked this pull request as ready for review December 23, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant