modelbased icon indicating copy to clipboard operation
modelbased copied to clipboard

Add `residualize_over_grid()`

Open strengejacke opened this issue 1 year ago • 3 comments

Fixes #129

strengejacke avatar Feb 09 '25 19:02 strengejacke

Could we instead make this a model_residuals() function that takes a newdata argument, which could be a grid from get_datagrid()?

bwiernik avatar Feb 09 '25 20:02 bwiernik

Sure, but do we need newdata? The grid is extracted / taken from the estimate_means() (or related) result.

strengejacke avatar Feb 09 '25 20:02 strengejacke

It can still be useful for power-users to have a way to pass the data no?

DominiqueMakowski avatar Mar 03 '25 08:03 DominiqueMakowski

@gemini-code-assist review

strengejacke avatar Aug 16 '25 17:08 strengejacke

This is the current state - though I'm not sure how to fix the last error, and I don't understand why ggplot complains about discrete values?

strengejacke avatar Aug 16 '25 18:08 strengejacke

library(modelbased)

model <- lm(Sepal.Length ~ Species * Sepal.Width, data = iris)

pr <- estimate_means(model, c("Sepal.Width", "Species"))
plot(pr, show_residuals = TRUE)



set.seed(1234)
x1 <- rnorm(200)
x2 <- rnorm(200)

# quadratic relationship
y <- 2 * x1 + x1^2 + 4 * x2 + rnorm(200)
d <- data.frame(x1, x2, y)

model <- lm(y ~ x1 + x2, data = d)

pr <- estimate_means(model, "x1")
plot(pr, show_residuals = TRUE)


model <- lm(y ~ x1 + x2, data = d)

pr <- estimate_means(model, c("x1", "x2=[sd]"))
plot(pr, show_residuals = TRUE)
#> Error in `scale_colour_continuous()`:
#> ! Discrete value supplied to a continuous scale.
#> ℹ Example values: -0.93, 0.07, and 1.08.

Created on 2025-08-16 with reprex v2.1.1

strengejacke avatar Aug 16 '25 18:08 strengejacke

It can still be useful for power-users to have a way to pass the data no?

I'm not quite sure at which point we should / can add newdata, since the data frame method already accepts a grid? Feel free to modify/add this function, where necessary.

strengejacke avatar Aug 16 '25 18:08 strengejacke

Is there a way to get a table of partial residuals as easily as it is done here for plotting?

marcora avatar Oct 14 '25 15:10 marcora

Yes, should be residualize_over_grid().

strengejacke avatar Oct 14 '25 17:10 strengejacke

Thanks!!!

On Tue, Oct 14, 2025 at 1:28 PM Daniel @.***> wrote:

strengejacke left a comment (easystats/modelbased#386) https://github.com/easystats/modelbased/pull/386#issuecomment-3402921614

Yes, should be residualize_over_grid().

— Reply to this email directly, view it on GitHub https://github.com/easystats/modelbased/pull/386#issuecomment-3402921614, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABRR5E5SGIV6W2SHJVHFD3XUXFDAVCNFSM6AAAAABWZE34GOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBSHEZDCNRRGQ . You are receiving this because you commented.Message ID: @.***>

marcora avatar Oct 14 '25 21:10 marcora