Survival analysis model to predict next transaction




I am looking for a statistical model to predict when a customer can do next transaction.

For example, I have a group of customers and their lifetime transactions (a particular transaction like buy grocery on dates). How can I predict when will that particular member will do next transaction.

I am using R.


Hi @nehak

I shall use a mixture of recommendation, time serie and basket analysis, more than one model anyway. I R the forecast package for time series, rules for basket analysis and association rules, recommender well there I do not know :frowning: but somebody in this forum certainly know, anyway you can implement very close as to work with text, so big matrix, frequency and linear algebra will certainly make something good (I hope…).

Hope those few lines help a little



HI @Lesaffrea

I believe survival analysis can be done using the past data and the frequency of purchase.
Is it required to consider recommendation for a survival problem? I have not worked on survival analysis but interested in knowing how recommendation will be used?

By the way, there is a package called “recommender” in R.

Thank you.


Hi @karthe1

I am careful, survival analysis is usually used in experiments when people (illness) disappear during the study and it is driven by the plan of experiment.
You mentioned customer behaviours, well true they can disappear, but you want to predict the next buy am I right? So in recommender you weight people that buy similar products and not, in a way you make one inference that there is a probability that they will buy similar product and this I believe could help the famous Walmart diaper and beer, by looking at pattern if you buy beer and you are in your 30s and married then then there is high probability you will buy diapers (in US), you acquired let say “Dune” in science fiction you next buy could be “Blade Runner” as you are in your 20s and just out of college (guess) but in your data you have certainly demographic attributes (variables).
Recommender is usually it is used in promotion, but you can turn it in forecasting and producer retailer do so ( there I am sure) for production forecast.
Hope this help to solve you problem, do it by steps and keep recommender for the end.
Have a good project :slightly_smiling:


there is just one product which the consumer can other option of purchase is available to him.for example i have gone through a survival model-anderson gill in which injuries of sportmen can be predicted give past matches and injuries they have a similar way i am taking this transaction logic it right?


Hi @nehak

Sounds good I shall not call it survival myself but sounds good if you time a time with decay involved, it means that you have done a time series analysis. If not it will be more a classification problem buy yes/no based on the previous buys, they key point is time is it recurring buying? do you have a decay ? And how many similar observations?

Hope this help.



Hi nehak - I am also working on a survival analysis problem, but haven’t made much progress. The available R packages seem to be able to identify the importance of factors which affect survival but they don’t seem to result in a prediction of the ‘time to event’. I have tried the randomForestSRC package which is a specialized random forest package for survival analysis as well as the glmnet package which handles survival analysis is you set family to “cox”. They both have predict functions, but these don’t predict ‘time to event’. If you figure out how to make these predictions then please let me know.


randomForestSRC’s predict function provides probability of survival for various time intervals. For eg. it will give a probability for an event surviving for n days. “n” is provided by the “time.interval” parameter which is automatically computed by the algorithm.


thanks girish.


i am running this code

cphfit = coxph(Surv(Start,Stop,Event)~Age+JoinYears+cluster(ID),data=data)

but the issue is that how to predict for further time intervals?


Pretty nice discussion for this problem statement. I am also in the same boat but a little late than buddies here. Hope i can learn from your implementations. @nehak Let me know if you implemented this. Share some thoughts post your implementation. Hope i can learn here