Reputation: 1
I would like to know if there is a proper way to deal (decompose, model, etc.) with data restricted to one period of the year, like Summer-only data, or any such period, across years.
And I guessed the fable framework would be a good toolbox to incorporate, but I can't make it work.
I have daily data, and a defined period of the year, in this case of 65 days (a pollinic season).
When I try to use functions of the fable framework I get errors related to missing values.
My dataset has 65 daily data (e.g. from January-1 to March-5) per 12 years, no missing values within this range, and is already an indexed tsibble with:
For example with the STL (Seasonal and Trend decomposition using Loess) method.
My final objective is to use the components that STL isolates to test the effect of meterological predictors (daily data) with a model, and then produce forecasts for future pollinic seasons.
For example, I used this code:
dataset %>% model(STL(Metric)) %>% components() %>% autoplot()
Error in transmute():
ℹ In argument: cmp = map(.fit, components).
Caused by error in UseMethod():
! no applicable method for 'components' applied to an object of class "null_mdl"
Run rlang::last_trace() to see where the error occurred.
Warning message:
1 error encountered for STL(Metric)
[1] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using tsibble::fill_gaps() if required.
I tried using the "fill_gaps" function, but this is not my objective, since my data of interest is already complete (65 days per year). Making the "NAs" explicit, i.e. the 300 remaining days in each year, did not work.
Upvotes: 0
Views: 87
Reputation: 2459
There isn't currently a way to specify a time index with 65 days per year (I'm currently working on making this possible). You can however reindex with a numeric time index without gaps (similar is currently done for 'trading day' data in the textbook here: https://otexts.com/fpp3/simple-methods.html#example-googles-daily-closing-stock-price)
library(tsibble)
#> Registered S3 method overwritten by 'tsibble':
#> method from
#> as_tibble.grouped_df dplyr
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
library(fable)
#> Loading required package: fabletools
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(feasts)
Prepare some example data
vic_elec_summer <- tsibbledata::vic_elec |>
filter(lubridate::yday(Date) <= 65) |>
index_by(Date) |>
summarise(Demand = sum(Demand))
Notice the gaps in data since the time index follows a complete calendar
vic_elec_summer |>
autoplot(Demand)
Reindex the data to use a numeric time index (no calendar)
vic_elec_summer_seq <- vic_elec_summer |>
mutate(index_seq = seq_along(Date)) |>
as_tsibble(index = index_seq)
There are no gaps with this time index
vic_elec_summer_seq |>
autoplot(Demand)
Produce a model - note that seasonal periods must be specified explicitly since there is no awareness of calendrical seasons anymore
vic_elec_summer_seq |>
model(STL(Demand ~ season(period = 65))) |>
components() |>
autoplot()
Created on 2024-08-30 with reprex v2.1.0
Upvotes: 0