【发布时间】:2013-10-10 00:08:57
【问题描述】:
对不起,如果这个问题是微不足道的,但我试图弄清楚如何在 R 中绘制某种类型的自然三次样条 (NCS),但我完全没有想到。
在previous question 中,我学习了如何在 ggplot 中绘制由 ns() 命令生成的 NCS,但我感兴趣的是如何绘制一个稍微不同的 NCS,在 pspline 包中生成了 smooth.Pspline 命令.据我所知,这是唯一一个通过 CV 为给定数据集自动选择适当平滑惩罚的包。
理想情况下,我可以提供 smooth.Pspline 作为 ggplot2 中 stat_smooth 层的方法。我当前的代码是这样的:
plot <- ggplot(data_plot, aes(x=age, y=wOBA, color=playerID, group=playerID))
plot <- plot + stat_smooth(method = lm, formula = y~ns(x,4),se=FALSE)
我想用 smooth.Pspline 的功能替换“lm”公式。我做了一点谷歌搜索,发现 solution 与 Hadley 编写的非常相似的 B 样条函数 smooth.spline。但我无法将其完美地适应 smooth.Pspline。有人有这方面的经验吗?
非常感谢!
【问题讨论】: