【问题标题】:How to get the spline formula in R?如何获得R中的样条公式?
【发布时间】:2018-08-28 06:19:11
【问题描述】:

以下代码将绘制点和样条曲线(通过样条函数获得):

x <- 1:7
y <- c(2,1,4,2,5,1,2)
# plot the points
plot(x, y)
# plot the spline
lines(spline(x, y, n = 100, method = "natural"), col = 2)

我需要的是由spline(x, y, n = 100, method = "natural") 获得的函数本身,因此我可以在给定任何x 的情况下获得y 的值。我该怎么做?

我尝试了下面的代码,但它不起作用

f <- spline(x, y, n = 100, method = "natural")
f(7)

【问题讨论】:

    标签: r


    【解决方案1】:

    使用?splinefun,参考?spline 帮助页面。

    f <- splinefun(x, y, method = "natural")
    f(1)
    #[1] 2
    f(2)
    #[1] 1
    f(3.5)
    #[1] 2.901923
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 2018-06-10
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多