10
$\begingroup$

My question originally arises from reading this post Use of circular predictors in linear regression.

Right now, I'm trying construct linear regression using "Bike Sharing dataset" from https://archive.ics.uci.edu/ml/datasets/bike+sharing+dataset which basically tries to regression bike rental count on different variables

One of the predictor that I have question is on using "Hour" of when the rental occurred, which takes value from 0 to 23. The original post suggests transforming the circular data (time of day) using sine function to maintain the circular characteristic.

I was trying to apply to same methodology to my situation to transform the Hour variable. However,transforming 0~23 using sin(π hour/180) lets 00:00 and 12:00 to have 0. But I think people will certainly display different behavior when renting bike at midnight(00:00) and afternoon(12:00)

In this case, is it better to just use 23 dummy variables to account for hour or am I misunderstanding the concept of circular regression?

$\endgroup$
1
  • 1
    $\begingroup$ I doubt bike sharing data of any sort are well represented by a simple sine wave. For more flexibility consider using a circular spline instead. $\endgroup$
    – whuber
    Commented Mar 25, 2018 at 19:04

2 Answers 2

10
$\begingroup$

Circular regression most often would refer to regression with a circular outcome.

In this case, we have linear regression with a circular predictor. In that case, we would add both the sine and the cosine of the angle to the regression, so that we predict the outcome as $\hat{y} = \beta_1\cos(\pi * \text{hour} / 12) + \beta_2\sin(\pi * \text{hour} / 12).$ Adding both the sine and cosine naturally resolves the issue you mention. Note that here, different than you, I've assumed that you represent hour in hours rather than degrees.

For a more elaborate answer on how to do this and what it means, please see the answer to this SO question.

$\endgroup$
4
$\begingroup$

You want to map the interval $(0,24)$ to the interval $(0,2\pi)$ - a full cycle -; the function to do so is

$$2\pi \frac{\mathrm{hour}}{24}$$

You then need two terms in your linear model (recall that an equivalent non-linear parametrization uses phase & amplitude):

$$\beta_1 \sin\left(2\pi\frac{\mathrm{hour}}{24}\right) + \beta_2 \cos\left(2\pi \frac{\mathrm{hour}}{24}\right)$$

Noon & midnight aren't constrained to result in equal predictor values because the phase is estimated from your data. Noon might be at the peak and midnight at the trough of the wave.

And you can continue with harmonics in an analogous way to higher-order polynomial terms: $$\ldots +\beta_3 \sin\left(2\times 2\pi\frac{\mathrm{hour}}{24}\right) + \beta_4 \cos\left(2\times 2\pi \frac{\mathrm{hour}}{24}\right)+\ldots$$

$\endgroup$
5
  • 1
    $\begingroup$ harmonic regression $\endgroup$
    – Aksakal
    Commented Mar 25, 2018 at 17:23
  • $\begingroup$ Won't these two terms be correlated or collinear and then harm the model? $\endgroup$
    – skan
    Commented Nov 16, 2022 at 0:18
  • 1
    $\begingroup$ @skan: They'll typically be correlated in observational data, but not especially so. You can orthogonalize them if you want. $\endgroup$
    – Scortchi
    Commented Nov 16, 2022 at 16:48
  • $\begingroup$ @Scortchi-ReinstateMonica Why would the first two terms (with $\beta_1$ and $\beta_2$ be correlated? They are already orthogonal. (And what do you mean by orthogonalizing them?) $\endgroup$
    – psyguy
    Commented Jun 12 at 11:17
  • 1
    $\begingroup$ @psyguy: If you have many observations of $\mathrm{hour}$ spread out rather uniformly over a whole no. of days (or a long time period), you'd expect to see little correlation between the vectors $\sin\left(2\pi\frac{\mathrm{hour}}{24}\right)$ & $\cos\left(2\pi\frac{\mathrm{hour}}{24}\right)$. But none of those conditions need be the case. (An experimenter might choose to measure the response at fixed intervals throughout a whole no. days such that they were orthogonal.) $\endgroup$
    – Scortchi
    Commented Jun 12 at 13:32

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.