小编A T*_*oll的帖子

如何识别geom_smooth()使用的函数

我想显示一个由创建的图,geom_smooth()但是对我来说,能够描述如何创建该图很重要。

我可以从文档中看到,当n> = 1000时,使用gam作为平滑函数,但是我看不到使用了多少个结或使用哪个函数生成了平滑。

例:

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 …
Run Code Online (Sandbox Code Playgroud)

r spline smoothing ggplot2 gam

6
推荐指数
1
解决办法
2208
查看次数

标签 统计

gam ×1

ggplot2 ×1

r ×1

smoothing ×1

spline ×1