1

I am trying to decompose a daily time series, however this gives an

Error 'only univariate series are allowed'

When I have clearly converted the daily data in to time series using the ts function. How can I fix this?

I have tried solutions from other posts but none has worked for me. My data comprise of 669 observations, where the data spans from Jan 2017 to March 2019.

SCTB.LV.TS = ts(SCTB_TS[,-1], start = c(2017,6,01), frequency = 365)
SCTB.LV.TS

decomp <- stl(log(SCTB.LV.TS), s.window = 'Periodic')

Before converting the data frame to time series the data looks like below

Date    Count
6/1/2017    329
6/2/2017    284
6/3/2017    429
6/4/2017    454
6/5/2017    362
6/6/2017    334
6/7/2017    369
6/8/2017    319
6/9/2017    349
6/10/2017   373
6/11/2017   456
6/12/2017   344
Gun
  • 169
  • 3
  • 12
  • 1
    It's `"periodic"` not `"Periodic"`. This is working as expected: `stl(log(AirPassengers), s.window = "periodic")` – RLave May 30 '19 at 10:36
  • I don't think this is a version problem, but you should add your `sessionInfo()` here, with a reproducible complete example. Try first using classical available `ts` like `AirPassengers`. – RLave May 30 '19 at 10:39
  • 669 observations and daily sampling from Jan 2017 to March 2019 doesn't add up, there's about a four month deficit. Do you have missing data? No sampling during holidays? 669 observations sampled regularly at a frequency of 365 still span less than two periods. – AkselA May 30 '19 at 13:51
  • Does this answer your question? [Time series and stl in R: Error only univariate series are allowed](https://stackoverflow.com/questions/10492155/time-series-and-stl-in-r-error-only-univariate-series-are-allowed) – Santiago Capobianco Dec 17 '20 at 18:50

1 Answers1

0

I get no complaints of 'only univariate series are allowed', only about too few periods, which is understandable.

SCTB_TS <- read.table(text="
    Date      Count
    6/1/2017    329
    6/2/2017    284
    6/3/2017    429
    6/4/2017    454
    6/5/2017    362
    6/6/2017    334
    6/7/2017    369
    6/8/2017    319
    6/9/2017    349
    6/10/2017   373
    6/11/2017   456
    6/12/2017   344", header=TRUE)

# your argument to start didn't make sense, so I changed it
SCTB.LV.TS <- ts(SCTB_TS[,-1], start=c(2017, 1), frequency=365)
SCTB.LV.TS

decomp <- stl(log(SCTB.LV.TS), s.window="periodic")

Error in stl(log(SCTB.LV.TS), s.window = "periodic") : series is not periodic or has less than two periods

Which again is understandable. How can you do seasonal decomposition when you only have 12/365 period to work with?

AkselA
  • 8,153
  • 2
  • 21
  • 34
  • I have 669 observations, where the data spans from June 2018 to March 2019, which I have stated in the question. i have only shared a sample of the data. I tried changing the code for the ts function which you shared but still get the same error. – Gun May 30 '19 at 09:55
  • @Gun: June 2018 to March 2019 is still less than one period, let alone two. – AkselA May 30 '19 at 10:03
  • my mistake its from Jan 2017 to March 2019. I have typed this wrong in the question – Gun May 30 '19 at 10:09
  • @Gun: I think it's time for a reproducible example. Create some dummy data that produce the error, but can also be easily shared. – AkselA May 30 '19 at 10:13