首页 > 解决方案 > 从闰年的数据中引导/模拟

问题描述

新年快乐!

我有一些数据,x(温度)我想引导/模拟并用于预测。

Length(x) = 35064, or 366*24 + 3*365*24. 

问题是数据包括闰年 - 2016 年的值,我想用它来预测 2020 年(许多人想忘记的那一年)。我无法从该数据中创建行号 = 8784 的矩阵,因为原始数据中的年份长度是365.25*24,所以我必须手动包含 2 月 29 日。到目前为止,这是我的代码:

library(tidyverse)
library(tsibble)
library(fable)
library(feasts)
library(lubridate)


# Remove February 29 from data
tmp <- x %>% 
filter(datetime <= "2016-02-28 23:30" | datetime >= "2016-03-01 00:00")
# Bootstrap data
tempsim <- forecast::bld.mbb.bootstrap(tmp$temp1, num = 100, block_size = 24)

# Create matrix and compute the means
tempsim <- sapply(tempsim, unlist)
tempsim <- matrix(tempsim, nrow = 8760)
tempsim <- rowMeans(tempsim)

# Add February 29th
a <- matrix(c(6.631599,6.733649,6.385545,6.385545,6.385545,6.385545,6.087687,6.139491,6.297789,6.841701,7.195739,7.441793,7.758391,7.600092,7.302234,7.910756,8.054760,7.948265,8.000068,7.297858,7.437417,6.139491,6.191294,6.647451))

# Add this to the simulated temperature:
temp <- append(tempsim, a, after = 1417)

当然,一个人只能使用 2016 年进行引导,但剩余年份的所有信息都会丢失。我希望有某种方法可以包含所有四年的数据并创建包含 8784 行的矩阵。任何帮助将不胜感激。

祝大家新年快乐!

标签: rforecastingleap-yearfable-r

解决方案


推荐阅读