【发布时间】:2021-11-02 09:32:05
【问题描述】:
我确信下面的代码可以对某些数据进行季节性调整,但现在似乎并非如此。我可能做了一些愚蠢的事情,但不知道是什么。有人可以帮忙吗?
数据:https://github.com/Paul-Edward-C/cn-data
library(lubridate)
library(seasonal)
library(xts)
df <- read.csv(input_file,
sep = ",",
na.strings = "NA",
strip.white = TRUE,
stringsAsFactors = FALSE)
df$Date <- as.Date(df$Date, format="%Y-%m-%d")
start_month <- month(df$Date[1])
start_year <- year(df$Date[1])
df_ts <- ts(df[-1],
start=c(start_year,start_month),
freq=12)
m <- seas(cbind(df_ts),
xreg = genhol(cny, start = 0, end = 0, center = "calendar"),
regression.aictest = "td",
x11 = "",
regression.usertype = "holiday"
)
df_sa <- as.xts(final(m))
names(df_sa)<-c(colnames(df)[-1])
index(df_sa) <- as.Date(index(df_sa),
format="%b %Y")
write.csv(df_sa,output_file,
row.names = index(df_sa))
附加包:'lubridate'
以下对象被“package:base”屏蔽:
date, intersect, setdiff, union
加载所需的包:动物园
附加包:“动物园”
以下对象被“package:base”屏蔽:
as.Date, as.Date.numeric
> tail(df, n=20)
Date National.retail.sales..CNY..Monthly
240 2019-12-01 38,782.0
241 2020-01-01 26,060.1
242 2020-02-01 26,060.1
243 2020-03-01 26,441.2
244 2020-04-01 28,167.0
245 2020-05-01 31,979.6
246 2020-06-01 33,528.8
247 2020-07-01 32,189.0
248 2020-08-01 33,570.6
249 2020-09-01 35,294.7
250 2020-10-01 38,576.5
251 2020-11-01 39,514.2
252 2020-12-01 40,566.0
253 2021-01-01 34,868.4
254 2021-02-01 34,868.4
255 2021-03-01 35,484.1
256 2021-04-01 33,152.6
257 2021-05-01 35,945.1
258 2021-06-01 37,585.8
259 2021-07-01 34,925.1
National.retail.sales..retail.trade..CNY..Monthly National.retail.sales..catering..CNY..Monthly
240 33,855.8 4,930.0
241 23,967.6 2,097.5
242 23,967.6 2,097.5
243 24,613.9 1,832.2
244 25,869.5 2,306.6
245 28,971.0 3,014.5
246 30,272.5 3,263.6
247 28,918.1 3,282.1
248 29,951.3 3,619.3
249 31,579.5 3,715.1
250 34,204.1 4,372.3
251 34,534.4 4,979.7
252 35,616.3 4,949.7
253 31,325.7 3,542.7
254 31,325.7 3,542.7
255 31,973.5 3,510.5
256 29,775.8 3,376.9
257 32,128.8 3,816.3
258 33,663.0 3,922.8
259 31,173.7 3,751.4
])
> tail(df_ts, n=20)
National.retail.sales..CNY..Monthly National.retail.sales..retail.trade..CNY..Monthly
[240,] 165 117
[241,] 86 70
[242,] 86 70
[243,] 91 72
[244,] 96 82
[245,] 140 96
[246,] 149 103
[247,] 141 95
[248,] 150 102
[249,] 157 111
[250,] 164 118
[251,] 166 119
[252,] 196 120
[253,] 155 109
[254,] 155 109
[255,] 158 112
[256,] 146 101
[257,] 160 113
[258,] 162 116
[259,] 156 108
National.retail.sales..catering..CNY..Monthly
[240,] 117
[241,] 31
[242,] 31
[243,] 13
[244,] 43
[245,] 68
[246,] 80
[247,] 81
[248,] 96
[249,] 100
[250,] 114
[251,] 119
[252,] 118
[253,] 94
[254,] 94
[255,] 92
[256,] 86
[257,] 104
[258,] 109
[259,] 102
+ )
Error: X-13 run failed
Errors:
- Adding AO2021.Apr exceeds the number of regression effects allowed in the model
(80). Check the regression model, change the automatic outlier options, (e.g.
method to ADDONE, raise the critical value, or change types to identify AOs only),
or change the program limits (see Section 2.7 of the X-13ARIMA-SEATS Reference
Manual). Program error(s) halt execution for
/var/folders/jj/yp86y9gs6dd3fxn4j9mgyvk80000gn/T//Rtmptiuv5K/x131d895e37f09a/NationalretailsalesC.spc
- Adding AO2016.Nov exceeds the number of regression effects allowed in the model
(80). Check the regression model, change the automatic outlier options, (e.g.
method to ADDONE, raise the critical value, or change types to identify AOs only),
or change the program limits (see Section 2.7 of the X-13ARIMA-SEATS Reference
Manual). Program error(s) halt execution for
/var/folders/jj/yp86y9gs6dd3fxn4j9mgyvk80000gn/T//Rtmptiuv5K/x131d895e37f09a/Nationalretailsalesr.spc
- Adding A
【问题讨论】:
标签: r dataframe time-series