Skip to content

compute the correct interval for locfit smoothers #4435

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

Merged
merged 1 commit into from
Apr 20, 2021
Merged

compute the correct interval for locfit smoothers #4435

merged 1 commit into from
Apr 20, 2021

Conversation

topepo
Copy link
Member

@topepo topepo commented Apr 19, 2021

Closes #3806

library(ggplot2)
library(locfit)
#> locfit 1.5-9.4    2020-03-24

mtcars$x <- mtcars$disp
grid <- seq(71, 470, length.out = 100)
fit <- locfit::locfit(mpg ~ x, data = mtcars)
prd <- predict(fit, data.frame(x = grid), se.fit = TRUE)
resid_df <- fit$dp["df2"]

lower_95 <- prd$fit + qt(0.025, df = resid_df) * prd$se.fit
upper_95 <- prd$fit + qt(0.975, df = resid_df) * prd$se.fit
res_95 <- ggplot2:::predictdf(fit, xseq = grid, se = TRUE, level = 0.95)
all.equal(res_95$ymin, lower_95, tolerance = 0.0001)
#> [1] TRUE
all.equal(res_95$ymax, upper_95, tolerance = 0.0001)
#> [1] TRUE

lower_99 <- prd$fit + qt(0.005, df = resid_df) * prd$se.fit
upper_99 <- prd$fit + qt(0.995, df = resid_df) * prd$se.fit
res_99 <- ggplot2:::predictdf(fit, xseq = grid, se = TRUE, level = 0.99)
all.equal(res_99$ymin, lower_99, tolerance = 0.0001)
#> [1] TRUE
all.equal(res_99$ymax, upper_99, tolerance = 0.0001)
#> [1] TRUE

Created on 2021-04-19 by the reprex package (v1.0.0.9000)

@thomasp85 thomasp85 merged commit 87e9b85 into tidyverse:master Apr 20, 2021
@thomasp85
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

locfit and geom_smooth
2 participants