I am trying to catch changes in customers sales from week to week using R.
Historical.stats <- ddply(Historical, .(Company,Customer), summarise, mean= mean(Sales), lowerlimit = quantile(Sales,.05) ,higherlimit = quantile(Sales,.95), pval=t.test(Sales,data=Historical)$p.value)
My first attempt at doing this was to use the Quantile and then merge by Current Week data by the Company and Customer. I then would check if the sales this week were above or below the lower and higher quantiles.
dat <- merge(CurrentWeek, Historical.stats, by = c("Company","Customer")) dat$plot <- ifelse((dat$Sales< dat$lowerlimit | dat$Sales> dat$higherlimit) ,1 ,0)
After doing more research would it be best to use something like the Levine test, a standard t.test or some type of ANOVA method to do this type of anomaly detection. I understand I won't be able to take into account seasonality or holidays.
Example Data Company Customer Week Sales Company A Customer 1 05/07/2014 100 Company A Customer 2 05/07/2014 50 Company B Customer 1 05/07/2014 200 Company B Customer 2 05/07/2014 150 Company A Customer 1 05/14/2014 20 Company A Customer 2 05/14/2014 20 Company B Customer 1 05/14/2014 100 Company B Customer 2 05/14/2014 50