Search code examples
rstl-decomposition

Weekly periodicity by STL with hourly energy consumption: series is not periodic or has less than two periods


I have a timeseries with hourly gas consumptions of some buildings. I need to forecast them with ARIMA and R, but I'm not an expert of R.

I tried to see if there are periodicities during one week.

Data format

Source:

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")

Head:

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

Why isn't it periodic? Do I need to specify the frequency? (How in case?)


Solution

  • 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)
    

    enter image description here

    > 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