r-黄土预测返回NA [英] r - loess prediction returns NA

查看:112
本文介绍了r-黄土预测返回NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用loess进行样本外"预测.我得到原始样本之外的新x的NA值.我可以得到这些预测吗?

I am struggling with "out-of-sample" prediction using loess. I get NA values for new x that are outside the original sample. Can I get these predictions?

x <- c(24,36,48,60,84,120,180)
y <- c(3.94,4.03,4.29,4.30,4.63,4.86,5.02)
lo <- loess(y~x)
x.all <- seq(3,200,3)
predict(object = lo,newdata = x.all)

我需要模拟完整的收益率曲线,即不同期限的利率.

I need to model full yield curve, i.e. interest rates for different maturities.

推荐答案

predict.loess的手册页中:

当使用surface ="interpolate"(默认值)进行拟合时,predict.loess将不会进行推断-因此,包围原始数据的,与轴对齐的超立方体之外的点将缺少(NA)预测值和标准误差

如果将曲面参数更改为"direct",则可以外推值.

If you change the surface parameter to "direct" you can extrapolate values.

例如,这将起作用(附带说明:在绘制预测后,我的感觉是您应该稍微增加loess调用中的span参数):

For instance, this will work (on a side note: after plotting the prediction, my feeling is that you should increase the span parameter in the loess call a little bit):

lo <- loess(y~x, control=loess.control(surface="direct"))
predict(lo, newdata=x.all)

这篇关于r-黄土预测返回NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆