Multivariate - Time series data pattern changes New to R. In my example, my customers have restricted allocation of budget for Milk. I have more than 5 brands of milk in my store. Here my objective is how I know my customer is shifting from one brand to other? (Example: Customer is replacing Brand 1 with Brand 2 in my time series data). I would like to compute that shifting pattern every quarter and observe the trend quarter by quarter.

Sample Quarter Data:

Date    Milk-Brand1 Milk-Brand2 Milk-Brand3 Milk-Brand4 Milk-Brand5

1/1/2015    200 140 190 220 150
1/2/2015    204 138 195 226 144
1/3/2015    208 136 200 232 126
1/4/2015    212 134 205 238 108
2/2/2015    216 132 210 244 90
1/6/2015    220 130 215 250 72
1/7/2015    224 128 220 256 54
1/8/2015    228 126 225 262 36
1/9/2015    232 124 230 268 18
3/1/2015    236 122 235 274 0
3/2/2015    240 120 240 280 13
3/3/2015    244 118 245 286 33
3/4/2015    248 116 250 292 15
20/3/2015   252 114 255 298 33
20/3/2015   256 112 260 304 15


Do you suggest compute correlation between each 'brand of milk' and compare those correlations from one quarter to other quarter? Or Cross-correlation? Or others? I am open.

Thanks for your advice.

Here is the data via dput for anyone wanting it:

structure(list(Date = structure(c(1420070400, 1422748800, 1425168000, 
1427846400, 1422835200, 1433116800, 1435708800, 1438387200, 1441065600, 
1420243200, 1422921600, 1425340800, 1428019200, 1426809600, 1426809600
), tzone = "UTC", class = c("POSIXct", "POSIXt")), Milk.Brand1 = c(200L, 
204L, 208L, 212L, 216L, 220L, 224L, 228L, 232L, 236L, 240L, 244L, 
248L, 252L, 256L), Milk.Brand2 = c(140L, 138L, 136L, 134L, 132L, 
130L, 128L, 126L, 124L, 122L, 120L, 118L, 116L, 114L, 112L), 
    Milk.Brand3 = c(190L, 195L, 200L, 205L, 210L, 215L, 220L, 
    225L, 230L, 235L, 240L, 245L, 250L, 255L, 260L), Milk.Brand4 = c(220L, 
    226L, 232L, 238L, 244L, 250L, 256L, 262L, 268L, 274L, 280L, 
    286L, 292L, 298L, 304L), Milk.Brand5 = c(150L, 144L, 126L, 
    108L, 90L, 72L, 54L, 36L, 18L, 0L, 13L, 33L, 15L, 33L, 15L
    )), .Names = c("Date", "Milk.Brand1", "Milk.Brand2", "Milk.Brand3", 
"Milk.Brand4", "Milk.Brand5"), row.names = c(NA, -15L), class = "data.frame")
One starting approach is doing the cross-correlation as you've said. The correlation will fail to capture the time shifted behavior. But you should calculate it for every pair of Milk/Drug you have.

The ccf() function in R does it for you.

If you're not successful i suggest you to take a look at the multiple time-series plotted side by side (like here) and check if really there exists this time-shifted pattern in your customer behavior.