Is there an hypothesis test of whether a normally-distributed dependent variable is associated with a directionally-distributed variable?

For example, if time of day is the explanatory variable (and assuming things like day of week, month of year, etc. are irrelevant)—that is how to account for the fact that 11pm is 22 hours ahead of 1am, and also 2 hours behind 1am in a test of association? Can I test whether continuous time of day explains the dependent variable without assuming that 12:00 midnight does not follow a minute after 11:59pm?

Does this test also apply to discrete directional (modular?) explanatory variables? Or does that require a separate test? For example, how to test whether the dependent variable is explained by month of year (assuming day and season of year, and specific year or decade are irrelevant). Treating month of year categorically ignores the ordering. But treating month of year as a standard ordinal variable (say Jan=1... Dec=12) ignores that January comes two months after November.

  • 1
    $\begingroup$ The answer could fill a book (and there are several of them out there). Making your question more specific might help focus the answers on what matters to you. $\endgroup$
    – whuber
    Mar 22, 2016 at 21:35
  • $\begingroup$ @whuber Um... gosh... can you help me out on how to narrow? Specifying a distribution for the DV? Limiting to just a single test, rather than regression? I am a bit stumped and don't know where to begin... $\endgroup$
    – Alexis
    Mar 22, 2016 at 22:06
  • $\begingroup$ @whuber I have attempted to narrow the question quite a bit, and would be grateful for any pointers on making it more useful (I really just want a starting place for thinking about modular predictors). If this is now in decent form, I am likely to follow up with a similar question about such test that is distribution-free in the DV. $\endgroup$
    – Alexis
    Mar 23, 2016 at 21:16
  • $\begingroup$ @whuber Mulling the discrete modular IV over in a regression context: would a two-level mixed model with the discrete modular IV as the level-2 identifier with each level-2 unit having a pre- and post- random effect variable equal to the preceding and subsequent value in the number system be on the right track? $\endgroup$
    – Alexis
    Mar 28, 2016 at 23:27
  • $\begingroup$ See here jstatsoft.org/article/view/v031i10/v31i10.pdf, page 16. $\endgroup$
    – amoeba
    Apr 9, 2016 at 0:27

3 Answers 3


In general, I think it's more fruitful scientifically and statistically to start by asking a broader and different question, which is how far can a response be predicted from a circular predictor. I say circular here rather than directional, partly because the latter includes spherical and even more fabulous spaces, which can't all be covered in a single answer; and partly because your examples, time of day and time of year, are both circular. A further major example is compass direction (relevant to winds, animal or human movements, alignments, etc.), which features in many circular problems: indeed, for some scientists it is a more obvious starting point.

Whenever you can get away with it, using sine and cosine functions of time in some kind of regression model is a simple and easy to implement modelling method. It is the first port of call for many biological and/or environmental examples. (The two kinds are often mushed together, because biotic phenomena showing seasonality are usually responding directly or indirectly to climate, or to weather.)

For concreteness, imagine time measurements over 24 hours or 12 months, so that e.g.

$\sin [2\pi (\text{hour}/24)],\ \ \cos [2\pi (\text{hour}/24)]$

$\sin [2\pi (\text{month}/12)],\ \ \cos [2\pi (\text{month}/12)]$

each describe one cycle over the entire day or year. A formal test of no relationship between a measured or counted response and some circular time would then be a standard test of whether the coefficients of sine and cosine are jointly zero in a generalized linear model with sine and cosine as predictors, an appropriate link and family being chosen according to the nature of the response.

The question of the marginal distribution of the response (normal or other) is in this approach secondary and/or to be handled by family choice.

The merit of sines and cosines is naturally that they are periodic and wrap around automatically, so the values at the beginning and end of each day or year are necessarily one and the same. There is no problem with boundary conditions, because there is no boundary.

This approach has been called circular, periodic, trigonometric and Fourier regression. For one introductory tutorial review, see here

In practice,

  1. Such tests usually show overwhelmingly significant results at conventional levels whenever we expect seasonality. The more interesting question is then the precise seasonal curve estimated, and whether we need a more complicated model with other sinusoidal terms too.

  2. Nothing rules out other predictors too, in which case we simply need more comprehensive models with other predictors included, say sines and cosines for seasonality and other predictors for everything else.

  3. At some point, depending jointly on the data, the problem and the tastes and experience of the researcher, it may become more natural to emphasise the time series aspect of the problem and build a model with explicit time dependence. Indeed, some statistically minded people would deny that there is any other way to approach it.

What is easily named as trend (but not always so easily identifiable) comes under either #2 or #3, or even both.

Many economists and other social scientists concerned with seasonality in markets, national and international economies, or other human phenomena are usually more impressed with the possibilities for more complicated variability within each day or (more commonly) year. Often, although not always, seasonality is a nuisance to be removed or adjusted for, in contrast to biological and environmental scientists who frequently regard seasonality as interesting and important, even the main focus of a project. That said, economists and others also often adopt a regression-type approach too, but with ammunition a bundle of indicator (dummy) variables, most simply $0, 1$ variables for each month or each quarter of a year. This can be a practical way of trying to catch the effects of named holidays, vacation periods, side-effects of school years, etc., as well as influences or shocks of climatic or weather origin. With those differences noted, most of the comments above also apply in economics and social sciences.

Attitudes of, and approaches by, epidemiologists and medical statisticians concerned with variations in morbidity, mortality, hospital admissions, clinic visits, and the like, tend to fall in between these two extremes.

In my view splitting days or years into halves to compare is usually arbitrary, artificial and at best awkward. It is also ignoring the kind of smooth structure typically present in the data.

EDIT The account so far does not address the difference between discrete and continuous time, but I don't from my experience regard it as a big deal in practice.

But precise choices depend on how the data arrive and on the pattern of change.

If data were quarterly and human, I would tend to use indicator variables (e.g. quarters 3 and 4 are often different). If monthly and human, the choice isn't clear, but you would have to work hard to sell sines and cosines to most economists. If monthly or finer and biological or environmental, definitely sines and cosines.

EDIT 2 Further details on trigonometric regression

A distinctive detail of trigonometric regression (named in any other way if you prefer) is that almost always sine and cosine terms are best presented to a model in pairs. We first scale time of day, time of year or compass direction so that it is represented as an angle on the circle $\theta$ in radians, hence on the interval $[0, 2\pi]$. Then we use as many of the pairs $ \sin k\theta, \cos k\theta, k = 1, 2, 3, \dots$ as are needed in a model. (In circular statistics, trigonometric conventions tend to trump statistical conventions, so that Greek symbols such as $\theta, \phi, \psi$ are used for variables as well as parameters.)

If we offer a pair of predictors such as $\sin \theta, \cos \theta$ to a regression-like model, then we have coefficient estimates, say $b_1, b_2$, for terms in the model, namely $b_1 \sin \theta, b_2 \cos \theta$. This is a way of fitting phase as well as amplitude of a periodic signal. Otherwise put, a function such as $\sin (\theta + \phi)$ can be rewritten as

$$ \sin \theta \cos \phi + \cos \theta \sin \phi,$$

but $\cos \phi$ and $\sin \phi$ representing phase are estimated in the model fitting. That way we avoid a non-linear estimation problem.

If we use $b_1 \sin \theta + b_2 \cos \theta$ to model circular variation, then automatically the maximum and minimum of that curve are half a circle apart. That is often a very good approximation for biological or environmental variations, but conversely we may well need several more terms to capture economic seasonality in particular. That could be a very good reason to use indicator variables instead, which lead immediately to simple interpretations of the coefficients.

  • $\begingroup$ I note some unsurprising overlap with the answer from @Kelvin. $\endgroup$
    – Nick Cox
    Apr 11, 2016 at 17:13
  • $\begingroup$ +1 (Esp. for using "fabulous" as you did! :) Nick Cox, would you be so kind as to make explicit the case for discrete circular variables also, as per my question? Would that be as simple as the "trigonometric modeling" approach you describe using a discrete measure of time? Or would there need to be "continuity corrections" of some sort? $\endgroup$
    – Alexis
    Apr 11, 2016 at 21:02
  • $\begingroup$ As far as I'm aware, the only difference between discrete and continuous circular variables is in the rounding of values to discrete points (e.g., 2pm vs 14.12345hrs), as with non-circular variables, so there won't be much difference as long as you apply less rounding with small steps relative to the overall period. Basically, it's just a matter of having some rounding error or not. Best not, if you can avoid it. $\endgroup$
    – Kelvin
    Apr 12, 2016 at 5:54
  • $\begingroup$ I agree that discrete and continuous are not much different. In practice, many measurements are more or less coarsened by reporting just in quarters, half-years, months, days, etc. or as anything ranging from (N. S) through (N, E, S, W) on to finer resolution for compass directions. In detail, there are difference between point measurements (the temperature at a precise time) and interval measurements (e.g. total monthly sales). I wouldn't lump all such details together as rounding error, as sometimes there is no error so much as aggregation or averaging. $\endgroup$
    – Nick Cox
    Apr 12, 2016 at 6:45

Here is a distribution-free option, since it seems that's what you're looking for anyway. It is not particular to the field of circular statistics, of which I am fairly ignorant, but it is applicable here and in many other settings.

Let your directional variable be $X$.

Let the other variable be $Y$, which can lie in $\mathbb R^d$ for any $d \ge 1$ (or, indeed, any type of object on which a useful kernel can be defined: graphs, strings, images, probability distributions, samples from probability distributions, ...).

Define $Z := (X, Y)$, and suppose you have $m$ observations $z_i = (x_i, y_i)$.

Now, conduct a test using the Hilbert Schmidt Independence Criterion (HSIC), as in the following paper:

Gretton, Fukumizu, Teo, Song, Schölkopf, and Smola. A Kernel Statistical Test of Independence. NIPS 2008. (pdf)

That is:

  • Define a kernel $k$ for $X$. Here we mean a kernel in the sense of a kernel method, i.e. a kernel of an RKHS.

    • One choice is to represent $X$ on the unit circle in $\mathbb R^2$ (as in Kelvin's edit), and use the Gaussian kernel $k(x, x') = \exp\left( - \frac{1}{2 \sigma^2} \lVert x - x' \rVert^2 \right)$. Here $\sigma$ defines the smoothness of your space; setting it to the median distance between points in $X$ is often good enough.
    • Another option is to represent $X$ as an angle, say in $[-\pi, \pi]$, and use the von Mises kernel $k(x, x') = \exp\left( \kappa \cos(x - x') \right)$. Here $\kappa$ is a smoothness paramater.1
  • Define a kernel $l$ for $Y$, similarly. For $Y$ in $\mathbb R^n$ the Gaussian kernel, above, is a reasonable default.

  • Let $H$, $K$, and $L$ be $m \times m$ matrices such that $K_{ij} = k(x_i, x_j)$, $L_{ij} = l(y_i, y_j)$, and $H$ is the centering matrix $H = I - \frac1m 1 1^T$. Then the test statistic $\frac{1}{m^2} \mathrm{tr}\left( K H L H \right)$ has some nice properties when used as an independence test. Its null distribution can be approximated either by moment-matching to a gamma distribution (computationally efficient), or by bootstrapping (more accurate for small sample sizes).

Matlab code for carrying this out with RBF kernels is available from the first author here.

This approach is nice because it is general and tends to perform well. The main drawbacks are:

  • $m^2$ computational complexity to compute the test statistic; this can be reduced with kernel approximations if it's a problem.
  • The complicated null distribution. For large-ish $m$, the gamma approximation is good and not too onerous; for small $m$, bootstrapping is necessary.
  • Kernel choice. As presented above, the kernels $k$ and $l$ must be selected heuristically. This paper gives a non-optimal criterion for selecting the kernel; this paper presents a good method for a large-data version of the test that unfortunately loses statistical power. Some work is ongoing right now for a near-optimal criterion in this setting, but unfortunately it's not ready for public consumption yet.

1. This is frequently used as a smoothing kernel for circular data, but I haven't in a quick search found anyone using it as an RKHS kernel. Nonetheless, it is positive-definite by Bochner's theorem, since the shift-invariant form $k(x - x')$ is proportional to the pdf of a von Mises distribution with mean 0, whose characteristic function is proportional to a uniform distribution on its support $[-\pi, \pi]$.


You could run a t-test between the mean from opposite "halves" of the period, for example by comparing the mean value from 12am to 12pm with the mean value from 12pm to 12am. And then compare the mean value from 6pm to 6am with the mean value from 6am to 6pm.

Or if you have enough data, you could break the period into smaller (e.g., hourly) segments and perform a t-test between each pair of segments, while correcting for multiple comparisons.

Alternatively, for a more "continuous" analysis (i.e., without arbitrary segmentation), you could run linear regressions against the sine and cosine functions of your directional variable (with the correct period), which will automatically "circularize" your data:

$$x' = sin(x * 2\pi/period)$$ $$x'' = cos(x * 2\pi/period)$$

The main problem with any such approach, is that it will be difficult to ensure that the phase of your model is set to pick out the maximum correlation, hence you may need to try several different phases, or else select the phase by eye to formulate your hypothetical value $a$:

$$x''' = sin((x+a) * 2\pi/period)$$

However, ideally you should formulate your hypothesis (e.g., afternoons are more active than mornings) and then set the appropriate $a$ before you even look at the data.

EDIT: One further thought is that you could run a multiple regression against BOTH the sine and cosine functions of the directional variable at the same time (i.e., between your normal variable $y$ plus $x'$ and $x''$) as that should take into account the true "direction", in much the same way that the sine and cosine functions together define the x and y coordinates of a complete circle. Then you wouldn't need to bother about the phase issue separately, as it would be taken care of automatically. I have never seen this done before, but I don't see why it shouldn't work.

In any case, I think you must make some assumptions regarding the period, and then test accordingly.

  • 1
    $\begingroup$ Kelvin, "breaking" the circular data as you describe would seem to ignore precisely the issue I raised about modular ordering. $\endgroup$
    – Alexis
    Apr 11, 2016 at 20:55
  • $\begingroup$ Did you read the second half of my answer, which describes continuous analysis by multiple regression? $\endgroup$
    – Kelvin
    Apr 11, 2016 at 20:59
  • 1
    $\begingroup$ You're right about sine and cosine together. This is explained further in my answer and in the 2006 paper it cites and in further references that that cites. $\endgroup$
    – Nick Cox
    Apr 12, 2016 at 11:33
  • $\begingroup$ @Nick - I hadn't seen your answer as you posted after my last edit, but good that we came to the same answer independently as I was just being creative (virtually thinking out loud) and had never actually seen this done before. $\endgroup$
    – Kelvin
    Apr 13, 2016 at 7:47

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.