首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有缺失数据的时间序列的"loess“

带有缺失数据的时间序列的"loess“
EN

Stack Overflow用户
提问于 2012-12-04 08:28:25
回答 1查看 1.9K关注 0票数 5

我在使用带有缺失数据的时间序列的loessloess.smooth时遇到了问题。

这两个命令都不能处理这个玩具数据。

代码语言:javascript
复制
x <- as.Date(c(1, 2, 4, 5, 6), origin="2010-1-1")
y <- c(4, 8, 8, 28, 11)

plot(x, y, ylim=c(1,30))

lines(loess(y ~ x), col="red")
lines(loess.smooth(y=y, x=x), col="blue")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-22 19:19:40

我最终使用了以下代码:

代码语言:javascript
复制
# Data

x.1 <- as.Date(c(1, 2, 4, 5, 6), origin="2010-1-1")
x.2 <- c(1, 2, 4, 5, 6)
y <- c(4, 8, 8, 28, 11)


# x.2 - x is numeric variable

plot(x.2, y, ylim=c(1,30))

lines(loess(y ~ x.2, span=1.01), col="black", lwd=2, lty=2)  # neccessary to change span default to avoid warnings (span = 0.75)
lines(loess.smooth(x.2, y, span=1.01), col = "orange", , lwd=2)  # neccessary to change span default to avoid warnings (span = 2/3)
lines(smooth.spline(x.2,y), col="blue", lwd=2) 


# x.1 - x is date variable

plot(x.1, y, ylim=c(1,30))
# loess() cannot deal with date variables, thus convert it to 
lines(loess(y~as.numeric(x.1), span=1.01), col="red", lwd=2)  # neccessary to change span default to avoid warnings (span = 0.75) 
lines(loess.smooth(x.1, y, span=1.01), col = "orange", lwd=2)   # neccessary to change span default to avoid warnings (span = 2/3)
lines(smooth.spline(x.1,y), col="blue", lwd=2) 

问题是:(1) loess不能处理日期变量。(2)必须调整span参数(>1)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13694212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档