【发布时间】:2019-07-19 03:43:27
【问题描述】:
在阅读了有关平滑样条的资料后,我想使用以下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))
思考过程是否正确?还是我错过了什么?
【问题讨论】: