2次スプライン(3次スプラインではなく)をいくつかのデータに調整する方法はありますか?
私はこのデータを持っていますが、R でこれを行うための適切な関数が見つからないようです。
上記のコメントを少し拡張すると、B スプライン基底 ( function で実装splines::bs()
)を使用できdegree=2
、デフォルトではなく次のように設定できますdegree=3
。
library(splines)
## Some example data
set.seed(1)
x <- 1:10
y <- rnorm(10)
## Fit a couple of quadratic splines with different degrees of freedom
f1 <- lm(y ~ bs(x, degree = 2)) # Defaults to 2 - 1 = 1 degree of freedom
f9 <- lm(y ~ bs(x, degree = 2, df=9))
## Plot the splines
x0 <- seq(1, 10, by = 0.1)
plot(x, y, pch = 16)
lines(x0, predict(f1, data.frame(x = x0)), col = "blue")
lines(x0, predict(f9, data.frame(x = x0)), col = "red")