2

I am new to time series in R and correct me if I made any mistake.

I have daily snapshots of the inventory of a product in a store. You can take it as the number of IPads in Bestbuy if that is helpful, and I go to Bestbuy and count all the Ipads in their warehouse :) and take a note.

And I can monitor how many IPads they have sold every day and also when did they replenish their inventory. My goal is trying to do some time series analysis. First find the trend and seasonality of their IPad sales and then build a burst detection model, so if one day the sales is too low or too high. I will get notified.

Some fake data:

library(zoo)
index <- seq(as.Date('2013-01-01'), as.Date('2013-01-31'), by="day")
data <- c(seq(5, 1), seq(15, 1), seq(10, 5), seq(10, 5))
z <- zoo(data, index)
plot(z)

enter image description here

(1) Is there a handy function to calculate the delta of two days next to each other to get their daily sales first? So negative means sold so many Ipads and positve means replenishment.

(2) When I was trying to find the trend using decompose, it told me:

> decompose(z)
Error in decompose(z) : time series has no or less than 2 periods

Then I realize I need to determine the seasonality where a week would be a good start. So I can do.

plot(decompose(ts(z[,1], frequency=7)))

I know somehow, I need to modify the period to make it work. But the seasonality is actually different depends on the products and I don't know how to handle that problem.

(3) General Comments are welcome about my idea. For example, the plot above basically show they sell 1 pad almost every day. Then I need to detect somehow, a few days they sold more than 10+ ipads which I will take as a burst. Is there any other R packages easy to use for burst detection in general? Thanks

Community
  • 1
  • 1
B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
  • For question 1) have a look at `diff()`. – EDi Oct 22 '13 at 22:42
  • Why are you trying to find a trend? Are you forecasting? We're drifting into stats advice, but I think it is good practice to decide on the seasonal period a priori, rather than "data snooping" until R allows you to make a decomposition. Indeed, it doesn't look like there's much seasonality in your data, but it could just be the small size of the window. – Hugh Oct 22 '13 at 22:55
  • @Hugh I am actually thinking about doing forecasting not at the product level, but instead work on the supplier level, say all the apple products, find the trend.. Sorry I did not mention the plan in the question. There should be a weekly seasonality since people got more time during the weekend to shop on "Bestbuy". The inventory will not look obvious but the sales will. – B.Mr.W. Oct 22 '13 at 23:02

1 Answers1

3

Take a look at diff() for the delta question, it also is a quick way to notice "bursts".

diff(z)
plot(diff(z))
Hugh
  • 15,521
  • 12
  • 57
  • 100
  • 1
    Thanks, that is exactly what I want for question1. set lag to be 1 and probably plot(-diff(z)) – B.Mr.W. Oct 22 '13 at 22:49