Inverse link function #194
-
I have a gam model with this family
Is there any chance for appraise to plot linear predictor on x axis and taking into account the inverse link function? I saw an issue about the use of trans parameter but can't see how :-) Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Why would you want to do that within As If you want to plot the residuals vs the linear predictor on the response scale, you can do: library("mgcv")
library("gratia")
library("ggplot2")
dat <- data_sim("eg1", n = 400, dist = "normal", scale = 2, seed = 2)
mod <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat,
family = gaussian(link = "log")) # <-- wrong fmaily!
fv <- fitted_values(mod, scale = "response") |>
add_residuals(mod, type = "response")
fv |>
ggplot(aes(x = fitted, y = .residual)) +
geom_point() +
geom_smooth(method = "loess", col = "red") Or was there something more specific from |
Beta Was this translation helpful? Give feedback.
Why would you want to do that within
appraise()
? Thedraw()
methods for GAMs have argumentsconstant
andtrans
that would allow you to plot each individual smooth as if it were on the response scale, in your case you'd need to passconstant = coef(m)[1], trans = inv_link(m)
todraw(m, ....)
and even then this is only really OK with a single smooth...As
appraise()
is for diagnosing potential problems with the model, and one of the tools we have for that is to plot the linear predictor on the link scale, there isn't an option to plot on the response scale --- it would be extraordinarily difficult indeed to discern if the mean variance relationship say was the correct one. Also, we'd have t…