[R] Periodicity of Weekly Zoo

Andrew Freedman andrewf at hotsprings.com.au
Tue Dec 4 02:30:35 CET 2012


Hi List,

I have weekly sales observations for several products drawn via ODBC.
Source data is available at
https://www.dropbox.com/s/78vxae5ic8tnutf/asr.csv.

This is retail sales data, so will contain seasonality and trend
information. I expect to see 52 or 53 observations per year, each
observation occuring on the same day of the week (Saturday). Ultimately
I'm looking to feed these series into forecasting models for demand
planning.

The data has issues with internal gaps, so while I've been able to
create a ts that appears to respect the frequency and period, I suspect
that a zoo is going to be a better data container. Unfortunately, I'm
not understanding the use of zoo() to describe frequency/period/deltat.

In the example below I use sales[,16] (aka $p) as it has several
periods (data between 2004 and 2012). I've tried using frequency=52, =7
and =1, but get the same result each time; every data point ends up in
cycle 1 and I don't have the periodicity needed to find seasonality.

> sales <- read.csv("asr.csv")
> library(zoo)

Attaching package: 'zoo'

The following object(s) are masked from 'package:base':

as.Date, as.Date.numeric

> sales.zoo <- zoo(subset(sales, select=c(2:length(sales))), order.by=
+ sales$date_end, frequency = 52)
> sales.zoo.i <- na.approx(sales.zoo) # interpolate internal NA values
> frequency(sales.zoo.i) # 52, which seems right
[1] 52
> cycle(sales.zoo.i[1:20,16]) # everything is in the same cycle...
2004-08-14 2004-08-21 2004-08-28 2004-09-04 2004-09-11 2004-09-18 
         1          1          1          1          1          1 
2004-09-25 2004-10-02 2004-10-09 2004-10-16 2004-10-23 2004-10-30 
         1          1          1          1          1          1 
2004-11-06 2004-11-13 2004-11-20 2004-11-27 2004-12-04 2004-12-11 
         1          1          1          1          1          1 
2004-12-18 2004-12-25 2005-01-01 2005-01-08 2005-01-15 2005-01-22 
         1          1          1          1          1          1 
2005-01-29 2005-02-05 2005-02-12 2005-02-19 2005-02-26 2005-03-05 
         1          1          1          1          1          1 
> 

Doubtless it's some facile error that will make me feel sheepish, but
I've been staring at this for a bit now and just getting nowhere. Any
pointers would be greatly appreciated.

Thanks,

Andrew



More information about the R-help mailing list