b_surial
b_surial

Reputation: 572

Equivalent of span using geom_smooth() with "gam"

This is probably a very basic question but I haven't found an answer yet. Is there an equivalent to the span argument in the geom_smooth function when method = "gam"? I am not familiar with GAM's in general so I would appreciate any input on that. I want to add a more flexible (wigglier) smoother to data with n > 1'000 and method = "loess" takes a lot of time to calculate.

Upvotes: 6

Views: 5193

Answers (1)

Roland
Roland

Reputation: 132969

mgcv::gam by default optimizes the smoothness using penalized regression. You can switch that off and specify the smoothness manually with the k parameter:

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

You should probably study the documentation of package mgcv.

Upvotes: 10

Related Questions