Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将arima生成的预测时间转换为标准日期时间_R_Time Series_Xts_Zoo_Arima - Fatal编程技术网

将arima生成的预测时间转换为标准日期时间

将arima生成的预测时间转换为标准日期时间,r,time-series,xts,zoo,arima,R,Time Series,Xts,Zoo,Arima,我使用ARIMA进行了预测: 预测结果如下: Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 15552001 18.80470 18.52527 19.08413 18.37735 19.23206 15555601 18.94718 18.63358 19.26078 18.46758 19.42679 15559201 18.86774 18.53623 19.19924 18.36074 1

我使用ARIMA进行了预测:

预测结果如下:

    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
15552001       18.80470 18.52527 19.08413 18.37735 19.23206
15555601       18.94718 18.63358 19.26078 18.46758 19.42679
15559201       18.86774 18.53623 19.19924 18.36074 19.37473
15562801       18.84979 18.46603 19.23355 18.26288 19.43670
15566401       18.91506 18.52182 19.30830 18.31366 19.51646
15570001       18.86569 18.46538 19.26599 18.25347 19.47791
15573601       18.86727 18.45311 19.28143 18.23387 19.50067
15577201       18.89555 18.47853 19.31258 18.25777 19.53334
15580801       18.86784 18.44715 19.28854 18.22444 19.51125
15584401       18.87419 18.44782 19.30056 18.22212 19.52627
15588001       18.88546 18.45692 19.31399 18.23007 19.54085
15591601       18.87097 18.43914 19.30280 18.21054 19.53139
15595201       18.87679 18.44097 19.31262 18.21025 19.54334
15598801       18.88064 18.44225 19.31904 18.21018 19.55111
15602401       18.87349 18.43165 19.31533 18.19775 19.54923
15606001       18.87755 18.43210 19.32300 18.19630 19.55880
15609601       18.87844 18.43003 19.32685 18.19265 19.56423
15613201       18.87510 18.42320 19.32701 18.18397 19.56623
15616801       18.87759 18.42224 19.33293 18.18120 19.57397
15620401       18.87748 18.41899 19.33597 18.17627 19.57868
15624001       18.87602 18.41411 19.33793 18.16959 19.58245
15627601       18.87742 18.41219 19.34264 18.16592 19.58891
我想把这一点转换成人类可读的日期时间。我该怎么做

我的初始数据帧的历元时间为行。名称如下:

         y
1484337600 19.22819
1484341200 19.28906
1484344800 19.28228
1484348400 19.21669
148435200019.32759
1484355600 19.21833
1484359200 19.20626
1484362800 19.28737
1484366400 19.20651
1484370000 19.18424

我使用以下方法转换了此初始数据集:

xts_dataframe <- xts(x = dataframe$y, order.by = as.POSIXct(as.numeric(row.names(dataframe)), origin="1970-01-01"))



fit <- auto.arima(ts_dataframe ,trace = TRUE,stepwise = FALSE)  #411 
  fc <- forecast(fit,h=24)
  fc <- as.POSIXct(as.numeric(fc$mean), origin = '1970-01-01')
  print(fc)
没有预测结果

问题2:如果我没有对预测结果中的点进行任何更改:

 fit <- auto.arima(ts_dataframe ,trace = TRUE,stepwise = FALSE)
    fc <- forecast(fit,h=24)
    print(fc)

fit我希望您的数据是这样的

> head(data)
       epoch        y
1 1484341200 19.28906
2 1484344800 19.28228
3 1484348400 19.21669
4 1484352000 19.32759
5 1484355600 19.21833
6 1484359200 19.20626

> data$epoch <- as.POSIXct(data$epoch, origin = '1970-01-01')

> head(data)
                epoch        y
1 2017-01-14 02:30:00 19.28906
2 2017-01-14 03:30:00 19.28228
3 2017-01-14 04:30:00 19.21669
4 2017-01-14 05:30:00 19.32759
5 2017-01-14 06:30:00 19.21833
6 2017-01-14 07:30:00 19.20626

> xts_dataframe <- xts(data$y, order.by = data$epoch)
> fit <- auto.arima(xts_dataframe ,trace = TRUE,stepwise = FALSE)
> fc <- forecast(fit,h=24)

> fc <- as.data.frame(fc)
> time1 <- as.data.frame(seq(tail(data$epoch,1)+60, length.out = nrow(fc), by = "30 min"))

> output <- as.data.frame(cbind(time1[,1],fc))
> print(output)
>头部(数据)
纪元y
1 1484341200 19.28906
2 1484344800 19.28228
3 1484348400 19.21669
4 1484352000 19.32759
5 1484355600 19.21833
6 1484359200 19.20626
>数据$epoch头(数据)
纪元y
1 2017-01-14 02:30:00 19.28906
2 2017-01-14 03:30:00 19.28228
3 2017-01-14 04:30:00 19.21669
4 2017-01-14 05:30:00 19.32759
5 2017-01-14 06:30:00 19.21833
6 2017-01-14 07:30:00 19.20626
>xts_数据帧适合fc时间1输出打印(输出)

您可以查看新的
sweep
软件包。下面是一个描述过程的示例。以下输入基于您的数据帧:

  • data
    是一个包含日期或日期时间的列和一列值的数据框
  • freq
    是您的频率,
    start
    是您对
    ts
    对象的开始
  • h
    是您对未来的预测期
以下是一般流程

library(forecast)
library(sweep)
library(timekit)

# Make ts with tk_ts()
data_ts <- tk_ts(data, freq = freq, start = start)

# auto.arima()
fit <- auto.arima(data_ts)

# Make forecast
fcast <- forecast(fit, h = h)

# Use sw_sweep with timekit_idx = TRUE
sw_sweep(fcast, timekit_idx = T)
库(预测)
图书馆(扫描)
图书馆(时间工具包)
#用tk_ts()制作ts

数据适合
输出,因此,我已经使用:fc as.POSIXct->as.POSIXct.default Execution haltedorigin尝试了您的代码。我得到的预测数据已经发布。你是要我申请ARIMA的初始数据集吗?谢谢你的回复。你能告诉我如何在数据中应用1小时或5分钟的频率吗?你能告诉我在这个tk_ts()方法中是否可以应用每小时频率吗?
ts
系统使用指定频率和开始时间的正则化时间序列。开始并不重要,除了漂亮的打印,但频率很重要。我会看看你们的数据,试着找出你们的基期。对于月度数据,您需要设置
freq=12
,因为它每年都重复。如果以1小时的频率收集数据,我会设置
freq=24
start=1
。如果间隔为5分钟,我会设置
freq=60/5
,因为每小时有12次观察。我发现tk_方法的其他变体可以用于频率,如每小时一分钟。我使用的是这样的东西:tk_xts_dataframe,但有一件事我想问的是,即使我使用的是final
library(forecast)
library(sweep)
library(timekit)

# Make ts with tk_ts()
data_ts <- tk_ts(data, freq = freq, start = start)

# auto.arima()
fit <- auto.arima(data_ts)

# Make forecast
fcast <- forecast(fit, h = h)

# Use sw_sweep with timekit_idx = TRUE
sw_sweep(fcast, timekit_idx = T)