I am trying to fit a model of total rental bike with ten predictors using Poisson Regression. Four of them are integer :

  • Season : 1-4
  • Month : 1-12
  • Day : 0-6
  • Hour : 0-23

I usually treat integer variable as factor in R. But in this case, if I treat 'Month' and 'Hour' as factors, they will have many levels. But if I divide them into several groups (say, for variable 'Hour' : peak hour and non-peak hour), I'm afraid that the data will lose information.

There might be some alternative ways to analyse this kind of data, such as periodic formula. But unfortunately, I'm only allowed to use Poisson regression here.

So, is there any suggestions to properly treat these integer predictors in my analysis?

  • 3
    $\begingroup$ There's no such thing as a "periodic formula" in terms of a set of regressors, but you can use methods for periodic modeling as have been discussed in other SE posts, one from me is here. These can be applied to Poisson GLMs. $\endgroup$ – AdamO Mar 2 '18 at 21:28

I would use periodic splines to represent periodic function. Then I would use three of your variables, Month, Day, Hour leaving out Season (Season should be well enough represented by Month). These three periodicities will then be added. Some pseudo-code in R (since we do not have data):

library(pbs) # periodic splines basis functions 
mod.bike <- glm(total_rental ~ pbs::pbs(Hour, df=5, Boundary.knots=c(0,24)) +
                pbs::pbs(Day, df=3, Boundary.knots=c(0,7)) +
                pbs::pbs(Month, df=5, Boundary.knots=c(0,12)),
                family=poisson, data= ...)

If you could post some data we could use that for an example. A worked example can be found here: circular periodic time series or fit with periodic splines

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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