-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request (and offer for help): optionally supply derivatives of transforms and inverses #322
Labels
feature
a feature request or enhancement
Comments
This would be great if you're interested in doing it 😄 |
Cool! Definitely interested in doing it 😊. I will take a stab in advance of the next iteration of ggdist, probably this summer. |
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Mar 18, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Mar 18, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Apr 3, 2022
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
mjskay
added a commit
to mjskay/scales
that referenced
this issue
Nov 3, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something that comes up regularly when visualizing analytical distributions on transformed scales is the need to correct the density function for the scale transformation (the so-called "Jacobian correction"), which requires the derivative of the inverse of the scale transformation.
For example, {ggdist} allows visualizing analytical distributions on transformed scales and automatically determines the Jacobian in order to do this correctly. E.g. a log-normal distribution plotted on a log scale should look like a normal distribution (without this correction it would not):
Created on 2021-12-28 by the reprex package (v2.0.1)
In {ggdist} we currently do this first by attempting to get the symbolic derivative by applying
stats::D()
to the scale transformation function definition (this usually fails) and then fall back to numerical derivatives. Naturally, the latter are not perfect and will fail in some cases, degrading the user experience.The ask / offer
It occurred to me that this can't be the only application where it would be helpful to know the derivative of the
$transform()
and/or$inverse()
of a scale transformation. So I would like to propose adding two additional fields to thetrans
objects in {scales}:transform_grad
(orgrad_transform
ord_transform
ortransform_deriv
or ...) giving the derivative oftransform
inverse_grad
(orgrad_inverse
ord_inverse
orinverse_deriv
or ...) giving the derivative ofinverse
These would be optional fields (may be
NULL
) that not all transformations are required to have. This would retain backwards compatibility, and would also work for my purposes (as I can continue falling back to symbolic and numerical differentiation as needed), but would (1) immediately improve the user experience with existing scale functions by supplying known derivatives in this package and (2) allow users to easily fix cases with manual scales when numerical methods fail by supplying the derivative manually.If there is interest in something like this, I am happy to supply a PR that creates these fields and supplies derivatives for the existing transformations in
R/trans-numeric.r
. Thanks!The text was updated successfully, but these errors were encountered: