使用 geom_smooth() 和 "gam" 的等效跨度

Equivalent of span using geom_smooth() with "gam"

这可能是一个非常基本的问题,但我还没有找到答案。当 method = "gam" 时,geom_smooth 函数中的 span 参数是否等效?我一般不熟悉 GAM,因此我将不胜感激。我想为 n > 1'000 和 method = "loess" 的数据添加更灵活(更灵活)的平滑器,需要大量时间来计算。

mgcv::gam 默认情况下使用惩罚回归优化平滑度。您可以关闭它并使用 k 参数手动指定平滑度:

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(method = "gam", 
              formula = y ~ s(x, bs = "cs", fx = TRUE, k = 20))

你应该研究一下 mgcv 包的文档。