How to determine the function used by geom_smooth ()

I would like to display the graph created geom_smooth(), but it is important for me to describe how the plot was created.

I see from the documentation, when n> = 1000, gam is used as a smoothing function, but I do not see how many nodes are used or which function generated the smoothing.

Example:

library(ggplot2)

set.seed(12345)
n <- 3000
x1 <- seq(0, 4*pi,, n)
x2 <- runif(n)
x3 <- rnorm(n)
lp <- 2*sin(2* x1)+3*x2 + 3*x3
p <- 1/(1+exp(-lp))
y <- ifelse(p > 0.5, 1, 0)

df <- data.frame(x1, x2, x3, y)

# default plot
ggplot(df, aes(x=x1, y=y)) +
  geom_smooth() 

# specify method='gam'
# linear
ggplot(df, aes(x=x1, y=y)) +
  geom_smooth(method='gam') 

# specify gam and splines
# Shows non-linearity, but different from default
ggplot(df, aes(x=x1, y=y)) +
  geom_smooth(method='gam',
              method.args = list(family = "binomial"),
              formula = y ~ splines::ns(x, 7)) 

If I want to use the default graph, is there a way to identify the function used to create the smoothing so that I can describe it in the analysis methods section?

variaitions of geom_smooth

+4
source share

Source: https://habr.com/ru/post/1662198/


All Articles