# Time Series for each customer

Is it possible to create Time Series Analysis for each customer? Say if have 100 customers and I wanted to predict how much amount they are going to spend next. I have done the Time Series for the whole data set that do not have customer information. For example customer_number and  data in R:

customer_number <- c(1,1,1,4,5,6,7,7, 8,9,10, 10)
amount <- c(10,11, 50, 12,30,40,15,11,88,30,32,35)
dates <- as.Date(c("2012-08-01", "2012-09-01", "2012-12-01", "2012-08-01", "2012-08-01", "2012-08-01", "2012-08-01",
"2012-12-01", "2012-12-01", "2012-08-01", "2012-08-01", "2012-10-01"))
data <- data.frame(customer_number , amount , dates)
data

• @ sharp yes you can. Dec 1, 2014 at 15:28
• @forecaster. Great! Any guidance on how I can do this? I have tried the R packages:library(tseries), library(forecast) Dec 1, 2014 at 15:32

As @forecaster notes: sure you can. Just separate your data by customer.

However, you will need to consider a couple of things. For instance, you only have sales acts, no zeros, so you will need to think about how to fill in zeros. From when till when? Are there periods where zero filling makes no sense, because the product was not even available? And: are you interested in a daily, weekly or other time granularity?

No matter how you decide these questions, your time series will likely be very intermittent, i.e., contain many zeros. ARIMA (as your question is tagged) is not appropriate for that. One well-established forecasting technique for intermittent demands is Croston's method (croston() in the forecast package). Here is a brand new article discussing an alternative that also models obsolescence (which makes sense for your data: this would be customers that won't return) and gives further pointers to the literature.

Most time series forecasting methods, like Croston's, will give you either average demands (e.g., 0.1 if someone buys one unit every 10 time buckets), the usefulness of which is a bit dubious. Or it gives you the demand size conditional on demand being nonzero. You will need to think about what exactly you need.

And actually, depending on what you actually want to use the forecast for, it may turn out that you don't really want separate forecasts per customer, but a total forecast aggregated over all customers. For instance, you will likely capture seasonality far better on aggregate data (Croston's and other intermittent demand methods don't model seasonality at all).

You could use separate time-series models on each customer, but you probably want to account for changes in sales of all customers when modeling each individual customer.

The most obvious way is to simply run VAR on the n-dimensional variable. There's an issue of missing observations: not every customer may have sales in every month. This easy to address with state-space (SSM) representation of VAR. The real problem is, of course, dimensionality: you'll have to estimate at least n$\times$n matrix. To deal with this issue you could apply PCA, and reduce the dimensionality of the problem to m$\times$m, where $m<<n$.

Another way of dealing with this issue is to build separate time series models for each customer such as ARIMA. Then calculate the $n\times$n correlation matrix of residuals from these models. Use this correlation matrix to create correlated random innovations for forecasting.

Another way is to run a Kalman filter on the n-dimensional vector assuming m-dimensional latent factor x. The key here is to assume diagonal matrix F, zero matrix B. This will render n$\times$m matrix H. So, the dimenionality of your problem went from n$\times$n to much lower ~n$\times$m.

Check out some of the Fader and Hardie work, e.g. http://www.statwizards.com/Help/ForecastWizard/WebHelp/Overview/Overview_of_Fader-Hardie_Probability_Models.htm This link seems to be to a commercial site, but Fader and Hardie published their models in standard academic journals such as Marketing Science.

Usually there are working prototypes on Hardie's site, although usually in Excel, not R.

For much of this work, there is a compound model. The number of purchases / amount of purchases is predicted with a NBD model (gamma-poisson). There is a separate model predicting how long the customer will remain a customer.

• I see there's now a R version, BTYD (Buy Til You Die models) Mar 17, 2019 at 23:53
• For any python person stumbling across this page, there's also a python version called Lifetimes. Apr 3, 2020 at 11:07

This kind of data is referred to as Intermittent Demand as the interval between demand/spend is non-uniform i.e there are days without any spend. Good forecasting software can handle these kinds of problems.

• Exactly how would good forecasting software handle this?
– whuber
Dec 1, 2014 at 16:47
• You can convert demand to a rate and then (gasp !) model rate as a function of interval in order to detect level shifts and/or pulses in the rate series. Make a prediction for rate using the average interval then convert the predicted rate to a predicted demand. Works for us !. Suggested to me by a university colleague ... Dec 1, 2014 at 18:05
• Thank you. Don't you think this explanation belongs in your answer itself?
– whuber
Dec 1, 2014 at 18:10
• We don't ordinarily disclose all of our "magic sauce" BUT since you pointedly asked I responded . Yes I could have added that and perhaps should have. Dec 1, 2014 at 18:15