fix(smooth): Standardize x before Loess fit so degree-2 works on Date axes#774
Merged
Conversation
… axes `smooth` with the default `degree = 2` collapsed on `Date` x axes. AoG converts dates to a ~1e11 numeric scale, and a multi-day range still spans ~1e9 after recentering, so the degree-2 normal equations mix terms differing by ~1e18 and the local fit is ill-conditioned. Standardize x (center on the mean, scale by the standard deviation) before fitting instead of only recentering. For continuous data Loess.jl is effectively affine-invariant, so predictions are unchanged to machine precision; only heavily-tied inputs (few distinct x values) shift, by a fraction of a percent of the signal range.
Merged
jkrumbiegel
added a commit
that referenced
this pull request
Jun 25, 2026
Minor release. Highlights: - Analyses (`linear`, `smooth`, `density`, `histogram`, `expectation`, `filled_contours`) now fit in transformed space and back-transform when the aesthetic carries a `scale` function via `scales` (e.g. `scales(Y = (; scale = log10))`) [#773](#773). - `histogram` now accepts a `direction` (`:x` or `:y`) keyword for 1D histograms [#773](#773). - `smooth` with the default `degree = 2` no longer collapses on `Date` (and other large-magnitude) x axes [#774](#774). The transformed-space analyses feature warrants the minor (`0.12.13` → `0.13.0`) bump.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
smooth()with its defaultdegree = 2collapsed to a near-flat line onDateaxes. The reason is conditioning: AoG converts dates to a ~1e11 numeric scale, and even after recentering a multi-day range still spans ~1e9, so the degree-2 normal equations mix terms differing by ~1e18 and the local fit goes haywire.degree = 1was unaffected because it has nox²term.The fix standardizes x (center on the mean, then divide by the standard deviation) before fitting, instead of only recentering. For continuous data Loess is effectively invariant to this affine rescaling, so predictions are unchanged to machine precision; only heavily-tied inputs (very few distinct x values) shift, by a fraction of a percent of the signal range.
Before
After