0
votes

How can I decompose a time series of daily frequency in R? I have the number of visitors to a website each day over the course of a year. I want to show a graph of the weekly season.

my_data = read.csv("time series test.csv", header = TRUE)

my_zoo_ts = read.zoo("time series test.csv", sep = ",", format="%m/%d/%y")

stl(my_zoo_ts)
# Error in stl(coerced_ts) : 
#   series is not periodic or has less than two periods

I was hoping to use STL, but apparently STL can't be used with daily data (from another S.O. question).

Here is the head of my data.

head(my_data)
      V1  V2
1 1/1/14 123
2 1/2/14 128
3 1/3/14 129
4 1/4/14 130
5 1/5/14 137
6 1/6/14 141
2
It can be used for daily data. But with more than two years of data. Anyway, what do you want to decompose?user3710546
stl cannot be used with "Date" class data. The data must be regularly spaced and one period must have the duration of 1.G. Grothendieck
@Pascal - I want to decompose a time series where it's the number of unique visitors to a website each day over 1 year. The periods would be weeks (since people visit certain websites more on certain days of the week). Is there any other function I can use?Don P
@G.Grothendieck - thanks I can create a series with zoothat is just a single vector regularly spaced. But I can't figure out how to specify the period to be 1 week.Don P
I still don't understand. Do you want to aggregate daily to weekly data?user3710546

2 Answers

0
votes

You should either aggregate the week or aggregate over the day-of-the-week.

Then you can plot the aggregates.

If you need further details, can you explain what you want to see?

0
votes
z <- as.Date("2014-1-1") + 0:364
visits <- sample(seq(from = 50, to = 100, by = 1), size = 365, replace = TRUE)
z.day <- zoo(visits, z)
week <- as.numeric(format(time(z.day), "%W"))
z.week <- aggregate(z.day, week, sum)

Then plot z.week