CircStat : A MATLAB Toolbox for Circular Statistics

Directional data is ubiquitious in science. Due to its circular nature such data cannot be analyzed with commonly used statistical techniques. Despite the rapid development of specialized methods for directional statistics over the last ﬁfty years, there is only little software available that makes such methods easy to use for practioners. Most importantly, one of the most commonly used programming languages in biosciences, MATLAB , is currently not supporting directional statistics. To remedy this situation, we have implemented the CircStat toolbox for MATLAB which provides methods for the descriptive and inferential statistical analysis of directional data. We cover the statistical background of the available methods and describe how to apply them to data. Finally, we analyze a dataset from neurophysiology to demonstrate the capabilities of the CircStat toolbox.


Introduction
Circular statistics is a subfield of statistics, which is devoted to the development of statistical techniques for the use with data on an angular scale.On this scale, there is no designated zero and, in contrast to a linear scale, the designation of high and low values is arbitrary.Consider for example the case of wind directions measured in degrees -wind blowing towards 359 deg follows almost the same path as wind blowing towards 0 deg.In addition to measurements which are naturally measured in angles circular statistics applies also to types of data such as time of the day, phase of the moon or day of the year that exhibit a different periodicity.
The circular nature of such data prevents the use of commonly used statistical techniques, as these would provide wrong or misleading results.The authors thus used tools from circular statistics to compute the average heading direction, assert the prevalence of a common heading direction for a group of birds and compare the average heading directions of an experimentally manipulated and a control group.The development of techniques suitable to this end started in the early 1950es with a seminal paper by Fisher (1953).Despite the fact that circular statistics is still in very active development, several monographs and textbook lay out a standard repertoire of circular statistics methods (e.g., Batschelet 1981;Fisher 1995;Zar 1999;Jammalamadaka and Sengupta 2001).
It is all the more surprising that techniques for the analysis of circular data have not yet become available as part of many commerical software products for data analysis such as MATLAB.MATLAB is a high-level programming environment designed for numerical computations developed and marketed by The Mathworks (The MathWorks, Inc. 2007).It is highly popular among many scientists in biomedical research and beyond, since it offers a wide range of preimplemented functionality.Currently it is used by more than one million people (Moler 2006).More specialized add-on packages are available in the form of toolboxes.The statistics toolbox (The MathWorks, Inc. 2008), for example, extends the capabilities of the core system by providing functions for many commonly encountered problems in descriptive and inferential statistics.Methods for the analysis of circular data, however, are not part of this, or any other, toolbox for MATLAB.The CircStat toolbox described in this paper is intended to provide the users of MATLAB with a comprehensive set of functions and solutions for most common problems in descriptive and inferential statistics for circular data1 .While the software package described in this paper is currently the only one offering circular statistics for the use with MATLAB, there are a small number of comparable toolboxes for other languages or environments.The CircStats package for the R programming language is most closely related to the toolbox described here (Lund and Agostinelli 2007).It offers a small number of tests as described in (Jammalamadaka and Sengupta 2001) and has been ported from a S-plus original version.While R is hugely popular among statisticians, MATLAB is the most commonly used programming and data analysis environment in the engineering and biological sciences.A similar package is available for Stata (Cox 2004).Both of these packages are open source and freely available on the internet.In addition, Oriana is a commerically available program which offers basic functionality for the analysis of circular data (Kovach Computing Services 2009).
In the following, we will describe the methods implemented in the CircStat toolbox and explain how they can be used for analysis of circular data.The exposition will be fairly detailed as we combine a set of methods described in various different sources.First, we start with descriptive statistics, before we cover important methods from inferential statistics and measures of association.For illustrations and examples, we will mostly be referring to two synthetic datasets shown in Figure 1.Both datasets are shown in raw format as well as in the form of histograms.The dataset shown in Figure 1a and b will be called α and the dataset shown in Figure 1c and d will be called β.Finally, we will apply the methods described in this paper to a dataset from a neuroscientific context and use them to study orientation tuning of single neurons.First, however, we discuss some notational conventions and cover some basic issues.
We denote a vector of N directional observations α i as α = (α 1 , . . ., α N ).All functions described in this paper take their arguments in radians.To convert angles in degrees to angles in radians we compute Conversions from degrees to radians and vice versa can be performed using the functions circ_ang2rad(alpha) and circ_rad2ang(alpha).
Similarly, data such as time of the day or phase of the moon can be converted to a common angular scale in radians by where x is the representation of the data in the original scale, α is its angular direction and k is the total number of steps on the scale that y is measured in.For example, we have x representing day of the year and thus k = 365, not considering leapyears for simplicity.In addition, data with multiple modes-known as axial data-can be converted to a unimodal sample for the purpose of certain analysis such as computation of a mean resultant vector by (Fisher 1995, Section 2.4.).For p-axial data this results in the following mapping: Afterwards, the result of the performed computation can be transformed back to the original scale.This operation is implemented in circ_axial.

Descriptive statistics
In this section we describe the methods and functions implemented in the CircStat toolbox for computing descriptive measures on angular data.They can be used to explore and summarize important properties of a sample of angular data such as central tendency, spread, symmetry or peakedness.
If not otherwise noted, all functions can also be applied to binned data if supplied with a second optional input argument w of the same length as α.They then assume that the data has been binned with bin center i equal to α i and w i equal to the number or fraction of samples falling into bin i.For measures of dispersion, the bin width can be specified as an optional third argument, which is then used for bias correction.
Mean The mean of a sample α cannot be computed by simply averaging the data points.
This is illustrated in Figure 1a and c, where all datapoints marked by circles lie on the unit sphere.As indicated for the light blue point in Figure 1c, the x-coordinate of a point corresponds to the cosine of the angle and the y-coordinate to the sine.
After this transformation, the vectors r i are vector averaged by The vector r is called mean resultant vector.To yield the mean angular direction ᾱ, r is transformed using the four quadrant inverse tangent function.For further illustraction, see also the example in Figure 2.
In CircStat, the mean resultant vector ᾱ of a set of datapoints can be computed by >> alpha_bar = circ_mean(alpha); For the example, this results in mean resultant vectors pointing towards ᾱ = 23.5 deg and β = 72.5 deg, respectively.These vectors are also shown in red.
For ease of implementation in MATLAB, the first transformation is implemented exploiting the identity cos α + i sin α = exp(iα) and the second transformation uses the MATLAB function angle.If a second and third output argument are requested, circ_mean computes the 95% confidence intervals on the estimation of ᾱ using circ_meanconf.

a b c
Figure 2: Illustration of the resultant vector and the resultant vector length.In a, three samples 60, 180, 300 deg (black) yield a resultant vector length of zero, since the points are exactely uniformly spaced around the circle.In b, 120, 180, 240 deg result in a resultant vector length of 2/3, with a common mean direction of π.In c, 150, 180, 210 deg yield a resultant vector length of 0.9107 with the same mean direction.Resultant vectors are shown in grey and can be obtained by vector addition.The light grey circle is the unit circle.
Median The median direction α of a sample α is the direction for which half of the datapoints fall on either side.For circular data thus the diameter of the circle that divides the data into two equal sized groups is found.The median is the endpoint of the diameter closer to the center of mass of the data.If N is even, it lies half-way between the two closest datapoints.
If N is odd, it falls on one of the data points.
If the datapoints are drawn from a uniform distribution or evenly spaced around the circle there is no well-defined median direction.
The median cannot be computed for binned data.

Resultant vector length
The length of the mean resultant vector is a crucial quantity for the measurement of circular spread or hypothesis testing in directional statistics.The closer it is to one, the more concentrated the data sample is around the mean direction.For an example, see Figure 2. The resultant vector length is computed by In CircStat, the resultant vector length is computed by >> R = circ_r(alpha); For the example, this results in R α = 0.45 and R β = 0.36.
The estimation of R is biased when binned data is used.This bias can be corrected for by supplying the bin spacing d as a third optional argument and computing a correction factor (Zar 1999, Equation 26.16) Variance The circular variance is closely related to the length of the mean resultant vector.
It is defined as In contrast to the variance on a linear scale, the circular variance s is bounded in the interval [0, 1].It is indicative of the spread in a data set.If all samples point into the same direction, the resultant vector will have length close to 1 and the circular variance will correspondingly be small.If the samples are spread out evenly around the circle, the resultant vector will have length close to 0 and the circular variance will be close to maximal.Importantly, however, a circular variance of 1 does not imply a uniform distribution around the circle.If all samples either point towards 0 deg or 180 deg, the resultant vector length is 0, yet the data is not distributed uniformly around the circle.
In CircStat, the circular variance is computed using >> S = circ_var(alpha); In the example, we thus obtain S α = 0.55 und S β = 0.64.Thus the dataset β is more spread out than dataset β.
Standard deviation Interestingly, multiple quantities have been introduced as analogues to the linear standard deviation.First, the angular deviation is defined as This quantity lies in the interval [0, √ 2].Alternatively, the circular standard deviation is defined as and ranges from 0 to ∞.Generally, the first measure is preferred, as it is bounded, but the two measures deviate little Zar (1999).
In CircStat, the angular deviation is computed as and the circular standard deviation as For the example, the respective values are s α = 1.05, s β = 1.14 and s 0,α = 1.26, s 0,β = 1.44.
Trigonometric moments It is possible to compute the p-th trigonometric moment of a sample of circular data (Fisher 1995).The uncentred p-th moment is given by Similarly, the centred trigonometric moments are obtained by calculating the moments relative to the sample mean by Similar to the mean resultant vector, m p and m p can be decomposed into direction ᾱp and magnitude R p .
In CircStat, the uncentred p-th trigonometric moment can be found by calling and the centred p-th trigonometric moment by Optionally, direction and magnitude are returned as second and third output argument.
Skewness As a measure of symmetry, circular skewness can be computed as (Pewsey 2004) A value close to 0 is indicative of a symmetric population around the mean direction.Alternatively, a standardized measure of skewness has been defined as (Fisher 1995) In CircStat, circular skewness is computed by >> [b, b0] = circ_skew(alpha); For the example, we find that both samples are relatively symmetric around their mean directions with skewness values of b α = 0.02 and b β = 0.04 or b 0,α = −0.019and b 0,β = −0.099.
Kurtosis As a measure of peakedness, circular kurtosis can be computed as (Pewsey 2004) A large positive sample value of k close to one indicates a strongly peaked distribution.Alternatively, a standardized measure of kurtosis has been defined as (Fisher 1995) The former definition is intuitively appealing, since many values close to the mean direction lead to positive contributions to the above average due to the shape of the cosine function.
However, the latter definition has the appealing property that data generated by a von Mises distribution, which is the circular analogue of the Normal distribution, has k 0 = 0.
In CircStat, circular kurtosis is computed by For the example, we find that k α = 0.42 and k β = 0.01, such that sample β is less peaked than sample α.If we want to compare the peakedness of the two samples to a von Mises distribution, we find that both samples have lower kurtosis with k 0,α = −0.66 and k 0,β = −1.18.

Inferential statistics
In this section, we describe a set of functions implemented in CircStat for inferential statistics with angular data.The first set of functions allows to test the popular question of circular uniformity, while other methods allow to investigate more specific hypothesis about the mean direction of one or multiple samples.For example, researchers studying the migratory behavior of birds (Wiltschko and Wiltschko 1972;Cochran et al. 2004) might want to establish that all animals from one species indeed migrate into a common direction or acertain that two species of birds migrate into differing directions.

Testing for circular uniformity
A common question in circular statistics is whether a data sample is distributed uniformly around the circle or has a common mean direction.There are multiple tests for this problem that share a common null hypothesis H 0 : The population is distributed uniformly around the circle with alternative hypothesis H A : The population is not distributed uniformly around the circle.
They differ in their efficiency to detect certain departures from uniformity, as discussed below.

Rayleigh test
The Rayleigh test asks how large the resultant vector length R must be to indicate a non-uniform distribution (Fisher 1995).It is particularly suited for detecting a unimodal deviation from uniformity.If the data indeed is unimodal, it is the most powerful test described in this section.
The approximate p-value under H 0 is computed as (Zar 1999, Equation 27.4) where R n = R • N .This approximation is valid up to three decimal places for N as small as 10.The Rayleigh test can also be applied to axial data after suitable transformation.Importantly, it assumes sampling from a von Mises distribution.
In CircStat, the Rayleigh test is performed by computing >> p = circ_rtest(alpha); where a small p indicates a significant departure from uniformity and indicates to reject the null hypothesis.
For the examples, we find that at the 0.05 significance level, the null hypothesis can be rejected for sample α (P = 0.02), while for sample β, this is not the case (P = 0.08).

Omnibus test
The "omnibus test" or Hodges-Ajne test (Zar 1999) for circular uniformity is an alternative to the Rayleigh test that works well for unimodal, biomodal and multimodal distributions.It is able to detect general deviations from uniformity at the price of some statistical power.Also, it does not make specific assumptions about the underlying distribution.
To conduct the test, the smallest number m that occur within a range of 180 deg is computed.
Under the null hypothesis, the probability of observing an m this small or smaller is which can for N > 50 be approximated by In CircStat, the Omnibus test is performed by computing >> p = circ_otest(alpha); For the examples, we find that at the 0.05 significance level, the null hypothesis cannot be rejected for either sample (P = 0.11 and P = 0.3, respectively).
Rao's spacing test Rao's spacing test for circular uniformity is an additional alternative to the Rayleigh test (Batschelet 1981).It is more powerful than alternatives when the data are neither unimodal nor axially bimodal.It is based on the idea that in an ordered sample α = (α 1 , . . ., α N ) with α i+1 > α i sampled from a uniform distribution the differences between successive samples should be approximately 360 • N .Its test statistic is defined as The distribution of U is computationally very complex, and we use tabled values instead of the full distribution as computed by (Russell and Levitin 1995).
In CircStat, Rao's spacing test is performed by >> p = circ_raotest(alpha); For the examples, we find that, at the 0.05 significance level, the null hypothesis cannot be rejected for either sample (P ≥ 0.05).
V test The V test for circular uniformity is similar to the Rayleigh test with the difference that under the alternative hypothesis H A is assumed to have a known mean direction ᾱA .It is important that the mean direction has to been known in advance, i.e., before any look at the data is taken.The test statistic is computed as (Zar 1999) where R n as above.Approximate critical values for the quanitity V 2 N can be obtained from the one tailed normal deviate Z α(1) .Due to the additional information used, the V test is more powerful than the Rayleigh test.The additional power comes at a certain cost: Not rejecting the null hypothesis in this case leaves it open whether the cause for that failure was insufficient evidence for non-uniformity or a different mean direction than ᾱA .
In CircStat, the V test is performed by >> p = circ_vtest(alpha,0); Testing for violations of uniformity assuming a mean direction of 0 deg results in a rejection of the null hypothesis for α (P = 0.045), but not β (P = 0.25).In the latter case we thus do not know whether the reason for not rejecting the null hypothesis was that the preferred direction was misspecified or because the sample is indeed uniformly distributed around the circle.

Tests concerning mean and median
This section covers a more diverse set of tests concerning various hypotheses about the mean or median direction.For example, they can be used to place confidence intervals on the mean direction, test for specific mean or median direction or for symmetry around the median.
Confidence Intervals for the Mean Direction We compute the (1 − δ)%-confidence intervals for the population mean (Zar 1999, Equations 26.23-26.26).For R ≤ 0.9 and R > χ 2 δ,1 /2N , we compute where R n = R • N .For R > 0.9, we compute In both cases, the lower confidence limit of the mean is found by L 1 = ᾱ − d and the upper confidence limit by L 2 = ᾱ + d.
In CircStat, 95%-confidence intervals are found either by calling
For the example, we can assert that the true population mean likely lies in the interval 341.5 − 65.43 deg and 12.73 − 132.27 deg, respectively for datasets α and β.
One sample test for the mean angle Similar to a one sample t-test on a linear scale, we can test whether the population mean angle is equal to a specified direction.H 0 : The population mean angle ᾱ is equal to ᾱ0 .H A : The population mean angle ᾱ is not equal to ᾱ0 , i.e., ᾱ = ᾱ0 .
The test at significance level δ is performed by checking whether ᾱ0 ∈ [L 1 , L 2 ], where L 1 is the lower 1 − δ confidence limit on the population mean and L 2 the upper confidence limit (Zar 1999).
In CircStat, this test is performed by >> p = circ_mtest(alpha,ang2rad(90)); For the example dataset α, we thus can reject the null hypothesis that the true population mean is equal to 90 deg, while we do not have sufficient evidence to reject the hypothesis that it is equal to 0 deg.

Significance of the median angle A nonparametric test with
H 0 : The population median angle α is equal to α0 .H A : The population median angle α is not equal to α0 , i.e., α = α0 . is performed by applying the binomial test (Zar 1999).To this end, the number n of samples falling on either side of a diameter through α0 are counted.The p-value for observing this sample under H 0 is found by computing the probability of observing n or more out of N samples falling on one side of the diameter under a binomial distribution B(N, p) with p = 0.5.
In CircStat, this test is performed by >> p = circ_medtest(alpha,ang2rad( 90)); For the example dataset α, we thus can reject the null hypothesis that the true population mean is equal to 105 deg, while we do not have sufficient evidence to reject the hypothesis that it is equal to 25 deg.

Symmetry around median angle
A simple test of symmetry of a sample around the median can be performed by computing the circular distance d i of each point from the median and subjecting the d i to a Wilcoxon signed-rank test (Zar 1999).It has the hypothesis set H 0 : The underlying distribution is symmetrical around α. H A : The underlying distribution is not symmetrical around α.
The Wilcoxon signed-rank test asks whether the median of the circular distances d i is zero.
In CircStat, testing for symmetry around the median angle is performed by >> p = circ_symtest(alpha); For the two datasets in the example, the null hypothesis cannot be rejected (P = 0.84 and P = 0.79), in line with the measurements of skewness close to zero above.

Paired and multisample tests
In this section, we will describe three methods for two-or multisample analysis concerning the mean or median direction with one or two factors.In the one-factor case, a parametric as well as a non-parametric test are available, while the two-factor case is covered only by a parametric test.We will use a new example , where we draw 30 samples each from three von Mises distributions with concentration parameter κ = 10 and preferred direction θ1 = π, θ2 = π + 0.25 and θ3 = π + 0.5.
One-factor ANOVA or Watson-Williams test The Watson-Williams two-or multisample test of the null hypothesis is a circular analogue of the two sample t-test or the one-factor ANOVA.Thus, it assesses the question whether the mean directions of two or more groups are identical or not.
H 0 : All of s groups share a common mean direction, i.e., ᾱ1 = • • • = ᾱs .H A : Not all s groups have a common mean direction.
The test statistic is calculated via (Watson and Williams 1956;Stephens 1969) where R is the mean resultant vector length when all samples are pooled and R j the mean resultant vector length computed on the jth group alone (similar to total variance and within group variance in the ANOVA setting).The correction factor K is computed from where κ is the maximum likelihood estimate of the concentration parameter of a von Mises distribution with resultant vector length r w .We compute κ via the approximation given by Fisher (1995, Section 4.5.5).Here, r w is the mean resultant vector length of the s resultant vectors r j computed for each group individually.The obtained value of the test statistic is then compared to a critical value at the δ level obtained from F δ(1),1,N −2 .
The Watson-Williams test assumes underlying von Mises distributions with equal concentration parameter, but has proven to be fairly robust against deviations from these assumptions (Zar 1999).The sample size for applying the test should be at least 5 for each individual sample.If binned data is used, bin widths should be no larger than 10 deg.Note that rejecting the null hypothesis only provides evidence that not all of the s groups come from a population with equal mean direction, not if all groups have pairwise differing mean directions or evidence of which of the groups differ.
In CircStat, the Watson-Williams test can be performed in two ways.For two samples, >> p = circ_wwtest(alpha, beta); compares the two samples directly, while >> p = circ_wwtest(alpha, idx); uses idx to assign individual samples α i to the groups.If a second output argument is requested, no ANOVA table is printed but rather returned as a cell structure.
We first apply the test to our example datasets θ 1 and θ 2 , which we find to show a highly significant difference in their mean preferred directions (P < 0.001).Next we test for difference between any of the group means of θ 1 , θ 2 and θ 3 , which we find also to be highly significantly different (P < 10 −10 ).

Multi-sample test for equal median directions
We can test a similar nonparametric hypothesis, namely for equal medians among s groups of samples, using a test suggested by Fisher (1995).It is a circular analogue to the Kruskal-Wallis test.
H 0 : Any of s samples share a common median direction, i.e., α1 = • • • = αs .H A : Not all s samples have a common median direction.
We first compute the total median direction α by pooling all groups.Then we compute the number m i of samples within the ith group, whose angular distance d(α i j , α) to the total median is negative, where α i j indicates the jth sample from the ith group.The test statistic is computed as Here, n i are the number of samples in each group.The obtained statistic is compared to the upper 1 − δ-percentile of a χ 2 s−1 -distribution.Similar caveats regarding the interpretation of the results hold as for the Watson-Williams test.The test should not be used if any n i < 10.
In CircStat, this test can be performed in two ways.For two samples, >> p = circ_cmtest(alpha, beta); compares the two samples directly, while >> p = circ_cmtest(alpha, idx); uses idx to assign individual samples α i to the groups.
For the example, we find that the two groups θ 1 and θ 2 have a significantly different median orientations (P = 0.005).
Two-factor ANOVA or Harrison-Kanji test In a similar fashion to the one-factor ANOVA, we can also test for the influence of two factors simultaneously.Such a two-factor ANOVA method for circular data has been introduced by (Harrison, Kanji, and Gadsden 1986;Harrison and Kanji 1988).In addition to potential effects of the two factors, we can also study the impact of their interactions on the population means.
The test developed by Harrison and Kanji (1988) treats two situations separately: First, when the pooled sample concentration parameter κ is larger than two.Second, when it is smaller than two.Since the respective test statistics and their derivation is somewhat lengthy, we refer to Harrison and Kanji (1988) for details.
In CircStat, the two-factor ANOVA can be performed in the following way: >> [p, table] = circ_hktest(alpha,idp,idq,true); Here, alpha contains the whole sample, while idp and idq indicate the respective level of the two factors.The last argument ensures that the effect of interactions is tested for as well.
To illustrate the test, we use θ 1 and θ 2 .Factor A indicates whether a sample belongs to θ 1 or θ 2 .Factor B is assigned randomly to the samples of θ 1 and θ 2 .We test for effects of factors A and B as well as their interactions.Since the joint κ ≈ 7.5, the large κ method is used.As expected from the setup, we find a significant effect of factor A (P < 0.001), but no effect of factor B and no interaction effect.

Measures of association
In this section, we describe two functions implemented in CircStat that can be used to study questions of association where angular data is involved.The first kind of situation is where the correlation between two circular variables is to be assessed, as for example in Berens, Keliris, Ecker, Logothetis, and Tolias (2008), where we used to two different signal-multi-unit spiking activity and local field potentials-and computed the preferred orientation of a visual stimulus for both of them.We used circular-circular correlation to study the relationship between the two signals.The second situation is where the association between a linear and a circular variable is of interest.In Berens et al. (2008), we might have been interested in the relationship between preferred orientation of a site and position of the stimulus on the screen.For illustrations in this section, we resort again to the example shown in Figure 1.
Circular-circular correlation Correlation between two directional variables can be assessed by computing a correlation coefficient ρ cc (Jammalamadaka and Sengupta 2001, p. 176) by , where α and β denote two samples of angular data and ᾱ the angular mean.Significance of this correlation can be assessed by computing a p-value for ρ cc .Under the null hypothesis of no correlation, the test statistic t = f • ρ cc , follows a standard normal distribution.The term f is given by .
In CircStat, the correlation between two circular samples is computed by >> [c,p] = circ_corrcc(alpha, beta); For the example datasets α and β, this results in a highly significant correlation of ρ cc = 0.67 with P = 0.007 as both samples are ordered (see Figure 3a).

Circular-linear correlation
The linear association between a directional random variable α and a linear variable x can be assessed by correlating x with cos α and sin α individually .To this end, we define the correlation coefficients r sx = c(sin α, x),r cx = c(cos α, x) and r cs = c(sin α, cos α), where c(x, y) is the Pearson correlation coefficient.Then the circularlinear correlation ρ cl is defined as (Zar 1999, Equation 27.47) A p-value for ρ cl is computed by considering the test statistic N ρ 2 , which follows a χ 2distribution with two degrees of freedom.
In CircStat, the correlation between a circular and a linear samples is computed by >> [c,p] = circ_corrcl(alpha, x); In the example, if we correlate α and β with their indices 1:20, we obtain a slightly higher correlation for β (ρ β cl = 0.71 vs. ρ α cl = 0.64) with both correlations being significant (P β = 0.006, P α = 0.017 (see Figure 3b).This is because α is somewhat more peaked than β.

The von Mises distribution
The most common unimodal circular distribution is the von Mises distribution V M (µ, κ), which can be considered a circular analogue of the normal distribution.Its probability density function if given by where I 0 is the modified Bessel function of order zero.
In CircStat, samples can be drawn using >> p = circ_vmpdf(mu,kappa,1000); Finally, we can estimate the parameters of a von Mises distribution via maximum likelihood as μ = ᾱ and κ via the approximation given by Fisher (1995, Section 4.5.5).

a b c
Figure 4: Orientation tuning curves of three neurons recorded in the primary visual cortex of an awake macaque monkey, while the monkey was watching a visual stimulus consisting of sinusoidal gratings at any of eight different orientations.Neurons were recorded extracellularly using tetrodes.Black lines indicate the orientation tuning curves of the neurons, red lines the mean resultant vectors.

Application to neuroscience
In this section, we provide an exemplar analysis of a set of angular data as it occurs frequently in neuroscience.Individual neurons recorded in the visual cortex of many animals show orientation tuning, i.e., they respond more vigorously to stimuli of a certain orientation.We analyze the tuning properties of three neurons recorded2 in the primary visual cortex of an awake monkey (Figure 4).
The dataset consists of a vector θ of eight orientations 0, 22.5, . . ., 167.5 deg that were shown to the animal during the experiment and vectors s i (i = 1, 2, 3) containing the number of action potentials that were emitted by neuron i in response to a particular orientation.To subject this dataset to analysis with the methods described in this paper, we treat it as if the spikes had been binned to the presented orientations using θ as the angular variable and s i as the associated weights.Since the data is axial, we multiply each orientation by two.In Figure 4, we show the responses of the three neurons as a function of orientation.
Visually, we find that all three neurons show clear orientation tuning, where neuron 4a is tuned to almost the opposite direction as neurons 4b and c.Accordingly, the angular mean of neuron 4a lies almost 180 deg opposite of the angular mean of the other two neurons (for an overview over descriptive measures see Table 1).We confirm that the deviations from circular uniformity are highly significant for all three neurons, both when assessed with the Rayleigh test and the Omnibus test (P < 10 −10 ).Using the Watson-Williams test, we detect significant differences between the preferred orientation of the three cells (P = 0.0002, F = 12.89, 3 groups).To determine which cells have significantly different preferred orientations, we perform pairwise comparisons between cells.We find that neurons 4b and 4c dot not have significantly different preferred orientations (P = 0.339).Comparisons between the other pairs yield highly significant p-values, but violate the assumptions of the Watson-Williams test concerning the shared resultant vector length.Upon initial inspection, neuron 4a seems to be more broadly tuned to orientation than the two other cells.As measured by the angular deviation s, neuron 4c is the most narrowly tuned cell, followed by neuron 4b.Cell 4a has almost twice the angular deviation the the two other neurons.All cells have symmetric tuning curves, with normalized skewness values b 0 between 0.136 and −0.052.Neurons 4a is much less peaked than a comparable von Mises distribution as indicated by the low value of k 0 .

Conclusion
In this paper, we described the CircStat toolbox for performing statistical analysis of circular and directional data in MATLAB.The functions cover a wide range of applications from descriptive and inferential statistics.We supply the reader with parametric and nonparametric methods for testing a variety of hypothesis about circular data including testing of circular uniformity as well as one-and two-factor ANOVA testing.We believe that this toolbox will make circular statistics available to a wider range of researchers, especially in applied fields of biomedical research.

Figure 1 :
Figure 1: Example datasets α (a,b) and β (c,d) used throughout the paper.Both datasets consist of N = 20 samples.In a and c, data is shown as points on the unit circle.In b and d, angular histograms are shown.Red lines indicate the direction and magnitude of the mean resultant vector.Grey lines in c serve to illustrate the cosine and sine component of an angular datapoint.

Figure 3 :
Figure3: (a) Datasets α and β plotted against each other as if they had been obtained as paired samples.(b) α (red) and β (black) plotted against their indices 1, . . ., 20. β shows a slightly higher linear association with its index, since it is less peaked.

Table 1 :
Results from descriptive statistics for the three neurons studied in Section 6. Abbreviations conform to those introduced in Section 2.