我正在尝试做一个简单的STL分解,但该函数指责这不是一个单变量系列。这对我来说没有意义。我在其他地方寻找答案,但没有人帮助我解决这个问题。你能救我吗?
Time series and stl in R: Error only univariate series are allowed
stl() decomposition won't accept univariate ts object?
pdtv <- ts(Prod, start=c(2006,9), freq=12)
pdtv
Jan Feb Mar Apr May Jun
2006
2007 2.957986 3.076377 3.032362 3.002684 2.998301 2.998301
2008 3.037797 3.058511 3.024955 3.003206 3.024000 3.024000
2009 2.465526 2.511370 2.460660 2.352522 2.337496 2.337496
2010 3.044934 3.092652 3.126031 3.126108 3.152243 3.152243
2011 3.066405 3.096732 3.259540 3.305672 3.364590 3.373816
2012 2.661912 2.450209 2.441621 2.447879 2.442005 2.442005
2013 3.274132 3.262601 3.305515 3.334852 3.338704 3.348022
2014 3.338500 2.932178 2.931838 2.929874 2.929874 2.950362
2015 3.253992 3.276724 3.266712 3.293284 3.293284 3.292635
2016 3.405285 3.305412 3.159213 3.140374 3.140374 3.116621
2017 3.462615 3.512385 3.592744 3.651052 3.719270 3.734618
2018 3.489051 3.494139 3.478237 3.469897
Jul Aug Sep Oct Nov Dec
2006 2.380385 2.380385 2.379928 2.379928
2007 2.963497 2.963497 2.963497 2.963497 2.963497 2.963497
2008 2.991359 2.991359 2.991359 2.991359 2.991359 2.991359
2009 2.340137 2.340137 2.340137 2.340137 2.340137 2.340137
2010 3.139452 3.139452 3.139452 3.139452 3.139452 3.139452
2011 3.373816 3.373816 3.373816 3.373816 3.373816 3.373816
2012 2.442005 2.452547 2.452547 2.452547 2.452547 2.452547
2013 3.348022 3.348022 3.348022 3.348022 3.348022 3.348022
2014 2.950362 2.950362 2.950362 2.950362 2.950362 2.950362
2015 3.292635 3.292635 3.292635 3.292635 3.292635 3.292635
2016 3.116621 3.116621 3.116621 3.116621 3.116621 3.087348
2017 3.735368 3.735368 3.759308 3.759308 3.759308 3.759308
2018
pdtv.stl = stl(pdtv)
Error in stl(pdtv) : only univariate series are allowed
答案 0 :(得分:0)
我自己遇到了这个问题,并尝试了一种解决方法。使用我的示例...
“ mtrain”是从2008年1月开始每月数据的时间序列对象。
str(mtrain)
Time-Series [1:105, 1] from 2008 to 2017: 344 263 234 222 287 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "GOOG.Open"
dimnames部分显然是导致stl()问题的部分
stl(mtrain)
Error in stl(mtrain) : only univariate series are allowed
解决方法:
mtrain = ts(as.numeric(mtrain), start=c(2008,1), frequency = 12)
str(mtrain)
Time-Series [1:105] from 2008 to 2017: 344 263 234 222 287 ...
stl.mtrain = stl(mtrain, s.window = "periodic")
head(stl.mtrain$time.series)
seasonal trend remainder
Jan 2008 18.4055569 297.7198 28.07094
Feb 2008 6.1883614 287.9555 -31.51698
Mar 2008 4.2087952 278.1911 -48.16837
Apr 2008 -0.7705219 267.8488 -44.65494
May 2008 -8.4452575 257.5065 38.22522
Jun 2008 -6.3193790 246.9789 48.70846
因此将mtrain转换回简单的数值向量,然后将time属性应用到它。昏暗的名称部分全部消失了,不会给stl()带来麻烦。
希望这会有所帮助!