分解每小时时间序列

问题描述 投票:0回答:1

我有以下时间序列数据示例:

    structure(list(cycle_rounded = structure(c(1604534400, 1604538000, 
1604541600, 1604545200, 1604548800, 1604552400, 1604556000, 1604559600, 
1604563200, 1604566800, 1604570400, 1604574000, 1604577600, 1604581200, 
1604584800, 1604588400, 1604592000, 1604595600, 1604599200, 1604602800, 
1604606400, 1604610000, 1604613600, 1604617200, 1604620800, 1604624400, 
1604628000, 1604631600, 1604635200, 1604638800, 1604642400, 1604646000, 
1604649600, 1604653200, 1604656800, 1604660400, 1604664000, 1604667600, 
1604671200, 1604674800, 1604678400, 1604682000, 1604685600, 1604689200, 
1604692800, 1604696400, 1604700000, 1604703600, 1604707200, 1604710800, 
1604714400, 1604718000, 1604721600, 1604725200, 1604728800, 1604732400, 
1604736000, 1604739600, 1604743200, 1604746800, 1604750400, 1604754000, 
1604757600, 1604761200, 1604764800, 1604768400, 1604772000, 1604775600, 
1604779200, 1604782800, 1604786400, 1604790000, 1604793600, 1604797200, 
1604800800, 1604804400, 1604808000, 1604811600, 1604815200, 1604818800, 
1604822400, 1604826000, 1604829600, 1604833200, 1604836800, 1604840400, 
1604844000, 1604847600, 1604851200, 1604854800, 1604858400, 1604862000, 
1604865600, 1604869200, 1604872800, 1604876400, 1604880000, 1604883600, 
1604887200, 1604890800, 1604894400, 1604898000, 1604901600, 1604905200, 
1604908800, 1604912400, 1604916000, 1604919600, 1604923200, 1604926800, 
1604930400, 1604934000, 1604937600, 1604941200, 1604944800, 1604948400, 
1604952000, 1604955600, 1604959200, 1604962800), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), total_fito = c(2884L, 3691L, 3709L, 
2005L, 3437L, 4028L, 3693L, 4811L, 4798L, 4365L, 2258L, 3204L, 
1569L, 5859L, 9864L, 6974L, 4891L, 2812L, 5207L, 4720L, 4567L, 
4928L, 4740L, 2951L, 2449L, 1558L, 5556L, 5068L, 5348L, 6454L, 
6507L, 7755L, 7556L, 6986L, 5649L, 5525L, 4851L, 7967L, 7769L, 
8434L, 8486L, 6490L, 5836L, 4547L, 5794L, 5501L, 5983L, 5430L, 
4633L, 2556L, 5681L, 7791L, 12581L, 8521L, 9137L, 12713L, 9992L, 
9483L, 8455L, 5524L, 4509L, 11443L, 10365L, 10796L, 9621L, 9176L, 
7606L, 7209L, 11328L, 9312L, 9060L, 6303L, 6731L, 8548L, 9363L, 
8651L, 8211L, 16576L, 13381L, 13825L, 12442L, 10464L, 8967L, 
9723L, 7515L, 9832L, 10126L, 14077L, 12292L, 13396L, 11938L, 
11893L, 14420L, 14250L, 12894L, 14489L, 15005L, 14450L, 13027L, 
12085L, 12037L, 12824L, 12087L, 12027L, 12173L, 11920L, 3406L, 
8896L, 6535L, 8835L, 6559L, 9095L, 11347L, 10671L, 8389L, 12459L, 
6292L, 12862L, 9980L, 6321L)), row.names = c(NA, -120L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x59302a8ad540>)

我以不同的方式将其转换为时间序列对象,如下所示:

library(xts)
df_test <- xts(dados[c(97:216),]$total_fito, order.by = dados[c(97:216),]$cycle_rounded)

df_test <- ts(dados[c(97:216),]$total_fito,
              start = c(2020, 11, 05, 00),
              frequency = 24*4) # frequency is N time by N days

但是,与我使用的方式无关。当我使用 stl() 分解我的时间序列时:

plot(stl(df_test, s.window = "periodic"))

返回以下错误:

Error in h(simpleError(msg, call)) : 
  erro na avaliação do argumento 'x' na seleção do método para a função 'plot': 'series is not periodic or has less than two periods'

我该如何解决这个问题?

谢谢

r time-series xts decomposition stl-decomposition
1个回答
0
投票

您是否正在寻找这样的日常季节性?

library(tidyverse)

dados <- structure(list(cycle_rounded = structure(c(
  1604534400, 1604538000,
  1604541600, 1604545200, 1604548800, 1604552400, 1604556000, 1604559600,
  1604563200, 1604566800, 1604570400, 1604574000, 1604577600, 1604581200,
  1604584800, 1604588400, 1604592000, 1604595600, 1604599200, 1604602800,
  1604606400, 1604610000, 1604613600, 1604617200, 1604620800, 1604624400,
  1604628000, 1604631600, 1604635200, 1604638800, 1604642400, 1604646000,
  1604649600, 1604653200, 1604656800, 1604660400, 1604664000, 1604667600,
  1604671200, 1604674800, 1604678400, 1604682000, 1604685600, 1604689200,
  1604692800, 1604696400, 1604700000, 1604703600, 1604707200, 1604710800,
  1604714400, 1604718000, 1604721600, 1604725200, 1604728800, 1604732400,
  1604736000, 1604739600, 1604743200, 1604746800, 1604750400, 1604754000,
  1604757600, 1604761200, 1604764800, 1604768400, 1604772000, 1604775600,
  1604779200, 1604782800, 1604786400, 1604790000, 1604793600, 1604797200,
  1604800800, 1604804400, 1604808000, 1604811600, 1604815200, 1604818800,
  1604822400, 1604826000, 1604829600, 1604833200, 1604836800, 1604840400,
  1604844000, 1604847600, 1604851200, 1604854800, 1604858400, 1604862000,
  1604865600, 1604869200, 1604872800, 1604876400, 1604880000, 1604883600,
  1604887200, 1604890800, 1604894400, 1604898000, 1604901600, 1604905200,
  1604908800, 1604912400, 1604916000, 1604919600, 1604923200, 1604926800,
  1604930400, 1604934000, 1604937600, 1604941200, 1604944800, 1604948400,
  1604952000, 1604955600, 1604959200, 1604962800
), class = c(
  "POSIXct",
  "POSIXt"
), tzone = "UTC"), total_fito = c(
  2884L, 3691L, 3709L,
  2005L, 3437L, 4028L, 3693L, 4811L, 4798L, 4365L, 2258L, 3204L,
  1569L, 5859L, 9864L, 6974L, 4891L, 2812L, 5207L, 4720L, 4567L,
  4928L, 4740L, 2951L, 2449L, 1558L, 5556L, 5068L, 5348L, 6454L,
  6507L, 7755L, 7556L, 6986L, 5649L, 5525L, 4851L, 7967L, 7769L,
  8434L, 8486L, 6490L, 5836L, 4547L, 5794L, 5501L, 5983L, 5430L,
  4633L, 2556L, 5681L, 7791L, 12581L, 8521L, 9137L, 12713L, 9992L,
  9483L, 8455L, 5524L, 4509L, 11443L, 10365L, 10796L, 9621L, 9176L,
  7606L, 7209L, 11328L, 9312L, 9060L, 6303L, 6731L, 8548L, 9363L,
  8651L, 8211L, 16576L, 13381L, 13825L, 12442L, 10464L, 8967L,
  9723L, 7515L, 9832L, 10126L, 14077L, 12292L, 13396L, 11938L,
  11893L, 14420L, 14250L, 12894L, 14489L, 15005L, 14450L, 13027L,
  12085L, 12037L, 12824L, 12087L, 12027L, 12173L, 11920L, 3406L,
  8896L, 6535L, 8835L, 6559L, 9095L, 11347L, 10671L, 8389L, 12459L,
  6292L, 12862L, 9980L, 6321L
)), row.names = c(NA, -120L), class = c(
  "data.table",
  "data.frame"
))

ts <- ts(dados[, 2], start = 1, frequency = 24)

plot(stl(ts, s.window = "periodic"))

创建于 2024-04-27,使用 reprex v2.1.0

© www.soinside.com 2019 - 2024. All rights reserved.