I am trying to predict the traffic volume for all the stations. My dataset consists of two response variables (double), the total traffic volume and the net flow traffic volume. There are 5 explanatory variables: the station id (factor), year (factor), month (factor), day (factor), hour (integer), weekday (binary). Due to the fact that there's no obvious linear increment of the traffic volume against year/ month/ day, these variables are treated as categorical ones.

I would like to use the 6 input variables to predict for the total traffic volume for each station and the net flow separately. Simple linear regression could never finish the computation. Random forest could not handle categorical predictors with more than 53 categories.

Could anyone help and point me the right direction about what models might be able to solve this problem in R?

  • 6
    $\begingroup$ Time variables should not be a factor variable. You need some kind of time series analysis which can take into account seasonality. $\endgroup$
    – Roland
    Apr 10, 2017 at 14:12
  • $\begingroup$ Just as Roland commented, month, day, hour variables especially seem to have seasonality on traffic y-variable where if you put them into regression model, residuals are highly auto-correlated that the result will be poor. You might have to plot them to check their moving patterns and apply time-series analysis. $\endgroup$
    – Mons2us
    Apr 10, 2017 at 14:28
  • $\begingroup$ You could look into fused lasso $\endgroup$ Apr 10, 2017 at 15:59
  • 3
    $\begingroup$ That gives you around 8000 observations per station--that ought to be enough for many purposes! Why not run a separate model for each station? $\endgroup$
    – whuber
    Apr 10, 2017 at 19:33
  • 2
    $\begingroup$ First I'd try to model the traffic for a single station only with a time-series approach. $\endgroup$
    – knb
    Sep 5, 2017 at 10:44

2 Answers 2


There are so many models can handle this kind of problems. Decision Tree algorithm (it can also include regression analysis) can be useful. Neural Network is always powerful but also computationally expensive. Logistic Regression is another approach, that I personally would follow as the first step since it is relatively powerful for prediction problems and does not consume so much computational resources relatively compared to aforementioned techniques.

Just to have a list of available algorithms in R (that I have used):


Logistic Regression

Naive Bayes

Neural Network

There are some other methods available that I am not familiar with therefore won't recommend. Another suggestion is using some measures like Coefficient of determination before converting date (i.e. year, month, day) to categorical variables (@Ronald's comment is helpful).

Good luck!


If you run a separate model for each station as whuber suggests in comments and bearing in mind that as roland suggested in comments you probably want to fit a model which takes account of the fact that your predictor variables are times and not just standard covariates then you will end up with 600 sets of coefficients and their variance covariance matrix. You can then combine these using standard multivariate meta-analysis methods using the estimates and their variance covariance matrix. Since you use R you might investigate some of the examples using metafor here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.