Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

I am analysing annual behavioural patterns and am currently scratching my head over how to best transform data to test for correlation where my independent variable is the moon phase (given as perecentual moon illumination, i.e. 0% new moon, 100% full moon).

May be a rather trivial question, but I haven't come across this problem before so am a bit at a loss.


share|improve this question
What's wrong with using the % value? –  Peter Flom Jul 3 at 9:35
The problem is that moon phase data are not linear. The response variables are strongly skewed towards new and full moon. –  Tomm Jul 3 at 9:59
add comment

2 Answers 2

The conventional term for "sinuous" data is that they are circular or angular variables. These are values that exhibit inherent periodicity and can therefore be thought of as if they were angles or, equivalently, "phases" during a repeating set of "seasons."

"Circular statistics" is that branch of data analysis comprising techniques specifically applicable to angular variables. It includes many definitions of coefficients of correlation between angular variables, corresponding roughly to the several well-known kinds of correlation between any two quantitative variables (such as the Pearson and Spearman coefficients). Typically these coefficients are computed in terms of the sines and cosines of the angular variables in a way that is strongly reminiscent of their ordinary counterparts. This makes them relatively easy to calculate and interpret. There are similar analogs of distribution-fitting procedures, linear regression, t-tests, and more.

In the present context, the phase of the moon (to a very good approximation) depends only on the time modulo the moon's period: it is an angular variable. This alone indicates that methods of circular statistics are needed. If the annual "behavioral patterns" can be recorded as times during the year, then their patterns also can be considered to be an angular variable. (If not, there are methods of "circular regression", as described in the references below, that relate conventional quantitative variables to angular variables.)


A circular statistics package circular exists in R. It includes natural counterparts to standard correlation tests, such as cor.circular, an analog of cor (correlation matrix). The sample code from the manual page generates bivariate circular data using the Von Mises distribution, the circular analog of a Normal distribution, and induces a linear relationship among them:

n <- 50
x <- rvonmises(n, mu=circular(0), kappa=3)
y <- x + rvonmises(n, mu=circular(pi), kappa=10)

Let's visualize these data: first alone, on circular plots in which position along a circle represents phase within a season; next together, as scatterplots.

plot(x, main="x"); plot(y, main="y")
plot(unclass(x) %% (2*pi), unclass(y)%% (2*pi), 
     xlab="Phase of x", ylab="Phase of y", main="Reduced Scatterplot")
abline(lm(y %% (2*pi) ~ I(x %% (2*pi))), col="Gray", lty=2)
plot(unclass(x), unclass(y), xlab="x", ylab="y", main="Raw Scatterplot")
abline(lm(y ~ x), col="Gray", lty=2)


The $x$ variable tends to be near an angle of zero: that is, it is observed around the beginning and end of each cycle. The $y$ variable tends to be near the midpoint of each cycle (an angle of $\pi$). But from this information alone we cannot tell anything about how $x$ and $y$ might be related. For this purpose one would naturally draw a scatterplot. Since only the phase matters, we typically would record only the phases of the variables, producing the "reduced scatterplot" of the bottom left. The dashed gray line is the ordinary least-squares line (which does not recognize the angular nature of the variables). It is a poor fit. Instead, if we judiciously modify how some of the y-values are recorded by adding one (or more) whole seasons to them (seasons are measured in radians for these data, so a whole season is $2\pi \approx 6.3$ on each scale), we can make the data line up as shown in the "raw scatterplot" at lower right. This time the least-squares line closely fits the data and indicates a strong positive correlation.

That correlation can be measured without having to figure out how many whole seasons to add to the $y$ (and/or) $x$ coordinates:

cor.circular(x, y, test=TRUE)

The output consists of three numbers: cor, a particular circular correlation coefficient (which can be interpreted in roughly the same way as the familiar Pearson coefficient), a test statistic, and a p-value. In this case the tiny p-value indicates this is a strongly significant correlation (which we already had guessed from the scatterplots) and the coefficient of $0.86$ indicates the association between $x$ and $y$ is strong and positive, with little scatter around the fitted line.

[1] 0.8602176

[1] 4.590058

[1] 4.431237e-06


A classic (and highly readable) reference is

  • Edward Batschelet, Circular Statistics in Biology. Academic Press, 1981.

An original account of a circular correlation coefficient, an estimator, and tests using it, is available through JSTOR:

  • N.I. Fisher and A.J. Lee, A correlation coefficient for circular data. Biometrika 70 no 2, pp 327-32, 1983.

Fisher is the author of a more recent textbook on circular statistics.

  • N.I. Fisher, Statistical Analysis of Circular Data. Cambridge University Press, 1995
share|improve this answer
add comment

From your reply to my comment, the problem is that the effect of moon phase is nonlinear. So, you could do anything that you usually do to a continuous variable that has a nonlinear response. Spline regression might be a good choice.

share|improve this answer
Or lowess regresion, running line smooth regression, running mean smooth regression, generalized additive models, etc. :) –  Alexis Jul 3 at 16:17
@Alexis and Peter, the problem with any such regression solution is illustrated by the "Reduced Scatterplot" figure in my answer: you are both proposing to fit curves to those points but obviously that won't work. The difficulty comes down to how one represents phases of the moon, because "new moon" and "old moon" are just days apart but numerically they would be recorded as, say, $1$ day into the cycle and $28$ days into the cycle, suggesting they are far apart. –  whuber Jul 3 at 16:36
@whuber I had assumed we were talking about percentual (woo! new word!) amount of light, which, depending on the nature of the question may be what is substantively important as opposed to wax/wane stage. But I appreciate the circular stats take. –  Alexis Jul 3 at 17:00
@Alexis Thank you for the reminder that there can be multiple interpretations here. Until that is cleared up we should be careful to clarify what interpretation we are reacting to whenever we make recommendations. –  whuber Jul 3 at 17:38
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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