【问题标题】:Weekly periodicity by STL with hourly energy consumption: series is not periodic or has less than two periodsSTL 的每周周期与每小时的能源消耗:系列不是周期性的或少于两个周期
【发布时间】:2014-07-18 16:20:10
【问题描述】:

我有一个时间序列,其中包含一些建筑物每小时的燃气消耗量。我需要用 ARIMA 和 R 预测它们,但我不是 R 专家。

我试图查看一周内是否有周期性。

Data format

来源:

fmt <- '%Y-%m-%d %H:%M:%S'
dat <- read.zoo('740.csv', format=fmt, header=TRUE, sep=',', tz='GMT', stringsAsFactors=FALSE)
#suppress warning of duplicates index in zoo
dat.ts <- dat2$gas..m3.[duplicated(index(dat2$gas..m3.)) == FALSE]
dat.ts <- as.xts(dat2.ts)
eats.week <- dat.ts["2008-02-04::2008-02-08"]
fit <- stl(eats.week, s.window="periodic")

头:

2008-02-04 00:00:00   53
2008-02-04 01:00:00   54
2008-02-04 02:00:00   55
2008-02-04 03:00:00   53
2008-02-04 04:00:00   54
2008-02-04 05:00:00   53
2008-02-04 06:00:00   66
2008-02-04 07:00:00   55
2008-02-04 08:00:00  112
2008-02-04 09:00:00   54
2008-02-04 10:00:00  113
2008-02-04 11:00:00   55
2008-02-04 12:00:00  108
2008-02-04 13:00:00   55
2008-02-04 14:00:00  101
2008-02-04 15:00:00   54
2008-02-04 16:00:00   99
2008-02-04 17:00:00   57
2008-02-04 18:00:00   92
2008-02-04 19:00:00   65

Plot

为什么不是周期性的? 我需要指定频率吗? (以防万一?)

【问题讨论】:

  • 请提供一些示例数据供其他人测试和调整您的代码,例如将dput(head(dat, 20)) 的输出添加到您的问题中。
  • 你的数据的时间跨度是多少?当您的时间序列小于一个完整观察窗口长度的两倍时,通常会发生这种情况。例如,如果我每周采样一次数据并使用frequency = 52 创建一个ts 对象,但只有100 周的数据,stl() 将产生错误。另外,是的,您应该在ts() 中明确指定频率/周期。
  • @nrussell 数据每小时采样一次。如您所见,在我分析一周的样本中

标签: r stl-decomposition


【解决方案1】:
d0 <- as.POSIXct(
  "2014-01-01 00:00:00",
  format="%Y-%m-%d %H:%M:%S",
  tz="America/New_York")
##
dWeek <- d0 + seq(
  from=0,
  to=(3600*167),
  by=3600
)
##
set.seed(1234)
x <- rnorm(168,50,5)
tsData <- data.frame(
  Time = dWeek,
  Value=x,
  stringsAsFactors=FALSE)
x.ts <- ts(
  tsData$Value,
  frequency=24,
  start=1)
##
fit <- stl(x.ts,s.window="periodic")
plot(fit)

> summary(fit)
 Call:
 stl(x = x.ts, s.window = "periodic")

 Time.series components:
    seasonal             trend            remainder         
 Min.   :-2.033404   Min.   :46.34685   Min.   :-12.191364  
 1st Qu.:-1.349070   1st Qu.:48.56738   1st Qu.: -2.674591  
 Median :-0.595044   Median :50.09490   Median : -0.273946  
 Mean   : 0.000000   Mean   :49.55673   Mean   :  0.017022  
 3rd Qu.: 0.974903   3rd Qu.:50.49250   3rd Qu.:  2.196548  
 Max.   : 5.250292   Max.   :51.51990   Max.   : 11.635797  
 IQR:
     STL.seasonal STL.trend STL.remainder data 
     2.324        1.925     4.871         6.401
   %  36.3         30.1      76.1         100.0

 Weights: all == 1

 Other components: List of 5
 $ win  : Named num [1:3] 1681 37 25
 $ deg  : Named int [1:3] 0 1 1
 $ jump : Named num [1:3] 169 4 3
 $ inner: int 2
 $ outer: int 0

【讨论】:

  • 请在你的答案中包含文字,而不仅仅是代码。
猜你喜欢
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 2022-12-06
  • 1970-01-01
  • 2016-01-19
  • 2015-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多