Closed gavinsimpson closed 2 months ago
From #316 I noticed that with the example there
library(mgcv) library(gratia) # ---- Simulate data ---- set.seed(123) n <- 200 x1 <- runif(n, 0, 10) x2 <- runif(n, 0, 10) x3 <- runif(n, 0, 10) y <- sin(x1) + 0.5 * x2 + rnorm(n) # ---- Fit data ---- # Fit a GAM with 3 covariates model <- gam(y ~ s(x1) + s(x2) + s(x3), method = "REML")
that you can't do
ds <- data_slice(model, x1 = evenly(x1)) sm <- smooth_estimates(model, select = "s(x1)", data = ds) |> mutate(presids = partial_residuals(model, select = "s(x1)", data = ds)) |> pull(`s(x1)`)
because compute_partial_residuals is doing odd things and partial_residuals doesn't pass on the data.
compute_partial_residuals
partial_residuals
data
Fix compute_partial_residuals such that it does it for the model fitted data if data is NULL or for the data if not NULL
NULL
I'm an idiot - this is working just fine, you can't compute residuals for new data unless you already have the answer...
From #316 I noticed that with the example there
that you can't do
because
compute_partial_residuals
is doing odd things andpartial_residuals
doesn't pass on thedata
.Fix
compute_partial_residuals
such that it does it for the model fitted data ifdata
isNULL
or for thedata
if notNULL