r - 为 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))
思维过程正确吗?还是我错过了什么?
解决方案
推荐阅读
- python - 如何按小时分组一周中的每一天?
- php - 新用户注册和购买会员时自动创建日历
- angular - Angular 如何在特定子页面上禁用 authGuard
- javascript - lodash groupby item.product_id 可能吗?
- entity-framework - 从用户机密中获取一个值以在 dotnet CLI 中使用
- html - 页脚与部分 CSS 重叠
- javascript - 在嵌入、iframe 或对象元素中填充数据
- android - 蓝牙连接后关闭套接字
- printing - 如何在 SAP Business One 中通过 SDK 打印或打印审阅报告
- asynchronous - 使用 System.Net.Mail 发送电子邮件 - 使用同步方法“Send”有效,但“SendAsync”无效