1

Happy new year!

I have some data, x (temperatures) I want to bootstrap/simulate and use for prediction.

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

The problem is the data includes values from a leap year - 2016 and I want to use it for prediction in 2020 (the year many people want to forget). I have trouble creating a matrix with row number = 8784 from this data because the year length in original data is 365.25*24 and so I have to include February 29th manually. This is my code so far:

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)

Of course, one can use only 2016 for bootstrapping but then all the information in remaining years is lost. I hope there is some way to include all four years of data and create matrix with 8784 rows. Any help will be very appreciated.

I wish everyone a good year!

QuantumJazz
  • 139
  • 9
  • If `x` is your dataframe. What is `train` ? – Ronak Shah Jan 01 '21 at 12:24
  • Yes, it's a mistake; I edited the code; thank you! – QuantumJazz Jan 01 '21 at 14:56
  • Something seems to be off for me. 1) `x %>% filter(datetime <= "2016-02-28 23:30" | datetime >= "2016-03-01 00:00")` isn't doing what you think it is doing. You are comparing two character values but to remove data during those times you need to conver both to `POSIXct` type. 2) This line `tempsim <- sapply(tempsim, unlist)` doesn't make sense to me. Why are you doing that? 3) `tempsim <- matrix(tempsim, nrow = 8760)` gives a warning which is important. 4) What is the overall goal that you are trying to achieve? – Ronak Shah Jan 02 '21 at 03:44

0 Answers0