-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
visualisation_recipe with transformed responses #151
Comments
We should add a library(modelbased)
library(ggplot2)
m_inline_trans <- lm(log(dist) ~ speed, data = cars)
estimate_expectation(m_inline_trans, transformation = exp) |>
plot() Then internally, if out$Predicted <- transformation(out$Predicted)
out$CI_low <- transformation(out$CI_low)
out$CI_high <- transformation(out$CI_high)
out$Residuals <- transformation(out$Residuals)
trans_env <- as.environment(out)
trans_env$transformation <- transformation
jacob <- as.numeric(stats::numericDeriv(quote(transformation(Predicted)), "Predicted", rho = trans_env))
out$SE <- out$SE * jacob |
@strengejacke Can you write a |
Should this function only refer to the response variable, or also to a possible link-function? |
I think we already handle link/inverse link plotting fine. So we only need to handle in-formula transformations with such a function |
And the return value should be a function, right? Should that function do the same transformation, or the inverse-transformation? i.e. if Furthermore, I suggest using |
Get/find makes sense. How about get returns a list with $tranformation and $inverse slots |
I'm not that familiar with the code, maybe @DominiqueMakowski or @bwiernik can work in this? Would be great to have this resolved before an update is submitted to CRAN. |
I don't know how to "fix" that really, shouldn't all this transfo stuff be done at insight's level? |
We could probably do this: if (insight::find_transformation(model) != "identity") {
transformation <- insight::get_transformation(model)$inverse
out$Predicted <- transformation(out$Predicted)
out$CI_low <- transformation(out$CI_low)
out$CI_high <- transformation(out$CI_high)
out$Residuals <- transformation(out$Residuals)
trans_env <- as.environment(out)
trans_env$transformation <- transformation
jacob <- as.numeric(stats::numericDeriv(quote(transformation(Predicted)), "Predicted", rho = trans_env))
out$SE <- out$SE * jacob
} However, I'm not sure about the numericDeriv-stuff, looks like the code above can be directly used. |
And I'm, not sure where (i.e. to which function) to put this code? |
We should add the transformation argument to get_predicted() and add the call to find a model's inverse transformation inside .estimate_predicted(), which we pass to get_predicted() |
Ok, so |
Yep |
Currently, the default plot produced by
estimate_expected()
with a transformed response variable isn't correct. The data points are in the raw metric, but the predicted line is in the transformed metric.We should either:
transform
inestimate_expectation()
to allow back-transforming of predictionsCreated on 2021-10-08 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: