为R中的一个要素变量生成平滑样条

在阅读了有关平滑样条线的资料后,我想使用以下R代码为特征变量x生成平滑样条线。

下面是我为获得特征变量x的平滑样条基所做的工作:

x = sort(rnorm(30)) # x is the feature variable 
px = stats::poly(x, degree = 3) # orthogonal polynomial basis

smooth_spline_basis1 = smooth.spline(x, px[,1],df=3, all.knots = TRUE)$y 
smooth_spline_basis2 = smooth.spline(x, px[,2],df=3, all.knots = TRUE)$y 
smooth_spline_basis3 = smooth.spline(x, px[,3],df=3, all.knots = TRUE)$y 

par(mfrow=c(2,2))
plot(px[,1],smooth_spline_basis1, main = "smoothing_spline_basis1 VS polynomial_spline_basis1")
plot(px[,2],smooth_spline_basis2, main = "smoothing_spline_basis2 VS polynomial_spline_basis2")
plot(px[,3],smooth_spline_basis3, main = "smoothing_spline_basis3 VS polynomial_spline_basis3")
par(mfrow=c(1,1))

思维过程是正确的吗?还是我错过了什么?

?

?

转载请注明出处:http://www.mingyanggongyi.com/article/20230526/2575795.html