Title: | Circular Statistics |
---|---|
Description: | Circular Statistics, from "Topics in circular Statistics" (2001) S. Rao Jammalamadaka and A. SenGupta, World Scientific. |
Authors: | Ulric Lund [aut], Claudio Agostinelli [aut] , Hiroyoshi Arai [ctb], Alessando Gagliardi [ctb], Eduardo García-Portugués [ctb, cre] , Dimitri Giunchi [ctb], Jean-Olivier Irisson [ctb], Matthew Pocernich [ctb], Federico Rotolo [ctb] |
Maintainer: | Eduardo García-Portugués <[email protected]> |
License: | GPL-2 |
Version: | 0.5-1 |
Built: | 2024-11-28 06:45:07 UTC |
Source: | CRAN |
Operators act on vectors and matrices to extract or replace subsets, methods for Circular Data.
## S3 method for class 'circular' x[i, ...]
## S3 method for class 'circular' x[i, ...]
x |
object from which to extract elements. |
i , ...
|
elements to extract or replace. |
Claudio Agostinelli
x <- circular(matrix(rwrappednormal(n=100, mu=circular(0)), nrow=5)) dim(x) x[1,] x[,1] x[,1, drop=FALSE]
x <- circular(matrix(rwrappednormal(n=100, mu=circular(0)), nrow=5)) dim(x) x[1,] x[,1] x[,1, drop=FALSE]
Evaluates the first and zeroth order Bessel functions of the first kind at a specified non-negative real number, and returns the ratio.
A1(kappa)
A1(kappa)
kappa |
non-negative numeric value at which to evaluate the Bessel functions. |
The function uses besselI
.
If I1(kappa) is the first order Bessel function and I0(kappa) is the zeroth order Bessel function, then A1(kappa) returns I1(kappa)/I0(kappa).
Claudio Agostinelli
Evaluates the first derivative of the Ratio of First and Zeroth Order Bessel Functions
A1FirstDerivative(kappa)
A1FirstDerivative(kappa)
kappa |
non-negative numeric value at which to evaluate the first derivative of A1 function. |
The formula (3.48) of Fisher (1993), pag. 52 is implemented.
The function uses A1
and besselI
.
The value of the first derivative of A1 function in the point kappa
.
Claudio Agostinelli and Alessandro Gagliardi.
N.I. Fisher (1993) Statistical Analysis of Circular Data, Cambridge University Press.
Inverse function of the ratio of the first and zeroth order Bessel functions of the first kind. This function is used to compute the maximum likelihood estimate of the concentration parameter of a von Mises distribution.
A1inv(x)
A1inv(x)
x |
numeric value in the interval between 0 and 1. |
A1inv(0) = 0 and A1inv(1) = Inf. This function is useful in estimating the concentration parameter of data from a von Mises distribution. Our function use the results in Best and Fisher (1981). Tables use tabulated values by Gumbel, Greenwood and Durand (1953).
Returns the value k, such that A1inv(x) = k, i.e. A1(k) = x.
Claudio Agostinelli
BEST, D.J. and FISHER, N.I. 1981. The bias of the maximum likelihood estimators for the von Mises-Fisher concentration parameters. Communications in Statistics, 10, 493-502.
GUMBEL, E.J., GREENWOOD, J.A. AND DURAND, D. 1953. The circular normal distribution: theory and tables. J. Amer. Statis. Assoc., 48, 131-152.
#Generate data from a von Mises distribution data <- rvonmises(n=50, mu=circular(pi), kappa=4) #Estimate the concentration parameter s <- sum(sin(data)) c <- sum(cos(data)) mean.dir <- atan2(s, c) kappa <- A1inv(mean(cos(data - mean.dir)))
#Generate data from a von Mises distribution data <- rvonmises(n=50, mu=circular(pi), kappa=4) #Estimate the concentration parameter s <- sum(sin(data)) c <- sum(cos(data)) mean.dir <- atan2(s, c) kappa <- A1inv(mean(cos(data - mean.dir)))
Evaluates the second derivative of the second derivative of the Ratio of First and Zeroth Order Bessel Functions.
A1SecondDerivative(kappa)
A1SecondDerivative(kappa)
kappa |
non-negative numeric value at which to evaluate the second derivative of A1 function. |
Formula (3.49) of Fisher (1993), pag. 52 is implemented.
The function uses A1
, A1FirstDerivative
and besselI
.
The value of the second derivative of A1 function in the point kappa
.
Claudio Agostinelli and Alessandro Gagliardi.
N.I. Fisher (1993) Statistical Analysis of Circular Data, Cambridge University Press.
A1
, A1FirstDerivative
, besselI
, A1inv
.
Returns the square root of twice one minus the mean resultant length divided by the sample size of a vector of circular data.
angular.deviation(x, na.rm = FALSE)
angular.deviation(x, na.rm = FALSE)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
Returns the square root of twice one minus the mean resultant length divided by the sample size.
Claudio Agostinelli
Batschelet, E. (1981) Circular Statistics in Biology. Academic Press, London.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
Zar, J.H. (2010) Biostatistical Analysis. Fifth edition. Pearson Educational International.
sd.circular
, angular.variance
, mean.circular
, rho.circular
and summary.circular
.
x <- rvonmises(n=100, mu=circular(0), kappa=1) angular.deviation(x)
x <- rvonmises(n=100, mu=circular(0), kappa=1) angular.deviation(x)
Returns twice one minus the mean resultant length divided by the sample size of a vector of circular data.
angular.variance(x, na.rm = FALSE)
angular.variance(x, na.rm = FALSE)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
Returns twice one minus the mean resultant length divided by the sample size.
Claudio Agostinelli
Batschelet, E. (1981) Circular Statistics in Biology. Academic Press, London.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
Zar, J.H. (2010) Biostatistical Analysis. Fifth edition. Pearson Educational International.
var.circular
, angular.deviation
, mean.circular
, rho.circular
and summary.circular
.
x <- rvonmises(n=100, mu=circular(0), kappa=1) angular.variance(x)
x <- rvonmises(n=100, mu=circular(0), kappa=1) angular.variance(x)
One Critrion Analysis of Variance for circular data
aov.circular(x, group, kappa = NULL, method = c("F.test", "LRT"), F.mod = TRUE, control.circular=list()) ## S3 method for class 'aov.circular' print(x, digits = max(3, getOption("digits") - 3), ...)
aov.circular(x, group, kappa = NULL, method = c("F.test", "LRT"), F.mod = TRUE, control.circular=list()) ## S3 method for class 'aov.circular' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
a vector of class |
group |
a vector identifying the groups or samples. |
kappa |
the common value of the concentration parameter. Used
when |
method |
the test statistic to use; either a high-concentration F-test or a likelihood ratio test. |
F.mod |
logical; if |
control.circular |
the coordinate system used in the output for the objects |
digits |
the number of digits to be printed. |
... |
additional arguments. |
The samples are assumed to have been drawn from von Mises populations with equal concentration parameter, kappa. The null hypothesis being tested is that all populations also have the same mean direction.
If method
is "F.test"
a high concentration F-test makes use
of a decomposition of total sample variation into between groups and within
groups variation, analogous to the one-way classification analysis of variance
for linear data. Stephens (1972) presented an improved modification to the
F-test derived from this decomposition. This is implemented when F.mod
is TRUE
.
A likelihood ratio test is performed when method
is "LRT"
. This
function uses the test statistic presented by Cordeiro, Paula, and Botter (1994) which has
an approximate chi-squared distribution. If the common concentration parameter
is known, it can be specified and used in the computation of the test statistic.
Otherwise, the maximum likelihood estimate of the common concentration parameter is used.
An object of class aov.circular
with the following components:
mu |
mean direction for each sample with class |
mu.all |
mean direction of all samples combined with class |
kappa |
concentration parameter for each sample. |
kappa.all |
concentration parameter for all samples combined. |
rho |
mean resultant length for each sample. |
rho.all |
mean resultant length for all samples combined. |
method |
the test statistic used. |
df |
degrees of freedom. |
statistic |
the value of the test statistic. |
p.value |
the p.value of the test statistic. |
call |
the |
If the method
is "F.test"
then the object contains also:
SSE |
Sum of squares used in F-test. |
MSE |
Mean squares used in F-test. |
Claudio Agostinelli and Ulric Lund
Cordeiro, G., Paula, G. and Botter, D. (1994). Improved likelihood ratio tests for dispersion models. International Statistical Review, 62, 257-274.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 5.3, World Scientific Press, Singapore.
Mardia, K. and Jupp, P. (1999). Directional Statistics, Section 7.4, John Wiley and Sons, England.
Stephens, M. (1972). Multi-sample tests for the von Mises distribution. Technical Report 190, Department of Statistics, Stanford University.
x <- c(rvonmises(50, circular(0), 1), rvonmises(100, circular(pi/3), 10)) group <- c(rep(0, 50), rep(1, 100)) aov.circular(x, group) aov.circular(x, group, method="LRT")
x <- c(rvonmises(50, circular(0), 1), rvonmises(100, circular(pi/3), 10)) group <- c(rep(0, 50), rep(1, 100)) aov.circular(x, group) aov.circular(x, group, method="LRT")
Draw arrows in a circular plot.
arrows.circular(x, y = NULL, x0 = 0, y0 = 0, na.rm = FALSE, shrink = 1, plot.info = NULL, zero = NULL, rotation = NULL, ...)
arrows.circular(x, y = NULL, x0 = 0, y0 = 0, na.rm = FALSE, shrink = 1, plot.info = NULL, zero = NULL, rotation = NULL, ...)
x |
a vector. The object is coerced to class |
y |
a vector with the same length as |
x0 |
a vector of origins (x axis). |
y0 |
a vector of origins (y axis). |
na.rm |
logical, indicating if |
shrink |
parameter that controls the size of the plotted circle. Default is 1. Larger values shrink the circle, while smaller values enlarge the circle. |
plot.info |
an object from |
zero |
the zero used in the plot. Ignored if |
rotation |
the rotation used in the plot. Ignored if |
... |
further parameters passed to |
The function call arrows
and it is not a method of arrows
.
Claudio Agostinelli
plot(rvonmises(10, circular(0), kappa=1)) arrows.circular(rvonmises(10, circular(0), kappa=1)) arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10), col=2) arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10), x0=runif(10, -1, 1), y0=runif(10, -1, 1), col=3)
plot(rvonmises(10, circular(0), kappa=1)) arrows.circular(rvonmises(10, circular(0), kappa=1)) arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10), col=2) arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10), x0=runif(10, -1, 1), y0=runif(10, -1, 1), col=3)
This function is a method of as.data.frame
for a circular object.
## S3 method for class 'circular' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
## S3 method for class 'circular' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
object of class |
row.names |
|
optional |
logical; if |
... |
additional arguments to be passed to or from methods. |
Claudio Agostinelli
Density the Asymmetric Triangular circular distribution.
dasytriangular(x, rho)
dasytriangular(x, rho)
x |
a vector. The object is coerced to class |
rho |
concentration parameter of the distribution. rho must be
between 0 and |
dasytriangular
gives the density.
Claudio Agostinelli
Mardia (1972) Statistics for Directional Data, Wiley. Pag. 52
ff <- function(x) dasytriangular(x, rho=0.3) curve.circular(ff, shrink=1.2, join=TRUE)
ff <- function(x) dasytriangular(x, rho=0.3) curve.circular(ff, shrink=1.2, join=TRUE)
Density for the axial von Mises circular distribution.
daxialvonmises(x, mu, kappa, l = 2)
daxialvonmises(x, mu, kappa, l = 2)
x |
a vector. The object is coerced to class |
mu |
mean direction of the distribution. The object is coerced to class |
kappa |
non-negative numeric value for the concentration parameter of the distribution. |
l |
a positive number. |
daxialvonmises
gives the density.
Claudio Agostinelli
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.4, World Scientific Press, Singapore.
Add axis to a plot of circular data points on the current graphics device.
axis.circular(at=NULL, labels=NULL, units = NULL, template=NULL, modulo=NULL, zero=NULL, rotation=NULL, tick=TRUE, lty, lwd, cex, col, font, tcl=0.025, tcl.text=0.125, digits=2)
axis.circular(at=NULL, labels=NULL, units = NULL, template=NULL, modulo=NULL, zero=NULL, rotation=NULL, tick=TRUE, lty, lwd, cex, col, font, tcl=0.025, tcl.text=0.125, digits=2)
at |
the points at which tick-marks are to be drawn. If |
labels |
a vector of character strings to be placed at the
tickpoints. If |
units |
either |
template |
either |
modulo |
either |
zero |
the zero of the plot (in radians, counterclockwise). If |
rotation |
the rotation of the plot. If |
tick |
logical: if |
lty , lwd
|
line type, width for the tick marks. If missing means to use ‘par("lty")’ and ‘par("lwd")’. |
cex |
a numerical value giving the amount by which plotting text and symbols should be scaled relative to the default. |
col |
color for the the tick marks. If missing means to use ‘par("col.axis")’. |
font |
font for text. If missing means to use ‘par("font.axis")’. |
tcl |
The length of tick marks. |
tcl.text |
The position of the axis labels. |
digits |
number of digits used to print axis values. |
Claudio Agostinelli
plot.circular
and ticks.circular
.
data.vm <- rvonmises(n=100, mu=circular(0), kappa=3) plot(data.vm, axes=FALSE, ticks=FALSE) axis.circular(at=circular(seq(0, 11/6*pi, pi/6)), labels=c("0", expression(frac(pi,6)), expression(paste(frac(1,3), pi)), expression(frac(pi,2)), expression(paste(frac(2,3), pi)), expression(paste(frac(5,6), pi)), expression(pi), expression(paste(frac(7,6), pi)), expression(paste(frac(4,3), pi)), expression(paste(frac(3,2), pi)), expression(paste(frac(5,3), pi)), expression(paste(frac(11,6), pi))))
data.vm <- rvonmises(n=100, mu=circular(0), kappa=3) plot(data.vm, axes=FALSE, ticks=FALSE) axis.circular(at=circular(seq(0, 11/6*pi, pi/6)), labels=c("0", expression(frac(pi,6)), expression(paste(frac(1,3), pi)), expression(frac(pi,2)), expression(paste(frac(2,3), pi)), expression(paste(frac(5,6), pi)), expression(pi), expression(paste(frac(7,6), pi)), expression(paste(frac(4,3), pi)), expression(paste(frac(3,2), pi)), expression(paste(frac(5,3), pi)), expression(paste(frac(11,6), pi))))
Bandwidth selectors for circular kernels in density.circular
.
bw.cv.mse.circular(x, lower=NULL, upper=NULL, tol = 1e-4, kernel = c("vonmises", "wrappednormal"), K = NULL, min.k = 10) bw.cv.ml.circular(x, lower=NULL, upper=NULL, tol = 1e-4, kernel = c("vonmises", "wrappednormal"), K = NULL, min.k = 10) bw.nrd.circular(x, lower=NULL, upper=NULL, kappa.est=c("ML","trigmoments"), kappa.bias=FALSE, P=3)
bw.cv.mse.circular(x, lower=NULL, upper=NULL, tol = 1e-4, kernel = c("vonmises", "wrappednormal"), K = NULL, min.k = 10) bw.cv.ml.circular(x, lower=NULL, upper=NULL, tol = 1e-4, kernel = c("vonmises", "wrappednormal"), K = NULL, min.k = 10) bw.nrd.circular(x, lower=NULL, upper=NULL, kappa.est=c("ML","trigmoments"), kappa.bias=FALSE, P=3)
x |
the data from which the bandwidth is to be computed. The object is coerced to class |
lower , upper
|
range over which to minimize for cross validatory bandwidths. The default is almost always satisfactory, although it is recommended experiment a little with different ranges. A warning message indicates if the resulting bandwidth is too near to the endpoints of the interval search. |
tol |
for cross validatory bandwidths, the convergence tolerance for |
kernel |
a character string giving the smoothing kernel to be used. This must be one of |
K |
number of terms to be used in approximating the wrappednormal density. See |
min.k |
minimum number of terms used in approximating the
wrappednormal density. See |
kappa.est |
a numerical value or one available method. |
kappa.bias |
logical. If |
P |
integer, the maximum order of the sample trigonometric
moments used in the estimation of |
bw.cv.mse.circular
and bw.cv.ml.circular
implement cross validatory bandwidths minimizing squared–error loss and Kullback–Leibler loss, respectively. This is done by minimizing the second and third equations in section 5 of Hall, Watson and Cabrera (1987). Kullback–Leibler loss is equivalent to maximize the cross validation log–likelihood with respect to the bandwidth parameter.
bw.nrd.circular
implements a rule-of-thumb for choosing the
bandwidth of a von Mises kernel density estimator with underlying
population von Mises. It was proposed by Taylor (2008, equation (7)) and
is the circular analogue of the usual rule of thumb used for the normal
distribution. The only remarkable difference between them is that
Taylor's bandwidth supposes a von Mises population for the derivation of
AMISE, while normal rule of thumb only introduces distribution
assumption to compute the density curvature. Estimation of the spread is
done by maximum likelihood. The "trigmoments" method for the estimation of
kappa
is implemented as follows. Let be the p-th
sample trigonometric moment. Let
be the estimates of
kappa
using the p-th sample trigonometric moment, as solution
(using uniroot
function) of the equation . We let
kappa
equal to
, see Taylor (2008) for further details.
Note that circular bandwidth has a different scale from linear bandwidth (see Hall, Watson and Cabrera (1987)). The behaviour of the circular bandwidth is the inverse of the linear: large values overestimate the density, whereas small values underestimate.
A bandwidth on a scale suitable for the bw
argument
of density.circular
.
Plug-in bandwidth selector bw.nrd.circular
assumes that the
underlying population is von Mises. If this is not true, it might lead
to serious misestimations of the circular bandwidth. Example 2 below
shows how this behaviour can appear with multimodality populations. In
those cases, the use of kappa.est="trigmoments"
could be of help.
Claudio Agostinelli and Eduardo Garcia–Portugues
P. Hall and G.S. Watson and J. Cabrera (1987). Kernel Density Estimation with Spherical Data, Biometrika, 74, 4, 751–762.
C.C Taylor (2008). Automatic bandwidth selection for circular density estimation. Computational Statistics and Data Analysis, 52, 7, 3493–3500.
set.seed(12345) ## Example 1: von Mises ## theta1 <- rvonmises(n=150,mu=circular(pi),kappa=2) bw.nrd1 <- bw.nrd.circular(theta1) bw.cv.mse1 <- bw.cv.mse.circular(theta1) bw.cv.ml1 <- bw.cv.ml.circular(theta1) ## Linear plot plot(function(x) dvonmises(circular(x), mu=circular(pi), kappa=2), type="l", lwd=2, col=1, main="von Mises", xlab=expression(theta), ylab="Density", from=0, to=2*pi) plot(approxfun(density.circular(x=theta1, bw=bw.nrd1)), col=2, from=0, to=2*pi, add=TRUE) plot(approxfun(density.circular(x=theta1, bw=bw.cv.mse1)), col=3, from=0, to=2*pi, add=TRUE) plot(approxfun(density.circular(x=theta1, bw=bw.cv.ml1)), col=4, from=0, to=2*pi, add=TRUE) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) rug(theta1) ## Circular plot dvonmises1 <- function(x) dvonmises(circular(x), mu=circular(pi), kappa=2) curve.circular(dvonmises1, lwd=2, col=1, main="von Mises", xlim=c(-1.5, 1.5), ylim=c(-1.5,1.5)) lines(density.circular(x=theta1, bw=bw.nrd1), col=2) lines(density.circular(x=theta1, bw=bw.cv.mse1), col=3) lines(density.circular(x=theta1, bw=bw.cv.ml1), col=4) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) points(theta1) ## Example 2: mixture of von Mises ## theta2 <- rmixedvonmises(n=150, mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5,p=0.5) bw.nrd2 <- bw.nrd.circular(theta2) bw.cv.mse2 <- bw.cv.mse.circular(theta2) bw.cv.ml2 <- bw.cv.ml.circular(theta2) ## Linear plot plot(function(x) dmixedvonmises(circular(x), mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5, p=0.5), type="l", lwd=2, col=1, main="mixture of von Mises", xlab=expression(theta), ylab="Density", from=0, to=2*pi) lines(density.circular(x=theta2, bw=bw.nrd2), plot.type='line', col=2) lines(density.circular(x=theta2, bw=bw.cv.mse2), plot.type='line', col=3) lines(density.circular(x=theta2, bw=bw.cv.ml2), plot.type='line', col=4) rug(theta2) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) ## Circular plot dmixedvonmises1 <- function(x) dmixedvonmises(circular(x), mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5, p=0.5) curve.circular(dmixedvonmises1, join=TRUE, xlim=c(-1.5, 1.5), ylim=c(-1.5, 1.5), lwd=2, col=1, main="mixture of von Mises") lines(density.circular(x=theta2, bw=bw.nrd2), col=2) lines(density.circular(x=theta2, bw=bw.cv.mse2), col=3) lines(density.circular(x=theta2, bw=bw.cv.ml2), col=4) points(theta2) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) ## Example 3: mixture of von Mises and Wrapped Cauchy ## rmixture <- function(n){ x <- circular(sapply(runif(n), function(u) ifelse(u>0.5, rvonmises(n=1, mu=circular(pi),kappa=10), rwrappedcauchy(n=1,mu=circular(pi/2),rho=0.75)))) return(x) } theta3 <- rmixture(n=150) bw.nrd3 <- bw.nrd.circular(theta3) bw.cv.mse3 <- bw.cv.mse.circular(theta3, lower=0.1, upper=100) bw.cv.ml3 <- bw.cv.ml.circular(theta3, lower=0.1, upper=100) dmixture <- function(x) (dvonmises(x, mu=circular(pi), kappa=10)+dwrappedcauchy(x, mu=circular(pi/2), rho=0.75))/2 curve.circular(dmixture, join=TRUE, xlim=c(-1.5, 1.5), ylim=c(-1.5, 1.5), lwd=2, col=1, main="mixture of von Mises and Wrapped Normal") lines(density.circular(x=theta3, bw=bw.nrd3), col=2) lines(density.circular(x=theta3, bw=bw.cv.mse3), col=3) lines(density.circular(x=theta3, bw=bw.cv.ml3), col=4) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) points(theta3)
set.seed(12345) ## Example 1: von Mises ## theta1 <- rvonmises(n=150,mu=circular(pi),kappa=2) bw.nrd1 <- bw.nrd.circular(theta1) bw.cv.mse1 <- bw.cv.mse.circular(theta1) bw.cv.ml1 <- bw.cv.ml.circular(theta1) ## Linear plot plot(function(x) dvonmises(circular(x), mu=circular(pi), kappa=2), type="l", lwd=2, col=1, main="von Mises", xlab=expression(theta), ylab="Density", from=0, to=2*pi) plot(approxfun(density.circular(x=theta1, bw=bw.nrd1)), col=2, from=0, to=2*pi, add=TRUE) plot(approxfun(density.circular(x=theta1, bw=bw.cv.mse1)), col=3, from=0, to=2*pi, add=TRUE) plot(approxfun(density.circular(x=theta1, bw=bw.cv.ml1)), col=4, from=0, to=2*pi, add=TRUE) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) rug(theta1) ## Circular plot dvonmises1 <- function(x) dvonmises(circular(x), mu=circular(pi), kappa=2) curve.circular(dvonmises1, lwd=2, col=1, main="von Mises", xlim=c(-1.5, 1.5), ylim=c(-1.5,1.5)) lines(density.circular(x=theta1, bw=bw.nrd1), col=2) lines(density.circular(x=theta1, bw=bw.cv.mse1), col=3) lines(density.circular(x=theta1, bw=bw.cv.ml1), col=4) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) points(theta1) ## Example 2: mixture of von Mises ## theta2 <- rmixedvonmises(n=150, mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5,p=0.5) bw.nrd2 <- bw.nrd.circular(theta2) bw.cv.mse2 <- bw.cv.mse.circular(theta2) bw.cv.ml2 <- bw.cv.ml.circular(theta2) ## Linear plot plot(function(x) dmixedvonmises(circular(x), mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5, p=0.5), type="l", lwd=2, col=1, main="mixture of von Mises", xlab=expression(theta), ylab="Density", from=0, to=2*pi) lines(density.circular(x=theta2, bw=bw.nrd2), plot.type='line', col=2) lines(density.circular(x=theta2, bw=bw.cv.mse2), plot.type='line', col=3) lines(density.circular(x=theta2, bw=bw.cv.ml2), plot.type='line', col=4) rug(theta2) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) ## Circular plot dmixedvonmises1 <- function(x) dmixedvonmises(circular(x), mu1=circular(pi/2), mu2=circular(3*pi/2), kappa1=5, kappa2=5, p=0.5) curve.circular(dmixedvonmises1, join=TRUE, xlim=c(-1.5, 1.5), ylim=c(-1.5, 1.5), lwd=2, col=1, main="mixture of von Mises") lines(density.circular(x=theta2, bw=bw.nrd2), col=2) lines(density.circular(x=theta2, bw=bw.cv.mse2), col=3) lines(density.circular(x=theta2, bw=bw.cv.ml2), col=4) points(theta2) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) ## Example 3: mixture of von Mises and Wrapped Cauchy ## rmixture <- function(n){ x <- circular(sapply(runif(n), function(u) ifelse(u>0.5, rvonmises(n=1, mu=circular(pi),kappa=10), rwrappedcauchy(n=1,mu=circular(pi/2),rho=0.75)))) return(x) } theta3 <- rmixture(n=150) bw.nrd3 <- bw.nrd.circular(theta3) bw.cv.mse3 <- bw.cv.mse.circular(theta3, lower=0.1, upper=100) bw.cv.ml3 <- bw.cv.ml.circular(theta3, lower=0.1, upper=100) dmixture <- function(x) (dvonmises(x, mu=circular(pi), kappa=10)+dwrappedcauchy(x, mu=circular(pi/2), rho=0.75))/2 curve.circular(dmixture, join=TRUE, xlim=c(-1.5, 1.5), ylim=c(-1.5, 1.5), lwd=2, col=1, main="mixture of von Mises and Wrapped Normal") lines(density.circular(x=theta3, bw=bw.nrd3), col=2) lines(density.circular(x=theta3, bw=bw.cv.mse3), col=3) lines(density.circular(x=theta3, bw=bw.cv.ml3), col=4) legend("topright", legend=c("True", "Taylor", "LSCV", "MLCV"), col=1:4, lwd=2) points(theta3)
A method for circular object, which combines its arguments
## S3 method for class 'circular' c(..., recursive = FALSE)
## S3 method for class 'circular' c(..., recursive = FALSE)
... |
vectors, the first of which of class |
recursive |
logical. If 'recursive=TRUE', the function recursively descends through lists combining all their elements into a vector. |
Claudio Agostinelli
x <- rvonmises(10, circular(0), 10) y <- rvonmises(10, circular(0), 10, control.circular=list(units="degrees")) z <- runif(10, 0, 20) # here you do not use circular properties, #####but you mean it is measured in degrees c(x, y, z) # While y is converted in radians, z is treated as it was!
x <- rvonmises(10, circular(0), 10) y <- rvonmises(10, circular(0), 10, control.circular=list(units="degrees")) z <- runif(10, 0, 20) # here you do not use circular properties, #####but you mean it is measured in degrees c(x, y, z) # While y is converted in radians, z is treated as it was!
Density and random generation for the Cardioid circular distribution.
dcardioid(x, mu = circular(0), rho = 0) rcardioid(n, mu = circular(0), rho = 0, control.circular=list())
dcardioid(x, mu = circular(0), rho = 0) rcardioid(n, mu = circular(0), rho = 0, control.circular=list())
x |
a vector. The object is coerced to class |
n |
number of observations. |
mu |
mean direction of the distribution. The object is coerced to class |
rho |
concentration parameter of the distribution. Absolute value of |
control.circular |
the coordinate system used in the output of |
dcardioid
gives the density and rcardioid
generates random deviates.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.2, World Scientific Press, Singapore.
set.seed(1234) resrad <- rcardioid(n=10) set.seed(1234) resdeg <- rcardioid(n=10, control.circular=list(units="radians", zero=pi)) max(abs(resrad - conversion.circular(resdeg, zero=0)))
set.seed(1234) resrad <- rcardioid(n=10) set.seed(1234) resdeg <- rcardioid(n=10, control.circular=list(units="radians", zero=pi)) max(abs(resrad - conversion.circular(resdeg, zero=0)))
Density for the Carthwrite's power-of-cosine distribution.
dcarthwrite(x, mu, psi)
dcarthwrite(x, mu, psi)
x |
a vector. The |
mu |
the location angular parameter. The object is coerced to class |
psi |
the positive shape parameter. |
The Carthwrite's power-of-cosine distribution has density
for .
The density
Federico Rotolo
Carthwrite, D.E. (1963). The use of directional spectra in studying the output of a wave recorder on a moving ship. Ocean Wave Spectra , 203-218.
Tests for a change in mean direction, concentration, or both, given a set of directional data points.
change.point(x)
change.point(x)
x |
a vector. The object is coerced to class |
In either context, the user can choose which statistic (max or ave) to use, and then consult the appropriate table provided in the book referenced below. The critical values for these 4 statistics are to be found in Table 11.3 (or Figure 11.3) for rmax, Table 11.4 (or Figure 11.4) for rave, Figure 11.5 for tmax and Figure 11.6 for tave.
Returns a list with variables n, rho, rmax, k.r, rave, tmax, k.t, and tave. The first of these is the sample size, followed by the overall mean resultant length. Both of these are needed to enter any of the tables or nomograms (see under Details). The other values represent the change point test statistics. While rmax and rave test for a change in mean direction (with unknown concentration), tmax and tave are useful in the context of testing more generally, for a change in mean direction and/or concentration. k.r and k.t are the observation numbers for which rmax and tmax attain their maximum value and indicate the observation at which the change is most likely to have occurred, when the tables or nomograms indicate significance.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Chapter 11, World Scientific Press, Singapore.
Auxiliary function as user interface for circular plots. Typically only used when calling plot.circular.
circle.control(n = 1000, type = "l", col = 1, bg = par("bg"), pch = 1, cex = 1, lty = 1, lwd = 1)
circle.control(n = 1000, type = "l", col = 1, bg = par("bg"), pch = 1, cex = 1, lty = 1, lwd = 1)
n |
number of points used to interpolate the circle |
type |
1-character string giving the type of plot desired. The following values are possible, for details, see |
col |
The color used. |
bg |
The color to be used for the background of the device region. |
pch |
Either an integer specifying a symbol or a single character to be used as the default in plotting points. See |
cex |
A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default. |
lty |
The line type. Line types can either be specified as an integer (0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or as one of the character strings "blank", "solid", "dashed", "dotted", "dotdash", "longdash", or "twodash", where "blank" uses 'invisible lines' (i.e., does not draw them). Alternatively, a string of up to 8 characters (from c(1:9, "A":"F")) may be given, giving the length of line segments which are alternatively drawn and skipped. See section 'Line Type Specification'. |
lwd |
The line width, a positive number, defaulting to 1. The interpretation is device-specific, and some devices do not implement line widths less than one. (See the help on the device for details of the interpretation.) |
Claudio Agostinelli
plot(rvonmises(10, circular(0), 1), control.circle=circle.control(col=2, lty=2))
plot(rvonmises(10, circular(0), 1), control.circle=circle.control(col=2, lty=2))
The function circular
is used to create circular objects. as.circular
and is.circular
coerce an object to a circular and test whether an object is a circular data.
circular(x, type = c("angles", "directions"), units = c("radians", "degrees", "hours"), template = c("none", "geographics", "clock12", "clock24"), modulo = c("asis", "2pi", "pi"), zero = 0, rotation = c("counter", "clock"), names) ## S3 method for class 'circular' as(x, control.circular=list(), ...) ## S3 method for class 'circular' is(x) ## S3 method for class 'circular' print(x, info=TRUE, ...)
circular(x, type = c("angles", "directions"), units = c("radians", "degrees", "hours"), template = c("none", "geographics", "clock12", "clock24"), modulo = c("asis", "2pi", "pi"), zero = 0, rotation = c("counter", "clock"), names) ## S3 method for class 'circular' as(x, control.circular=list(), ...) ## S3 method for class 'circular' is(x) ## S3 method for class 'circular' print(x, info=TRUE, ...)
x |
a vector or a matrix. If a data.frame is supply then it is coerced to a matrix. |
type |
the type of measures (Not Used Yet). |
units |
units of the measures. |
template |
how the data should be plotted. This set |
modulo |
if we need to reduce the measures to modulo. |
zero |
the zero of the axes (in radians, counter). |
rotation |
the orientation of the axes. |
names |
names of the data. |
info |
if |
control.circular |
the attribute (coordinate system) used to coerced the resulting objects. See |
... |
For |
an object of class circular
. Since version 0.3-5 the previous class of the object is retain.
Claudio Agostinelli
x <- circular(c(pi, pi/3, pi/4)) print(x) is.circular(x) x <- circular(runif(10, -pi/2, pi/2), template="geographics") plot(x) class(x) x <- circular(data.frame(runif(10, -pi/2, pi/2))) plot(x) class(x) cbind(x, x) # the matrix, cbind, rbind functions unclass and lost attributes! ########Use it with care. x <- c(pi/12,2*pi+pi/12) print(x) x <- unique(x) print(x) x[1]==x[2] all.equal(x[1], x[2]) x <- as.circular(pi, control.circular=list(units="radians", zero=pi)) y <- conversion.circular(circular(pi), zero=pi) res <- plot(x) points(y, col=2, plot.info=res)
x <- circular(c(pi, pi/3, pi/4)) print(x) is.circular(x) x <- circular(runif(10, -pi/2, pi/2), template="geographics") plot(x) class(x) x <- circular(data.frame(runif(10, -pi/2, pi/2))) plot(x) class(x) cbind(x, x) # the matrix, cbind, rbind functions unclass and lost attributes! ########Use it with care. x <- c(pi/12,2*pi+pi/12) print(x) x <- unique(x) print(x) x[1]==x[2] all.equal(x[1], x[2]) x <- as.circular(pi, control.circular=list(units="radians", zero=pi)) y <- conversion.circular(circular(pi), zero=pi) res <- plot(x) points(y, col=2, plot.info=res)
The package ‘circular’ provides functions for the statistical analysis and graphics representation of circular data (observations which are angles). It originally started as a porting from S-plus to R of functions developed for the book: Circular Statistics, from "Topics in circular Statistics" (2001) S. Rao Jammalamadaka and A. SenGupta, World Scientific. Now, it has an S3 implementation and several new functions and datasets.
The version level of the package is given by the command
packageDescription("circular")
.
The most recent version of the package can be obtained from
the R-Forge repository at https://r-forge.r-project.org/projects/circular/
Claudio Agostinelli, Department of Mathematics University of Trento, Italy (http://datascience.maths.unitn.it/~claudio/)
Ulric Lund, Department of Statistics, California Polytechnic State University, San Luis Obispo, California, USA (https://statistics.calpoly.edu/ulric-lund)
This package and its documentation are usable under the terms of the
"GNU General Public License", a copy of which is distributed with the
package. While the software is freely usable, it would be appreciated
if a reference is inserted in publications or other work
which makes use of it; for this purpose, see the command
citation("circular")
.
The package has evolved through several versions, developed over some years.
Many thanks to all that points out bugs, provide suggestions and comments.
The functions median
and medianHS
are developed together with
Alessandro Gagliardi mailto:[email protected]
The functions watson.wiliams.test
and wallraff.test
are
developed by Jean-Olivier Irisson (https://www.obs-vlfr.fr/~irisson/)
The functions dcarthwrite
, dgenvonmises
,
(d,r)katojones
, djonespewsey
are developed by Federico Rotolo
The function rose.diag
has contribution by Hiroyoshi Arai (mailto:[email protected])
The function windrose
is developed by Matthew Pocernich
Dataset swallows
is kindly provided by Dimitri Giunchi http://unimap.unipi.it/cercapersone/dettaglio.php?ri=2504&template=dettaglio.tpl
The function bw.circular
is developed together with Eduardo Garcia Portugues https://egarpor.github.io/
If I miss to report your contribution please let me know by email at mailto:[email protected]
Density and random generation for the Circular Uniform distribution on the whole circle.
dcircularuniform(x) rcircularuniform(n, control.circular=list())
dcircularuniform(x) rcircularuniform(n, control.circular=list())
x |
a vector. The object is not coerced to class |
n |
number of observations. |
control.circular |
the attribute of the resulting object. |
dcircularuniform
gives the density and rcircularuniform
generates random deviates.
Claudio Agostinelli
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.1, World Scientific Press, Singapore.
data1 <- rcircularuniform(100, control.circular=list(units="degrees")) plot(data1) curve.circular(dcircularuniform, join=TRUE, xlim=c(-1.2, 1.2), ylim=c(-1.2, 1.2), main="Density of a Circular Uniform Distribution")
data1 <- rcircularuniform(100, control.circular=list(units="degrees")) plot(data1) curve.circular(dcircularuniform, join=TRUE, xlim=c(-1.2, 1.2), ylim=c(-1.2, 1.2), main="Density of a Circular Uniform Distribution")
Create a vector of n
contiguous colors.
circular.colors(n, m = 0, M = 2 * pi, offset = 0, ...)
circular.colors(n, m = 0, M = 2 * pi, offset = 0, ...)
n |
the number of colors (>= 1) to be in the palette. |
m |
the smallest angle in radians. |
M |
the largest angle in radians. |
offset |
the zero in radians. |
... |
further arguments passed to the function |
a vector of length n
.
Claudio Agostinelli
circular.colors(n=10, m=0, M=2*pi)
circular.colors(n=10, m=0, M=2*pi)
‘circularp’ returns the ‘circularp’ attribute (or ‘NULL’). ‘circularp<-’ sets the ‘circularp’ attribute.
circularp(x) circularp(x) <- value
circularp(x) circularp(x) <- value
x |
a vector or a matrix of circular data. |
value |
a vector of length 6 or a list with six components: type, units, template, modulo, zero and rotation. |
The circularp
attribute is a list of six elements: type, units,
template, modulo, zero and rotation; see circular
for
their meaning.
Assignments are checked for consistency.
Assigning NULL
removes the circularp
attribute
and any "circular"
class of x
.
Claudio Agostinelli
x <- pi circularp(x) # now NULL circularp(x) <- list(type="angles", units="radians", template="none", modulo="asis", zero=0, rotation="counter") circularp(x) x class(x) <- "circular" # now we set also the class so that print.circular is used x
x <- pi circularp(x) # now NULL circularp(x) <- list(type="angles", units="radians", template="none", modulo="asis", zero=0, rotation="counter") circularp(x) x class(x) <- "circular" # now we set also the class so that print.circular is used x
Conversion for Circular Data from one coordinate/units system to another one. For back compatibility, without arguments the function converts data from degrees to radians.
conversion.circular(x, units = c("radians", "degrees", "hours"), type = NULL, template = NULL, modulo = NULL, zero = NULL, rotation = NULL)
conversion.circular(x, units = c("radians", "degrees", "hours"), type = NULL, template = NULL, modulo = NULL, zero = NULL, rotation = NULL)
x |
an object of class |
units |
unit of the transformed data. |
type |
type of the transformed data. If |
template |
template of the transformed data. If |
modulo |
modulo of the transformed data. If |
zero |
zero of the transformed data. If |
rotation |
rotation of the transformed data. If |
an object of class circular
with the specified unit of measure, modulo, zero and rotation.
Claudio Agostinelli
deg
and rad
. If you want to set the properties of an object instead to transform it, you can use circular
or circularp<-
.
x <- rvonmises(n=10, mu=circular(0), kappa=9, control.circular=list(units="degrees")) par(mfcol=c(2, 2)) plot(x) y <- conversion.circular(x) # only the unit is changed (to radians) and ####### the data converted. plot(y) z <- conversion.circular(x, units="degrees", zero=pi) # only the zero is changed and ####### the data converted. plot(z) w <- conversion.circular(x, zero=pi, rotation="clock") # zero and rotation is ####### changed and the data converted. plot(w)
x <- rvonmises(n=10, mu=circular(0), kappa=9, control.circular=list(units="degrees")) par(mfcol=c(2, 2)) plot(x) y <- conversion.circular(x) # only the unit is changed (to radians) and ####### the data converted. plot(y) z <- conversion.circular(x, units="degrees", zero=pi) # only the zero is changed and ####### the data converted. plot(z) w <- conversion.circular(x, zero=pi, rotation="clock") # zero and rotation is ####### changed and the data converted. plot(w)
A dataset taken from the paper of Coope (1993).
data(coope)
data(coope)
x.coope
and y.coope
are vectors of length 8.
Coope, I. (1993). Circle fitting by linear and non-linear least squares. Journal of Optimization Theory and Applications, 76, 381-388.
From coordinates of the end point of a vector in 2 dimensions to the angle between this vector and the x-axis
coord2rad(x, y = NULL, control.circular = list())
coord2rad(x, y = NULL, control.circular = list())
x |
a |
y |
a vector. |
control.circular |
the attribute of the resulting object. |
an object of class circular
Claudio Agostinelli and Frederick T. Wehrle
set.seed(1234) x <- cbind(rnorm(20), rnorm(20)) y <- coord2rad(x)
set.seed(1234) x <- cbind(rnorm(20), rnorm(20)) y <- coord2rad(x)
Computes a circular version of the Pearson's product moment correlation, and performs a significance test if requested.
cor.circular(x, y=NULL, test=FALSE)
cor.circular(x, y=NULL, test=FALSE)
x |
vector or matrix of circular data. |
y |
vector or matrix of circular data. |
test |
if |
The correlation coefficient is computed like Pearson's product moment correlation for two linear variables X and Y. In the computational formula, however, (xi - xbar) and (yi - ybar) are replaced by sin(xi - xbar) and sin(yi - ybar), where xbar and ybar in the second two expressions are the mean directions of the samples.
Returns a vector or a matrix of a circular version of the Pearson's
product moment correlation, if test == TRUE
then a list is
reported with statistic and p.value, the test statistic and p-value respectively, for testing significance of the correlation coefficient.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 8.2, World Scientific Press, Singapore.
Jammalamadaka, S. and Sarma, Y. (1988). A correlation coefficient for angular variables. Statistical Theory and Data Analysis 2. North Holland: New York.
# Generate two circular data sets, and compute their correlation. x <- rvonmises(n=50, mu=circular(0), kappa=3) y <- x + rvonmises(n=50, mu=circular(pi), kappa=10) cor.circular(x, y, test=TRUE)
# Generate two circular data sets, and compute their correlation. x <- rvonmises(n=50, mu=circular(0), kappa=3) y <- x + rvonmises(n=50, mu=circular(pi), kappa=10) cor.circular(x, y, test=TRUE)
Draws a curve corresponding to the given function or expression (in
x
) over the interval [from,to]
in a circle. Mainly used to
plot circular density functions.
## S3 method for class 'circular' curve(expr, from=NULL, to=NULL, n=101, add=FALSE, cex=1, axes=TRUE, ticks=FALSE, shrink=1, tcl=0.025, tcl.text=0.125, tol=0.04, uin=NULL, xlim=c(-1, 1), ylim=c(-1, 1), digits=2, modulo=c("2pi", "asis", "pi"), main=NULL, sub=NULL, xlab="", ylab="", control.circle=circle.control(), ...) ## S3 method for class 'function.circular' plot(x, from=0, to=2*pi, ...)
## S3 method for class 'circular' curve(expr, from=NULL, to=NULL, n=101, add=FALSE, cex=1, axes=TRUE, ticks=FALSE, shrink=1, tcl=0.025, tcl.text=0.125, tol=0.04, uin=NULL, xlim=c(-1, 1), ylim=c(-1, 1), digits=2, modulo=c("2pi", "asis", "pi"), main=NULL, sub=NULL, xlab="", ylab="", control.circle=circle.control(), ...) ## S3 method for class 'function.circular' plot(x, from=0, to=2*pi, ...)
expr |
an expression written as a function of |
x |
a ‘vectorizing’ numeric R function. |
from , to
|
the range over which the function will be plotted. |
n |
integer; the number of x values at which to evaluate. |
add |
logical; if |
axes |
logical: if |
ticks |
logical: if |
shrink |
parameter that controls the size of the plotted circle. Default is 1. Larger values shrink the circle, while smaller values enlarge the circle. |
tcl |
length of the ticks. |
tcl.text |
The position of the axis labels. |
tol |
proportion of white space at the margins of plot. |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. Useful for centering the plot. |
digits |
number of digits used to print axis values. |
modulo |
the modulo used to process the data. |
main , sub , xlab , ylab , cex
|
graphical parameters. |
control.circle |
parameters passed to |
... |
parameters, passed to |
For now, curve circular draws functions defined in radians, counterclockwise coordinate and zero at 0.
A list with information on the plot: zero, rotation and next.points.
Claudio Agostinelli
lines.circular
and circle.control
ff <- function(x) sqrt(x)/20 curve.circular(ff) curve.circular(ff, to=6*pi, join=FALSE, nosort=TRUE, n=1001, modulo="asis", shrink=1.2) plot.function.circular(function(x) dvonmises(x, circular(0), 10), xlim=c(-1, 2.2))
ff <- function(x) sqrt(x)/20 curve.circular(ff) curve.circular(ff, to=6*pi, join=FALSE, nosort=TRUE, n=1001, modulo="asis", shrink=1.2) plot.function.circular(function(x) dvonmises(x, circular(0), 10), xlim=c(-1, 2.2))
Converts radians to degrees.
deg(x)
deg(x)
x |
vector or matrix of radian measurements. |
This function is available for compatibility with the CircStats
package; please use conversion.circular
.
Returns a vector or matrix of degree measurements corresponding to the data in radians.
Claudio Agostinelli and Ulric Lund
The function density.circular
computes kernel density estimates
with the given kernel and bandwidth for circular data.
## S3 method for class 'circular' density(x, z=NULL, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, from = circular(0), to = circular(2 * pi), n = 512, K = NULL, min.k=10, control.circular=list(), ...) ## S3 method for class 'density.circular' print(x, digits = NULL, ...)
## S3 method for class 'circular' density(x, z=NULL, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, from = circular(0), to = circular(2 * pi), n = 512, K = NULL, min.k=10, control.circular=list(), ...) ## S3 method for class 'density.circular' print(x, digits = NULL, ...)
x |
the data from which the estimate is to be computed. The object is coerced to class |
z |
the points where the density is estimated. If |
bw |
the smoothing bandwidth to be used. When the |
adjust |
the bandwidth used is actually |
type |
Not Yet Used. |
kernel |
a character string giving the smoothing kernel to be
used. This must be one of |
na.rm |
logical; if |
from , to
|
the left and right-most
points of the grid at which the density is to be estimated. The objects are coerced to class |
n |
the number of equally spaced points at which the density is to be estimated. |
K |
number of terms to be used in approximating the density. |
min.k |
minimum number of terms used in approximating the density. |
control.circular |
the attribute of the resulting objects ( |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
an object with class "density.circular"
whose
underlying structure is a list containing the following components.
data |
original dataset. |
x |
the |
y |
the estimated density values. |
bw |
the bandwidth used. |
N |
the sample size after elimination of missing values. |
call |
the call which produced the result. |
data.name |
the deparsed name of the |
has.na |
logical, for compatibility (always FALSE). |
Claudio Agostinelli
Z.D. Bai and C.R. Rao and L.C. Zhao (1988). Kernel Estimators of Density Function of Directional Data, Journal of Multivariate Analysis, 27, 24-39.
J. Klemel\"a (2000). Estimation of densities and derivatives of densities with directional data, Journal of Multivariate Analysis, 73, 18-40.
V.R. Prayag and A.P. Gore (1990). Density Estimation for Randomly Distributed Circular Objects, Metrika, 1990, 37, 63-69.
P. Hall and G.S. Watson and J. Cabrera (1987). Kernel Density Estimation with Spherical Data, Biometrika, 74, 4, 751–762.
plot.density.circular
and lines.density.circular
x <- rvonmises(n=100, mu=circular(pi), kappa=2) res25 <- density(x, bw=25, control.circular=list(units="degrees")) circularp(res25$x) plot(res25, points.plot=TRUE, xlim=c(-1.6,1)) res50 <- density(x, bw=25, adjust=2) lines(res50, col=2) lines(res50, col=3, shrink=0.9) #shrink the plot wrt the function :-) lines(res50, col=4, offset=0.5) #draw it with a reference circle of 0.5
x <- rvonmises(n=100, mu=circular(pi), kappa=2) res25 <- density(x, bw=25, control.circular=list(units="degrees")) circularp(res25$x) plot(res25, points.plot=TRUE, xlim=c(-1.6,1)) res50 <- density(x, bw=25, adjust=2) lines(res50, col=2) lines(res50, col=3, shrink=0.9) #shrink the plot wrt the function :-) lines(res50, col=4, offset=0.5) #draw it with a reference circle of 0.5
This function computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix containing circular data.
dist.circular(x, method = "correlation", diag = FALSE, upper = FALSE)
dist.circular(x, method = "correlation", diag = FALSE, upper = FALSE)
x |
a numeric matrix of class |
method |
the distance measure to be used. This must be one of
|
diag |
logical value indicating whether the diagonal of the
distance matrix should be printed by |
upper |
logical value indicating whether the upper triangle of the
distance matrix should be printed by |
Available distance measures are (written for two vectors and
):
correlation
: where
is the Circular Correlation coefficient defined as
and ,
are the mean direction of the two vectors
angularseparation
:chord
:geodesic
: where the abs(x - y) is expressed with an angle in [-pi,pi]
Missing values are allowed, and are excluded from all computations
involving the rows within which they occur.
Further, when Inf
values are involved, all pairs of values are
excluded when their contribution to the distance gave NaN
or
NA
.
If some columns are excluded in calculating the sum is scaled up proportionally
to the number of columns used. If all pairs are excluded when calculating a
particular distance, the value is NA
.
dist.circular
returns an object of class "dist"
.
The lower triangle of the distance matrix stored by columns in a
vector, say do
. If n
is the number of
observations, i.e., n <- attr(do, "Size")
, then
for , the dissimilarity between (row) i and j is
do[n*(i-1) - i*(i-1)/2 + j-i]
.
The length of the vector is , i.e., of order
.
The object has the following attributes (besides "class"
equal
to "dist"
):
Size |
integer, the number of observations in the dataset. |
Labels |
optionally, contains the labels, if any, of the observations of the dataset. |
Diag , Upper
|
logicals corresponding to the arguments |
call |
optionally, the |
method |
optionally, the distance method used; resulting from
|
This function tests for the homogeneity of concentration parameters for multiple samples of directional data.
equal.kappa.test(x, group) ## S3 method for class 'equal.kappa.test' print(x, digits = max(3, getOption("digits") - 3), ...)
equal.kappa.test(x, group) ## S3 method for class 'equal.kappa.test' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
a vector of class |
group |
a vector identifying the groups or samples. |
digits |
the number of digits to be printed. |
... |
additional arguments. |
The samples are assumed to have been drawn from von Mises populations. The null hypothesis tested is that all populations sampled have the same concentration parameter, kappa.
When the pooled data has high concentration, sample mean resultant length above 0.70, Bartlett's test is used. For less concentrated pooled data, variance-stabilizing transformations are used to improve normal approximations needed to arrive at an approximate chi-squared test statistic (see references below). For pooled sample mean resultant length below 0.45, it is possible that individually a sample may in fact have quite a large sample mean resultant length. In this case, it is possible that the variance-stabilizing transformation involving the inverse sine function is passed a value outside of -1,1. If this occurs, the function will automatically use Bartlett's test and issue a warning to that effect.
An object of class equal.kappa.test
with the following
components:
kappa |
concentration parameter for each sample. |
kappa.all |
concentration parameter of all samples combined. |
rho |
mean resultant length for each sample. |
rho.all |
mean resultant length of all samples combined. |
df |
degrees of freedom for chi-squared distribution. |
statistic |
the value of the chi-squared test statistic. |
p.value |
the p.value of the test statistic. |
call |
the |
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 5.3, World Scientific Press, Singapore.
Mardia, K. and Jupp, P. (1999). Directional Statistics, Section 7.4, John Wiley and Sons, England.
x <- c(rvonmises(50, circular(0), 1), rvonmises(100, circular(pi/3), 10)) group <- c(rep(0, 50), rep(1, 100)) equal.kappa.test(x, group)
x <- c(rvonmises(50, circular(0), 1), rvonmises(100, circular(pi/3), 10)) group <- c(rep(0, 50), rep(1, 100)) equal.kappa.test(x, group)
Arrival time on a 24-hour clock of 254 patients at an intensive care unit, over a period of about 12 months.
data(fisherB1) data(fisherB1c)
data(fisherB1) data(fisherB1c)
fisherB1
is a vector of 254 observations (in the format hours.minutes).
fisherB1c
contains the same observations in a circular objects (minutes are expressed as decimals).
Cox, D.R. and Lewis, P.A.W. (1966) The Statistical Analysis of Series of Events. London : Methuen & CO. Ltd. pp. 254-255
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 239.
data(fisherB1c) par(mfcol=c(1,2)) plot(fisherB1c, main="Clock 24", shrink=1.5) plot(fisherB1c, template="clock12", main="Clock 12", shrink=1.5)
data(fisherB1c) par(mfcol=c(1,2)) plot(fisherB1c, main="Clock 24", shrink=1.5) plot(fisherB1c, template="clock12", main="Clock 12", shrink=1.5)
Directions of 11 long-legged desert ants (Cataglyphis fortis) after one eye on each ant was 'trained' to learn the ant's home direction, then covered and the other eye uncovered.
data(fisherB10) data(fisherB10c)
data(fisherB10) data(fisherB10c)
fisherB10
is a list (in degrees).
fisherB10c
contains the same observations in a circular objects.
Personal communication of Prof. Dr. R. Wehner to Prof. N.I. Fisher, experiment described in
R. Wehner and M. Muller (1985) Does interocular transfer occur in visual navigation by ants? Nature, 315, 228-9.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 244-245.
data(fisherB10c) res <- plot(fisherB10c$set1) points(fisherB10c$set2, col=2, plot.info=res) points(fisherB10c$set3, col=3, plot.info=res)
data(fisherB10c) res <- plot(fisherB10c$set1) points(fisherB10c$set2, col=2, plot.info=res) points(fisherB10c$set3, col=3, plot.info=res)
Resultant directions of 22 sea stars 11 days after being displaced from their natural habitat.
data(fisherB11) data(fisherB11c)
data(fisherB11) data(fisherB11c)
fisherB11
a vector of 22 observations (in degrees).
fisherB11c
contains the same observations in a circular objects.
G.J.G. Upton and B. Fingleton (1989) Spatial Data Analysis by Example. Volume 2. Categorical and Directional Data. New York: John Wiley as adapted from B. Pabst and H. Vicentini (1978) Dislocation experiments in the migrating seastar. Astropecten jonstoni. Marine Biology 48, 271-8.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 245.
data(fisherB11c) plot(fisherB11c, stack=TRUE, shrink=1.5)
data(fisherB11c) plot(fisherB11c, stack=TRUE, shrink=1.5)
Vanishing directions of 15 homing pigeons, released just over 16 kilometres Northwest of their loft.
data(fisherB12) data(fisherB12c)
data(fisherB12) data(fisherB12c)
fisherB12
a vector of 15 observations (in degrees).
fisherB12c
contains the same observations in a circular objects.
Schmidt-Koenig (1963) On the role of the loft, the distance and site of release in pigeon homing (the "cross-loft experiment"). Biol. Bull. (125)154-164.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 245.
data(fisherB12c) plot(fisherB12c, stack=TRUE, shrink=1.5)
data(fisherB12c) plot(fisherB12c, stack=TRUE, shrink=1.5)
Orientations of termite mounds of Amitermes laurensis at 14 sites in Cape York Penisula, North Queensland.
data(fisherB13) data(fisherB13c)
data(fisherB13) data(fisherB13c)
fisherB13
a list of 14 datasets (axes in degrees) at several locations.
fisherB13c
contains the same observations in a circular objects.
Set 1: n=100, Latitude -15'43”, Longitude 144'42” Set 2: n=50, Latitude -15'32”, Longitude 144'17”
A.V. Spain, T. Okello-Oloya and R.D. John (1983) Orientation of the termitaria of two species of Amitermes (Isoptera:Termitinae) from Northern Queensland. Aust. J. Zoo. (31):167-177.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 246.
data(fisherB13c) plot(fisherB13c$set1, stack=TRUE, shrink=1.5)
data(fisherB13c) plot(fisherB13c$set1, stack=TRUE, shrink=1.5)
19 measurements of wind direction 'theta' and ozone level 'x' taken at 6.00am at four-day intervals between April 18th and June 29th, 1975 at a weather station in Milwaukee.
data(fisherB18) data(fisherB18c)
data(fisherB18) data(fisherB18c)
fisherB18
is a data.frame
of integer value.
fisherB18c
is a data.frame
that contains the same observations, but in the first column, the data is a circular
object.
N.I. Fisher (1993) pag. 251. Johnson & Wehrly (1977, Table 1).
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
data(fisherB18) data(fisherB18c) par(mfcol=c(1,3)) plot(fisherB18c$theta, xlab=expression(theta)) boxplot(fisherB18c$x, xlab="x") plot(c(fisherB18$x, fisherB18$x), c(fisherB18$theta, fisherB18$theta+360), xlab="x", ylab=expression(theta))
data(fisherB18) data(fisherB18c) par(mfcol=c(1,3)) plot(fisherB18c$theta, xlab=expression(theta)) boxplot(fisherB18c$x, xlab="x") plot(c(fisherB18$x, fisherB18$x), c(fisherB18$theta, fisherB18$theta+360), xlab="x", ylab=expression(theta))
Measurements of long-axis orientation of 133 feldspar laths in basalt
data(fisherB2) data(fisherB2c)
data(fisherB2) data(fisherB2c)
fisherB2
is a vector of 133 observations (in degrees).
fisherB2c
contains the same observations in a circular objects.
Smith, N.M. (1988) Reconstruction of the Tertiary drainage systems of the Inverell region. Unpublished B.Sc. (Hons.) thesis, Department of Geography, University of Sydney, Australia.
This dataset (set 28-6-1co.prn) was kindly supplied by Ms Nicola Smith to Prof. N.I. Fisher.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 240.
data(fisherB2c) plot(fisherB2c)
data(fisherB2c) plot(fisherB2c)
Distances 'x' and directions 'theta' by small blue periwinkles, Nodilittorina unifasciata, after they had been transplanted downshore from the height at which they normally live.
data(fisherB20) data(fisherB20c)
data(fisherB20) data(fisherB20c)
fisherB20
is a data.frame
of integer value.
fisherB20c
is a data.frame
that contains the same observations, but in the first column, the data is a circular
object.
N.I. Fisher (1993) pag. 252-253. Data kindly supplied by Dr A. Underwood and Ms G. Chapman.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
data(fisherB20) data(fisherB20c) par(mfcol=c(1,3)) plot(fisherB20c$theta, xlab=expression(theta)) boxplot(fisherB20c$x, xlab="x") plot(c(fisherB20$x, fisherB20$x), c(fisherB20$theta, fisherB20$theta+360), xlab="x", ylab=expression(theta))
data(fisherB20) data(fisherB20c) par(mfcol=c(1,3)) plot(fisherB20c$theta, xlab=expression(theta)) boxplot(fisherB20c$x, xlab="x") plot(c(fisherB20$x, fisherB20$x), c(fisherB20$theta, fisherB20$theta+360), xlab="x", ylab=expression(theta))
Measurements of the directions taken by 76 turtles after treatment.
data(fisherB3) data(fisherB3c)
data(fisherB3) data(fisherB3c)
fisherB3
is a vector of 76 observations (in degrees).
fisherB3c
contains the same observations in a circular objects.
Stephens, M.A. (1969) Techniques for directional data. Technical Report #150, Department of Statistics, Stanford University, Stanford, CA.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 241.
data(fisherB3c) plot(fisherB3c)
data(fisherB3c) plot(fisherB3c)
Sun compass orientations of 50 starhead topminnows, measured under heavily overcast conditions.
data(fisherB4) data(fisherB4c)
data(fisherB4) data(fisherB4c)
fisherB4
is a vector of 50 observations (in degrees).
fisherB4c
contains the same observations in a circular objects.
Goodyear (1970) Terrestrial and aquatic orientation in the Starhead Topminnow, Fundulus notti. Science 168, 603-5. Figure 1D.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 241.
data(fisherB3c) plot(fisherB3c)
data(fisherB3c) plot(fisherB3c)
Measurements of long-axis orientation of 164 feldspar laths in basalt
data(fisherB5) data(fisherB5c)
data(fisherB5) data(fisherB5c)
fisherB5
is a vector of 164 observations (in degrees).
fisherB5c
contains the same observations in a circular objects.
Smith, N.M. (1988) Reconstruction of the Tertiary drainage systems of the Inverell region. Unpublished B.Sc. (Hons.) thesis, Department of Geography, University of Sydney, Australia.
This dataset (set 24-6-5co.prn) was kindly supplied by Ms Nicola Smith to Prof. N.I. Fisher.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 242.
data(fisherB5c) plot(fisherB5c)
data(fisherB5c) plot(fisherB5c)
Set of cross-bed azimuths of palaeocurrents measured in the Belford Anticline (New South Wales).
data(fisherB6) data(fisherB6c)
data(fisherB6) data(fisherB6c)
fisherB6
is a list (in degrees).
fisherB6c
contains the same observations in a circular objects.
Fisher, N.I. & Powell C. McA. (1989) Statistical analysis of two-dimensional palaeocurrent data: Methods and examples. Aust. J. Earth Sci. 36, 91-107.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 242.
data(fisherB6c) res <- plot(fisherB6c$set1) points(fisherB6c$set2, col=2, plot.info=res) points(fisherB6c$set3, col=3, plot.info=res)
data(fisherB6c) res <- plot(fisherB6c$set1) points(fisherB6c$set2, col=2, plot.info=res) points(fisherB6c$set3, col=3, plot.info=res)
Directions chosen by 100 ants in response to an evenly illuminated black targets placed as shown.
data(fisherB7) data(fisherB7c)
data(fisherB7) data(fisherB7c)
fisherB7
a vector of 100 observations (in degrees).
fisherB7c
contains the same observations in a circular objects.
Randomly selected values from Jander, R. (1957) Die optische Richtangsorientierung der roten Waldameise (Formica rufa. L.) Z. vergl. Physiologie 40, 162-238. Figure 18A.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 243.
data(fisherB7c) plot(fisherB7c, zero=pi/2, rotation='clock', stack=TRUE)
data(fisherB7c) plot(fisherB7c, zero=pi/2, rotation='clock', stack=TRUE)
Horizontal axes of 100 outwash pebbles fromo a late Wisconsin outwash terrace along Fox river, near Cary, Illinois
data(fisherB8) data(fisherB8c)
data(fisherB8) data(fisherB8c)
fisherB8
a vector of 100 observations (in degrees).
fisherB8c
contains the same observations in a circular objects.
Mardia, K.V. (1972) Statistics of Directional Data. London: Academic Press. Table 1.6 adapted from Krumbein W.C. (1939) Preferred orientations of pebbles in sedimentary deposits. J. Geol. 47, 673-706.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 243.
data(fisherB8c) plot(fisherB8c, stack=TRUE, shrink=1.5)
data(fisherB8c) plot(fisherB8c, stack=TRUE, shrink=1.5)
Dance directions of 279 honey bees viewing a zenith patch of artificially polarised light.
data(fisherB9) data(fisherB9c)
data(fisherB9) data(fisherB9c)
fisherB9
a vector of 279 observations (in degrees).
fisherB9c
contains the same observations in a circular objects.
Adapted by Prof. N.I. Fisher from R. Wehner & S. Strasser (1985) The POL area of the honey bee's eye: behavioural evidence. Physiol. Entomol. 10, 337-49. Pag. 346.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press. Pag. 244.
data(fisherB9c) plot(fisherB9c, stack=TRUE, shrink=1.5)
data(fisherB9c) plot(fisherB9c, stack=TRUE, shrink=1.5)
Density for the Generalized von Mises circular distribution.
dgenvonmises(x, mu1, mu2, kappa1, kappa2)
dgenvonmises(x, mu1, mu2, kappa1, kappa2)
x |
a vector. The object is coerced to class |
mu1 |
principal direction of the distribution. The object is coerced to class |
mu2 |
secondary direction parameter. The object is coerced to class |
kappa1 |
non-negative numeric parameter of the distribution. |
kappa2 |
non-negative numeric parameter of the distribution. |
The Generalized von Mises distribution has density
for , where
and
is the normalizing constant.
The density
Federico Rotolo
Gatto , R. & Jammalamadaka , S.R. (2007). The generalized von Mises distribution. Statistical Methodology 4, 341-353.
ff <- function(x) dgenvonmises(x, mu1=circular(5*pi/4), mu2=circular(pi/4), kappa1=.3, kappa2=1) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a Generalized von Mises Distribution", xlab=expression(paste(mu,"1=5/4",pi,", ",mu2,"=",pi/4,", ",kappa,"1=0.3, ",kappa,"2=1")) )
ff <- function(x) dgenvonmises(x, mu1=circular(5*pi/4), mu2=circular(pi/4), kappa1=.3, kappa2=1) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a Generalized von Mises Distribution", xlab=expression(paste(mu,"1=5/4",pi,", ",mu2,"=",pi/4,", ",kappa,"1=0.3, ",kappa,"2=1")) )
A heat map is a false color image (basically
image(t(x))
) with a dendrogram added to the left side
and to the top. Typically, reordering of the rows and columns
according to some set of values (row or column means) within the
restrictions imposed by the dendrogram is carried out. See also heatmap
.
heatmap.circular(x, Rowv = NULL, Colv = if (symm) "Rowv" else NULL, distfun = dist.circular, hclustfun = hclust, reorderfun = function(d, w) reorder(d, w), add.expr, symm = FALSE, revC = identical(Colv, "Rowv"), na.rm = TRUE, margins = c(5, 5), lwid = c(1, 4), lhei = c(1, 4), ColSideColors, RowSideColors, NAColors = "black", cexRow = 0.2 + 1/log10(nr), cexCol = 0.2 + 1/log10(nc), labRow = NULL, labCol = NULL, main = NULL, xlab = NULL, ylab = NULL, keep.dendro = FALSE, annotate.expr, annotate = rep(NA, 4), verbose = getOption("verbose"), ...)
heatmap.circular(x, Rowv = NULL, Colv = if (symm) "Rowv" else NULL, distfun = dist.circular, hclustfun = hclust, reorderfun = function(d, w) reorder(d, w), add.expr, symm = FALSE, revC = identical(Colv, "Rowv"), na.rm = TRUE, margins = c(5, 5), lwid = c(1, 4), lhei = c(1, 4), ColSideColors, RowSideColors, NAColors = "black", cexRow = 0.2 + 1/log10(nr), cexCol = 0.2 + 1/log10(nc), labRow = NULL, labCol = NULL, main = NULL, xlab = NULL, ylab = NULL, keep.dendro = FALSE, annotate.expr, annotate = rep(NA, 4), verbose = getOption("verbose"), ...)
x |
numeric matrix of class |
Rowv |
determines if and how the row dendrogram should be
computed and reordered. Either a |
Colv |
determines if and how the column dendrogram should be
reordered. Has the same options as the |
distfun |
function used to compute the distance (dissimilarity)
between both rows and columns. Defaults to |
hclustfun |
function used to compute the hierarchical clustering
when |
reorderfun |
function(d,w) of dendrogram and weights for
reordering the row and column dendrograms. The default uses
|
add.expr |
expression that will be evaluated after the call to
|
symm |
logical indicating if |
revC |
logical indicating if the column order should be
|
na.rm |
logical indicating whether |
margins |
numeric vector of length 2 containing the margins
(see |
lwid |
a vector of values for the widths of columns on the device.
Relative widths are specified with numeric values. Absolute
widths (in centimetres) are specified with the |
lhei |
a vector of values for the heights of rows on the device.
Relative and absolute heights can be specified, see |
ColSideColors |
(optional) character vector of length |
RowSideColors |
(optional) character vector of length |
NAColors |
the color used to plot missing values. |
cexRow , cexCol
|
positive numbers, used as |
labRow , labCol
|
character vectors with row and column labels to
use; these default to |
main , xlab , ylab
|
main, x- and y-axis titles; defaults to none. |
keep.dendro |
logical indicating if the dendrogram(s) should be
kept as part of the result (when |
annotate |
annotation in the four external side of the figure. A positive value in a position means you want annotate something in that position (1=bottom, 2=left, 3=top, 4=right). For instance, |
annotate.expr |
must be a list of expressions with the same length as |
verbose |
logical indicating if information should be printed. |
... |
additional arguments passed on to |
If either Rowv
or Colv
are dendrograms they are honored
(and not reordered). Otherwise, dendrograms are computed as
dd <- as.dendrogram(hclustfun(distfun(X)))
where X
is
either x
or t(x)
.
If either is a vector (of ‘weights’) then the appropriate
dendrogram is reordered according to the supplied values subject to
the constraints imposed by the dendrogram, by reorder(dd,
Rowv)
, in the row case.
If either is missing, as by default, then the ordering of the
corresponding dendrogram is by the mean direction value of the rows/columns,
i.e., in the case of rows, Rowv <- rowMeans(x, na.rm=na.rm)
.
If either is NULL
, no reordering will be done for
the corresponding side.
Unless Rowv = NA
(or Colw = NA
), the original rows and
columns are reordered in any case to match the dendrogram,
e.g., the rows by order.dendrogram(Rowv)
where
Rowv
is the (possibly reorder()
ed) row
dendrogram.
heatmap()
uses layout
and draws the
image
in the lower right corner of a 2x2 layout.
Consequentially, it can not be used in a multi column/row
layout, i.e., when par(mfrow= *)
or (mfcol= *)
has been called.
par(mfrow= *)
or (mfcol= *)
has been called.
Claudio Agostinelli using the code from heatmap
.
dist.circular
, heatmap
, image
, hclust
An alias of besselI(x, nu=0)
.
I.0(x)
I.0(x)
x |
non-negative numerical value at which to evaluate the Bessel function. |
Returns the zeroth order Bessel function of the first kind evaluated at a specified real number.
An alias of besselI(x, nu=1)
.
I.1(x)
I.1(x)
x |
non-negative numerical value at which to evaluate the Bessel function. |
Returns the first order Bessel function of the first kind, evaluated at a specified real number.
An alias of besselI(x, nu=p)
.
I.p(p, x)
I.p(p, x)
p |
positive integer order of the Bessel function. |
x |
non-negative numerical value at which to evaluate the Bessel function. |
Returns the p-th order Bessel function of the first kind, evaluated at a specified real number.
Find an estimates of the probability of the intersection between a modal region and a given interval.
intersect.modal.region(x, ...) ## Default S3 method: intersect.modal.region(x, ...) ## S3 method for class 'circular' intersect.modal.region(x, breaks, z = NULL, q = 0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step = 0.01, eps.lower = 10^(-4), eps.upper = 10^(-4), ...)
intersect.modal.region(x, ...) ## Default S3 method: intersect.modal.region(x, ...) ## S3 method for class 'circular' intersect.modal.region(x, breaks, z = NULL, q = 0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step = 0.01, eps.lower = 10^(-4), eps.upper = 10^(-4), ...)
x |
numeric or an object of class |
breaks |
a matrix with two columns. Each row specifies a sub-interval. |
z |
numeric or object of class |
q |
numeric in the interval [0,1]. The quantile of the modal region. |
bw |
the smoothing bandwidth to be used. When the |
adjust |
the bandwidth used is actually |
type |
Not Yet Used. |
kernel |
a character string giving the smoothing kernel to be
used. This must be one of |
na.rm |
logical; if |
step |
numeric. Used in the construction of the regular grid |
eps.lower , eps.upper
|
the cut point in the density is searched in the interval [min(density)*(1+eps.lower),max(density)*(1-eps.upper)]. |
... |
further arguments passed to the next methods. |
Only the version for circular data is actually implemented.
For the circular method a list with the following three components
tot |
the total area. |
areas |
information for each subinterval. |
breaks |
the extremes of each subinterval. |
Claudio Agostinelli
x <- rvonmises(100, circular(pi), 10) res <- intersect.modal.region(x, breaks=circular(matrix(c(pi,pi+pi/12, pi-pi/12, pi), ncol=2, byrow=TRUE)), bw=50) res$tot x <- rvonmises(100, circular(0), 10) res <- intersect.modal.region(x, breaks=circular(matrix(c(pi,pi+pi/12), ncol=2)), bw=50) res$tot res <- intersect.modal.region(x, breaks=circular(matrix(c(pi/12, 2*pi-pi/12), ncol=2, byrow=TRUE)), bw=50) res$tot
x <- rvonmises(100, circular(pi), 10) res <- intersect.modal.region(x, breaks=circular(matrix(c(pi,pi+pi/12, pi-pi/12, pi), ncol=2, byrow=TRUE)), bw=50) res$tot x <- rvonmises(100, circular(0), 10) res <- intersect.modal.region(x, breaks=circular(matrix(c(pi,pi+pi/12), ncol=2)), bw=50) res$tot res <- intersect.modal.region(x, breaks=circular(matrix(c(pi/12, 2*pi-pi/12), ncol=2, byrow=TRUE)), bw=50) res$tot
Density for the Jones and Pewsey circular distribution.
djonespewsey(x, mu, kappa, psi)
djonespewsey(x, mu, kappa, psi)
x |
a vector. The object is coerced to class |
mu |
direction parameter of the distribution. The object is coerced to class |
kappa |
non-negative concentration parameter of the distribution. |
psi |
real shape parameter. |
The JonesPewsey distribution has density
for , where
is the associated Legendre function of the first kind, degree
and order 0.
The density
Federico Rotolo
Jones , M.C. and Pewsey, A. (2005). A family of symmetric distributions on the circle. J. Am. Statist. Assoc. 100, 1422-1428
ff <- function(x) djonespewsey(x, mu=circular(4), kappa=1.8, psi=-.6) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a JonesPewsey Distribution", xlab=expression(paste(mu,"=1.3",pi,", ",kappa,"=1.8, ",psi,"=-0.6")) )
ff <- function(x) djonespewsey(x, mu=circular(4), kappa=1.8, psi=-.6) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a JonesPewsey Distribution", xlab=expression(paste(mu,"=1.3",pi,", ",kappa,"=1.8, ",psi,"=-0.6")) )
Density and random generation for the Kato and Jones distribution.
rkatojones(n, mu, nu, r, kappa, control.circular=list()) dkatojones(x, mu, nu, r, kappa)
rkatojones(n, mu, nu, r, kappa, control.circular=list()) dkatojones(x, mu, nu, r, kappa)
x |
the angular value the density must be computed in. |
n |
number of observations. |
mu |
the Mobius 'mu' parameter. The object is coerced to class |
nu |
the Mobius 'nu' parameter. The object is coerced to class |
r |
the Mobius 'r' parameter. It must be in [0,1). |
kappa |
the positive vonMises parameter. |
control.circular |
the attribute of the resulting object. |
The Kato and Jones distribution has density
for ,
where
,
and
.
Original code for random generation is by Kato, S. and Jones, M.C. and can be found at the address http://pubs.amstat.org/doi/suppl/10.1198/jasa.2009.tm08313/suppl_file/t08-313code.txt.
The density.
dkatojones
gives the density and rkatojones
generates random deviates.
Federico Rotolo
Kato , S. and Jones, M.C. (2010). A family of distributions on the circle with links to, and applications arising from, Mobius transformation. J. Am. Statist. Assoc. 105, 249-262.
data1 <- rkatojones(n=100, mu=circular(0), nu=circular(pi/4), r=.2, kappa=1) plot(data1) data1 <- rkatojones(n=100, mu=circular(pi/3), nu=circular(pi), r=.7, kappa=2.3) plot(data1) ff <- function(x) dkatojones(x, mu=circular(pi/3), nu=circular(pi), r=.7, kappa=2.3) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a KatoJones Distribution", xlab=expression(paste(mu,"=",pi,"/3, ",nu,"=",pi,", r=0.7, ",kappa,"=2.3")) )
data1 <- rkatojones(n=100, mu=circular(0), nu=circular(pi/4), r=.2, kappa=1) plot(data1) data1 <- rkatojones(n=100, mu=circular(pi/3), nu=circular(pi), r=.7, kappa=2.3) plot(data1) ff <- function(x) dkatojones(x, mu=circular(pi/3), nu=circular(pi), r=.7, kappa=2.3) curve.circular(ff, join=TRUE, xlim=c(-1, 1), ylim=c(-1.2, 1.2), main="Density of a KatoJones Distribution", xlab=expression(paste(mu,"=",pi,"/3, ",nu,"=",pi,", r=0.7, ",kappa,"=2.3")) )
Performs Kuiper's one-sample test of uniformity on the circle.
kuiper.test(x, alpha=0) ## S3 method for class 'kuiper.test' print(x, digits = 4, ...)
kuiper.test(x, alpha=0) ## S3 method for class 'kuiper.test' print(x, digits = 4, ...)
x |
a vector. The object is coerced to class
|
alpha |
significance level of the test. Possible levels are 0.15, 0.1, 0.05, 0.025, 0.01. Alpha may be omitted or set to zero, in which case a range for the p-value of the test will be printed. |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Kuiper's test statistic is a rotation-invariant Kolmogorov-type test statistic. The critical values of a modified Kuiper's test statistic are used according to the tabulation given in Stephens (1970).
A list with the statistic and alpha value.
Kuiper's one-sample test of uniformity is performed, and the results are printed to the screen. If alpha is specified and non-zero, the test statistic is printed along with the critical value and decision. If alpha is omitted, the test statistic is printed and a range for the p-value of the test is given.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 7.2, World Scientific Press, Singapore.
Stephens, M. (1970). Use of the Kolmogorov-Smirnov, Cramer-von Mises and related statistics without extensive tables. Journal of the Royal Statistical Society, B32, 115-122.
range.circular
, rao.spacing.test
,
rayleigh.test
and watson.test
# Generate data from the uniform distribution on the circle. data <- circular(runif(100, 0, 2*pi)) kuiper.test(data) # Generate data from the von Mises distribution. data <- rvonmises(n=100, mu=circular(0), kappa=3) kuiper.test(data, alpha=0.01)
# Generate data from the uniform distribution on the circle. data <- circular(runif(100, 0, 2*pi)) kuiper.test(data) # Generate data from the von Mises distribution. data <- rvonmises(n=100, mu=circular(0), kappa=3) kuiper.test(data, alpha=0.01)
A method taking coordinates in a polar system and joining the corresponding points with line segments.
## S3 method for class 'circular' lines(x, y, join = FALSE, nosort = FALSE, offset=1, shrink=1, plot.info = NULL, zero = NULL, rotation = NULL, modulo = NULL, ...)
## S3 method for class 'circular' lines(x, y, join = FALSE, nosort = FALSE, offset=1, shrink=1, plot.info = NULL, zero = NULL, rotation = NULL, modulo = NULL, ...)
x |
a vector of class |
y |
a vector with the same length as 'x'. |
join |
logical: if |
nosort |
logical: if |
offset |
the radius of the circle |
shrink |
parameter that controls the size of the plotted function. Default is 1. |
plot.info |
an object from another circular graphic function. |
zero |
the zero of the axis. |
rotation |
the rotation of the axis. |
modulo |
the modulo applied to 'x' before sorting. |
... |
graphical parameters passed to |
A list with information on the plot: zero, rotation and next.points.
Claudio Agostinelli
x <- rvonmises(20, circular(0), 10) y <- runif(20, 0.5, 1) plot(x, shrink=2) lines(x, y)
x <- rvonmises(20, circular(0), 10) y <- runif(20, 0.5, 1) plot(x, shrink=2) lines(x, y)
The lines
add a plot for density.circular
objects.
## S3 method for class 'density.circular' lines(x, type = "l", zero.line = TRUE, points.plot = FALSE, points.col = 1, points.pch = 1, points.cex = 1, plot.type = c("circle", "line"), bins = NULL, offset=1, shrink = 1, tcl = 0.025, sep = 0.025, join = TRUE, nosort = FALSE, plot.info = NULL, zero = NULL, rotation = NULL, ...)
## S3 method for class 'density.circular' lines(x, type = "l", zero.line = TRUE, points.plot = FALSE, points.col = 1, points.pch = 1, points.cex = 1, plot.type = c("circle", "line"), bins = NULL, offset=1, shrink = 1, tcl = 0.025, sep = 0.025, join = TRUE, nosort = FALSE, plot.info = NULL, zero = NULL, rotation = NULL, ...)
x |
an object of class |
type |
plotting parameter with useful default. |
zero.line |
logical; if |
points.plot |
logical; if |
points.col , points.pch , points.cex
|
parameters used to draw the points. |
plot.type |
type of the plot. |
bins |
number of ticks to plot. |
offset |
the radius of the circle |
shrink |
parameter that controls the size of the plotted function. Default is 1. |
tcl |
length of the ticks. |
sep |
constant used to specify the distance between stacked points. Default is 0.025; smaller values will create smaller spaces. |
join |
logical: should the first and the last point joined. |
nosort |
logical: should the data sort before plotting. Defaults is to sort. |
plot.info |
an object from |
zero |
the zero of the plot. Ignored if |
rotation |
the rotation of the plot. Ignored if |
... |
further parameters passed to |
A list with information on the plot: zero, rotation and next.points and, if available, the coordinates x and y.
Claudio Agostinelli
density.circular
and plot.density.circular
set.seed(1234) x <- rvonmises(n=100, mu=circular(pi), kappa=2) y <- rvonmises(n=100, mu=circular(pi/2), kappa=2) resx <- density(x, bw=25) res <- plot(resx, points.plot=TRUE, xlim=c(-1.5,1), ylim=c(-1.1, 1.5)) resy <- density(y, bw=25) lines(resy, points.plot=TRUE, col=2, points.col=2, plot.info=res)
set.seed(1234) x <- rvonmises(n=100, mu=circular(pi), kappa=2) y <- rvonmises(n=100, mu=circular(pi/2), kappa=2) resx <- density(x, bw=25) res <- plot(resx, points.plot=TRUE, xlim=c(-1.5,1), ylim=c(-1.1, 1.5)) resy <- density(y, bw=25) lines(resy, points.plot=TRUE, col=2, points.col=2, plot.info=res)
Fits a regression model for a circular dependent and circular independent variable or for a circular dependent and linear independent variables.
lm.circular(..., type=c("c-c", "c-l")) lm.circular.cc(y, x, order = 1, level = 0.05, control.circular = list()) lm.circular.cl(y, x, init = NULL, verbose = FALSE, tol = 1e-10, control.circular = list()) ## S3 method for class 'lm.circular.cl' print(x, digits = max(3, getOption("digits") - 3), signif.stars= getOption("show.signif.stars"), ...)
lm.circular(..., type=c("c-c", "c-l")) lm.circular.cc(y, x, order = 1, level = 0.05, control.circular = list()) lm.circular.cl(y, x, init = NULL, verbose = FALSE, tol = 1e-10, control.circular = list()) ## S3 method for class 'lm.circular.cl' print(x, digits = max(3, getOption("digits") - 3), signif.stars= getOption("show.signif.stars"), ...)
... |
arguments passed to |
type |
if |
y |
vector of data for the dependent circular variable. |
x |
vector of data for the independent circular variable if
|
order |
order of trigonometric polynomial to be fit. Order must be
an integer value. By default, order=1. Used if |
level |
level of the test for the significance of higher order
trigonometric terms. Used if |
control.circular |
the attribute of the resulting objects ( |
init |
a vector with initial values of length equal to the columns
of |
verbose |
logical: if |
tol |
the absolute accuracy to be used to achieve convergence of the algorithm. |
digits |
the number of digits to be printed. |
signif.stars |
logical; if |
If type=="c-c"
or lm.circular.cc
is called directly a
trigonometric polynomial of x is fit against the cosine and sine of y.
The order of trigonometric polynomial is specified by order. Fitted
values of y are obtained by taking the inverse tangent of the predicted
values of sin(y) divided by the predicted values of cos(y). Details of
the regression model can be found in Sarma and Jammalamadaka (1993).
If type=="c-l"
or lm.circular.cl
is called directly,
this function implements the homoscedastic version of the maximum
likelihood regression model proposed by Fisher and Lee (1992). The
model assumes that a circular response variable theta has a von Mises
distribution with concentration parameter kappa, and mean direction
related to a vector of linear predictor variables according to the
relationship: mu + 2*atan(beta'*x), where mu and beta are unknown
parameters, beta being a vector of regression coefficients. The
function uses Green's (1984) iteratively reweighted least squares
algorithm to perform the maximum likelihood estimation of kappa, mu,
and beta. Standard errors of the estimates of kappa, mu, and beta are
estimated via large-sample asymptotic variances using the information
matrix. An estimated circular standard error of the estimate of mu is
then obtained according to Fisher and Lewis (1983, Example 1).
If type=="c-c"
or lm.circular.cc
is called directly an
object of class lm.circular.cc
is returned with the following components:
call |
the |
rho |
square root of the average of the squares of the estimated conditional concentration parameters of y given x. |
fitted |
fitted values of the model of class |
data |
matrix whose columns correspond to x and y. |
residuals |
circular residuals of the model of class |
coefficients |
matrix whose entries are the estimated coefficients of the model. The first column corresponds to the coefficients of the model predicting the cosine of y, while the second column contains the estimates for the model predicting the sine of y. The rows of the matrix correspond to the coefficients according to increasing trigonometric order. |
p.values |
p-values testing whether the (order + 1) trigonometric terms are significantly different from zero. |
A.k |
is mean of the cosines of the circular residuals. |
kappa |
assuming the circular residuals come from a von Mises distribution, kappa is the MLE of the concentration parameter. |
If type=="c-l"
or lm.circular.cl
is called directly an
object of class lm.circular.cc
is returned with the following components:
call |
the |
x |
the independent variables. |
y |
the dependent variable. |
mu |
the circular mean of the dependent variable of class |
se.mu |
an estimated standard error of the circular mean with the same units of measure used for |
kappa |
the concentration parameter for the dependent variable. |
se.kappa |
an estimated standard error of the concentration parameter. |
coefficients |
the estimated coefficients. |
cov.coef |
covariance matrix of the estimated coefficients. |
se.coef |
standard errors of the estimated coefficients. |
log.lik |
log-likelihood. |
t.values |
values of the t statistics for the coefficients. |
p.values |
p-values of the t statistics. Approximated values using Normal distribution. |
Claudio Agostinelli and Ulric Lund
Fisher, N. and Lee, A. (1992). Regression models for an angular response. Biometrics, 48, 665-677.
Fisher, N. and Lewis, T. (1983). Estimating the common mean direction of several circular or spherical distributions with different dispersions. Biometrika, 70, 333-341.
Green, P. (1984). Iteratively reweighted least squares for maximum likelihood estimation, and some robust and resistant alternatives. Journal of the Royal Statistical Society, B, 46, 149-192.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 8.3, World Scientific Press, Singapore.
Sarma, Y. and Jammalamadaka, S. (1993). Circular Regression. Statistical Science and Data Analysis, 109-128. Proceeding of the Thrid Pacific Area Statistical Conference. VSP: Utrecht, Netherlands.
# Generate a data set of dependent circular variables. x <- circular(runif(50, 0, 2*pi)) y <- atan2(0.15*cos(x) + 0.25*sin(x), 0.35*sin(x)) + rvonmises(n=50, mu=circular(0), kappa=5) # Fit a circular-circular regression model. circ.lm <- lm.circular(y, x, order=1) # Obtain a crude plot of the data and fitted regression line. plot.default(x, y) circ.lm$fitted[circ.lm$fitted>pi] <- circ.lm$fitted[circ.lm$fitted>pi] - 2*pi points.default(x[order(x)], circ.lm$fitted[order(x)], type='l') # Fit a circular-linear regression model and show predictions. set.seed(1234) x <- cbind(rnorm(10), rep(1, 10)) x <- cbind(rnorm(10), rep(1,10)) y <- circular(2*atan(c(x%*%c(5,1))))+rvonmises(10, mu=circular(0), kappa=100) lm.circular(y=y, x=x, init=c(5,1), type='c-l', verbose=TRUE) plot(y) lmC <- lm.circular(y=y, x=x, init=c(5,1), type='c-l', verbose=TRUE) p <- circular(lmC$mu+2*atan(x%*%lmC$coefficients)) points(p, col=2, pch= "+")
# Generate a data set of dependent circular variables. x <- circular(runif(50, 0, 2*pi)) y <- atan2(0.15*cos(x) + 0.25*sin(x), 0.35*sin(x)) + rvonmises(n=50, mu=circular(0), kappa=5) # Fit a circular-circular regression model. circ.lm <- lm.circular(y, x, order=1) # Obtain a crude plot of the data and fitted regression line. plot.default(x, y) circ.lm$fitted[circ.lm$fitted>pi] <- circ.lm$fitted[circ.lm$fitted>pi] - 2*pi points.default(x[order(x)], circ.lm$fitted[order(x)], type='l') # Fit a circular-linear regression model and show predictions. set.seed(1234) x <- cbind(rnorm(10), rep(1, 10)) x <- cbind(rnorm(10), rep(1,10)) y <- circular(2*atan(c(x%*%c(5,1))))+rvonmises(10, mu=circular(0), kappa=100) lm.circular(y=y, x=x, init=c(5,1), type='c-l', verbose=TRUE) plot(y) lmC <- lm.circular(y=y, x=x, init=c(5,1), type='c-l', verbose=TRUE) p <- circular(lmC$mu+2*atan(x%*%lmC$coefficients)) points(p, col=2, pch= "+")
Fit a 2D circle to an (x,y) dataset using LS.
lsfit.circle(x, y, init = NULL, units = c("radians", "degrees"), template = c("none", "geographics"), modulo = c("asis", "2pi", "pi"), zero = 0, rotation = c("counter", "clock"), ...) ## S3 method for class 'lsfit.circle' print(x, digits = max(3, getOption("digits") - 3), ...)
lsfit.circle(x, y, init = NULL, units = c("radians", "degrees"), template = c("none", "geographics"), modulo = c("asis", "2pi", "pi"), zero = 0, rotation = c("counter", "clock"), ...) ## S3 method for class 'lsfit.circle' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
either a matrix with two columns or a vector. |
y |
if |
init |
initial values of the parameters. A vector of length 3 with
the following components: radius of the circle, x-coordinate of the
center, y-coordinate of the center. If |
units |
the |
template |
the |
modulo |
the |
zero |
the |
rotation |
the |
... |
further parameters passed to the |
digits |
the number of digits to be printed. |
lsfit.circle
uses the optim
function to minimize the sum of the
squared residuals between the observations and the optimally fitting circle.
An object of class lsfit.circle
.
coefficients |
a vector of length 3 with the estimated radius and coordinate of the center of the fitted circle. |
x |
the x-coordinate. |
y |
the y-coordinate. |
x.centered |
the x-coordinate re-centered at the center of the circle. |
y.centered |
the y-coordinate re-centered at the center of the circle. |
angles |
angles of the observations with respect to the center
coordinate of class |
radius |
the distance between the observations and the center coordinate |
convergence |
value from the function optim. |
optim |
the output from the function optim. |
call |
the |
Claudio Agostinelli and Ulric Lund
Coope, I. (1993). Circle fitting by linear and non-linear least squares. Journal of Optimization Theory and Applications, 76, 381-388.
data(coope) res <- lsfit.circle(x=x.coope, y=y.coope) res plot(res) par(mfcol=c(1,2)) plot(res$angles) hist(res$radius) plot(circular(0), type="n", xlim=c(-5.2, 5.2), ylim=c(-5.2, 5.2), xlab="The Radius of the circle \n is measured from the base line of the axes.") lines(x=res$angles, y=res$radius, join=TRUE, type="b") ff <- function(x) sqrt((res$coefficients[1]*cos(x))^2+(res$coefficients[1]*sin(x))^2) curve.circular(ff, add=TRUE, join=TRUE, nosort=FALSE, col=2) windrose(x=res$angles, y=res$radius)
data(coope) res <- lsfit.circle(x=x.coope, y=y.coope) res plot(res) par(mfcol=c(1,2)) plot(res$angles) hist(res$radius) plot(circular(0), type="n", xlim=c(-5.2, 5.2), ylim=c(-5.2, 5.2), xlab="The Radius of the circle \n is measured from the base line of the axes.") lines(x=res$angles, y=res$radius, join=TRUE, type="b") ff <- function(x) sqrt((res$coefficients[1]*cos(x))^2+(res$coefficients[1]*sin(x))^2) curve.circular(ff, add=TRUE, join=TRUE, nosort=FALSE, col=2) windrose(x=res$angles, y=res$radius)
Returns the mean direction of a vector of circular data.
## S3 method for class 'circular' mean(x, na.rm=FALSE, control.circular=list(), ...)
## S3 method for class 'circular' mean(x, na.rm=FALSE, control.circular=list(), ...)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
control.circular |
the attribute of the resulting object. |
... |
further arguments passed to or from other methods. |
Each observation is treated as a unit vector, or point on the unit
circle. The resultant vector of the observations is found, and the
direction of the resultant vector is returned. An NA
is
returned if the resultant length (see rho.circular
) is
less than .Machine
Returns the mean direction of the data as an object of class circular
with the attribute given by control.circular
or from x
if missed in control.circular
.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
var.circular
, summary.circular
,
mle.vonmises
, rho.circular
and .Machine
.
# Compute the mean direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) mean(x)
# Compute the mean direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) mean(x)
Returns a measure of spread associated with the circular median of a vector of circular data.
meandeviation(x, na.rm = FALSE)
meandeviation(x, na.rm = FALSE)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
See equation (2.33) at pag. 36 in Fisher (1993)
for its definition. In the case the circular median is not defined, that
is, every angle is a median axis, the mean deviation is not reported and
set to NA
.
Returns a measure of spread associated with the circular median of a vector of circular data.
Claudio Agostinelli and Alessandro Gagliardi
N.I. Fisher (1993) Statistical Analysis of Circular Data, Cambridge University Press.
median.circular
, sd.circular
, angular.variance
, angular.deviation
, mean.circular
, rho.circular
and summary.circular
.
x <- rvonmises(n=100, mu=circular(0), kappa=1) meandeviation(x)
x <- rvonmises(n=100, mu=circular(0), kappa=1) meandeviation(x)
Sample median direction for a vector of circular data
## S3 method for class 'circular' median(x, na.rm = FALSE, ...)
## S3 method for class 'circular' median(x, na.rm = FALSE, ...)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
... |
NotYetUsed. |
The Definition in equations 2.32 & 2.33 from N.I. Fisher's 'Statistical Analysis of Circular Data', Cambridge Univ. Press 1993. is implemented.
Since version 0.4-4, the algorithm (not the definition) for the
calculation of the median is changed. For a measure of spread associated to the circular median use function meandeviation
.
A scalar with the circular median value.
The median is returned as an object of class circular
.
Claudio Agostinelli and Alessandro Gagliardi
N.I. Fisher (1993) Statistical Analysis of Circular Data, Cambridge University Press.
R.Y. Liu and K. Singh (1992) Ordering Directional Data: Concepts of Data Depth on Circles and Spheres, The Annals of Statistics, vol. 20, n. 3, 1468-1484.
meandeviation
, mean.circular
, var.circular
, summary.circular
, rho.circular
and medianHL.circular
.
# Compute the median direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) median(x) #only the median is returned meandeviation(x) #mean deviation is reported
# Compute the median direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) median(x) #only the median is returned meandeviation(x) #mean deviation is reported
Sample median for a vector of data using Hodges-Lehmann estimate and Sample median direction measure for a vector of circular data using Hodges-Lehmann estimate.
medianHL(x, na.rm=FALSE, ...) ## Default S3 method: medianHL(x, na.rm=FALSE, method=c("HL1","HL2","HL3"), prop=NULL,...) ## S3 method for class 'circular' medianHL(x, na.rm=FALSE, method=c("HL1","HL2","HL3"), prop=NULL,...)
medianHL(x, na.rm=FALSE, ...) ## Default S3 method: medianHL(x, na.rm=FALSE, method=c("HL1","HL2","HL3"), prop=NULL,...) ## S3 method for class 'circular' medianHL(x, na.rm=FALSE, method=c("HL1","HL2","HL3"), prop=NULL,...)
x |
a vector. For the function |
na.rm |
logical, indicating if |
method |
The method used to calculate the median, see details below. |
prop |
The proportion of pairs that are sampled. If |
... |
further arguments passed to the next method. |
The algorithm is as follows:
The algorithm will create pairs of elements of the vector x
.
It will calculate the circular mean on those pairs.
It will calculate the circular median on these averages.
The type of pairs considered are controlled by method
:
if method
is "HL1" are considered unordered pairs without
replications and repetition in the number of (n*(n-1))/2
pairs;
if method
is "HL2" are considered unordered pairs without
replications in the number of (n*(n+1))/2
pairs;
if method
is "HL3" all pairs are considered in the number of n^2
.
If prop
is not NULL
, the algorithm will consider a
subsample following the rules specified by method
, however, the
number of pairs considered is prop * (number of pairs defined by method
).
For more details see Bennett Sango Otieno, 'An Alternative Estimate of Preferred Direction for Circular Data', Virginia Tech (2002) pag. 27-28 and 46-47.
For medianHL.circular
the median is returned as an object of
class circular
with the attribute given by those of x
.
An attributes medians
reports all the averages which are
minimizer of the circular median function.
Claudio Agostinelli and Alessandro Gagliardi.
Bennett Sango Otieno, An Alternative Estimate of Preferred Direction for Circular Data, Virginia Tech (July 2002).
Bennett Sango Otieno and Christine M. Anderson-Cook,Measures of preferred direction for environmental and ecological circular data, Springer (June 2004).
mean.circular
, median.circular
.
# Compute the median direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) # Calculate the three medians for each method without \code{prop} argument. medianHL.circular(x,method="HL1") medianHL.circular(x,method="HL2") medianHL.circular(x,method="HL3")
# Compute the median direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) # Calculate the three medians for each method without \code{prop} argument. medianHL.circular(x,method="HL1") medianHL.circular(x,method="HL2") medianHL.circular(x,method="HL3")
return angles in the (-pi,pi] interval.
minusPiPlusPi(x)
minusPiPlusPi(x)
x |
an object of class |
a circular
object with values in the interval (-pi,pi].
Claudio Agostinelli and Alessandro Gagliardi
x <- circular(c(0, 90, 180, 270), units="degrees") minusPiPlusPi(x)
x <- circular(c(0, 90, 180, 270), units="degrees") minusPiPlusPi(x)
Density and random generation for the mixed von Mises circular distribution.
dmixedvonmises(x, mu1, mu2, kappa1, kappa2, prop) rmixedvonmises(n, mu1, mu2, kappa1, kappa2, prop, control.circular = list()) pmixedvonmises(q, mu1, mu2, kappa1, kappa2, prop, from=NULL, tol = 1e-020)
dmixedvonmises(x, mu1, mu2, kappa1, kappa2, prop) rmixedvonmises(n, mu1, mu2, kappa1, kappa2, prop, control.circular = list()) pmixedvonmises(q, mu1, mu2, kappa1, kappa2, prop, from=NULL, tol = 1e-020)
x , q
|
a vector. The object is coerced to class |
n |
number of observations. |
mu1 |
mean direction of one of the two von Mises distributions as a |
mu2 |
mean direction of the other von Mises distribution as a |
kappa1 |
concentration parameter of one of the two von Mises distributions. |
kappa2 |
concentration parameter of the other von Mises distribution. |
prop |
mixing proportion. |
from |
if |
tol |
the precision in evaluating the distribution function or the quantile. |
control.circular |
the attribute of the resulting object. |
dmixedvonmises
gives the density, pmixedvonmises
gives the
distribution function and rmixedvonmises
generates random deviates.
Claudio Agostinelli and Ulric Lund
dvonmises
pvonmises
and rvonmises
x <- rmixedvonmises(n=100, mu1=circular(0), mu2=circular(pi), kappa1=15, kappa2=15, prop=0.5) plot(x)
x <- rmixedvonmises(n=100, mu1=circular(0), mu2=circular(pi), kappa1=15, kappa2=15, prop=0.5) plot(x)
Computes the maximum likelihood estimates for the parameters of a von Mises distribution: the mean direction and the concentration parameter.
mle.vonmises(x, mu=NULL, kappa=NULL, bias=FALSE, control.circular=list()) ## S3 method for class 'mle.vonmises' print(x, digits = max(3, getOption("digits") - 3), ...)
mle.vonmises(x, mu=NULL, kappa=NULL, bias=FALSE, control.circular=list()) ## S3 method for class 'mle.vonmises' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
a vector. The object is coerced to class
|
mu |
if |
kappa |
if |
bias |
logical, if |
control.circular |
the attribute of the resulting objects ( |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Best and Fisher (1981) show that the MLE of kappa is seriously biased when both sample size and mean resultant length are small. They suggest a bias-corrected estimate for kappa when n < 16.
Returns a list with the following components:
call |
the |
mu |
the estimate of the mean direction or the value supplied as an object of class |
kappa |
the estimate of the concentration parameter or the value supplied |
se.mu |
the standard error for the estimate of the mean
direction (0 if the value is supplied) in the same units of |
se.kappa |
the standard error for the estimate of the concentration parameter (0 if the value is supplied). |
est.mu |
TRUE if the estimator is reported. |
est.kappa |
TRUE if the estimator is reported. |
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 4.2.1, World Scientific Press, Singapore.
Best, D. and Fisher N. (1981). The bias of the maximum likelihood estimators of the von Mises-Fisher concentration parameters. Communications in Statistics - Simulation and Computation, B10(5), 493-502.
mean.circular
and mle.vonmises.bootstrap.ci
x <- rvonmises(n=50, mu=circular(0), kappa=5) mle.vonmises(x) # estimation of mu and kappa mle.vonmises(x, mu=circular(0)) # estimation of kappa only
x <- rvonmises(n=50, mu=circular(0), kappa=5) mle.vonmises(x) # estimation of mu and kappa mle.vonmises(x, mu=circular(0)) # estimation of kappa only
Generates simple bootstrap confidence intervals for the parameters of a von Mises distribution: the mean direction mu, and the concentration parameter kappa.
mle.vonmises.bootstrap.ci(x, mu = NULL, bias = FALSE, alpha = 0.05, reps = 1000, control.circular = list()) ## S3 method for class 'mle.vonmises.bootstrap.ci' print(x, ...)
mle.vonmises.bootstrap.ci(x, mu = NULL, bias = FALSE, alpha = 0.05, reps = 1000, control.circular = list()) ## S3 method for class 'mle.vonmises.bootstrap.ci' print(x, ...)
x |
vector of angular measurements as a |
mu |
If |
bias |
logical, if |
alpha |
parameter determining level of confidence intervals. 1-alpha confidence intervals for |
reps |
number of resampled data sets to use. Default is 1000. |
control.circular |
the attribute of the resulting objects ( |
... |
arguments passed to |
Percentile confidence intervals are computed by resampling from the original data set reps
times. For each resampled data set, the MLE's of mu and kappa are computed. The bootstrap confidence intervals are the alpha/2 and 1-alpha/2 percentiles of the reps
MLE's computed for each resampled data set.
A list is returned with the following components:
mu.ci |
limits of the confidence interval for mu as a |
kappa.ci |
limits of the confidence interval for kappa. |
mu |
estimate of mu as a |
kappa |
estimate of kappa. |
Claudio Agostinelli and Ulric Lund
x <- rvonmises(n=25, mu=circular(0), kappa=3) x.bs <- mle.vonmises.bootstrap.ci(x, alpha=.10) par(mfcol=c(1,2)) rose.diag(x.bs$mu, bins=30, main=expression(mu)) hist(x.bs$kappa, main=expression(kappa))
x <- rvonmises(n=25, mu=circular(0), kappa=3) x.bs <- mle.vonmises.bootstrap.ci(x, alpha=.10) par(mfcol=c(1,2)) rose.diag(x.bs$mu, bins=30, main=expression(mu)) hist(x.bs$kappa, main=expression(kappa))
Computes the maximum likelihood estimates for the parameters of a Wrapped Cauchy distribution: mean and concentration parameter.
mle.wrappedcauchy(x, mu = NULL, rho = NULL, tol = 1e-15, max.iter = 100, control.circular = list()) ## S3 method for class 'mle.wrappedcauchy' print(x, digits = max(3, getOption("digits") - 3), ...)
mle.wrappedcauchy(x, mu = NULL, rho = NULL, tol = 1e-15, max.iter = 100, control.circular = list()) ## S3 method for class 'mle.wrappedcauchy' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
a vector. The object is coerced to class
|
mu |
if |
rho |
if |
tol |
precision of the estimation. |
max.iter |
maximum number of iterations. |
control.circular |
the attribute of the resulting objects ( |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Returns a list with the following components:
call |
the |
mu |
the estimate of the mean direction or the value supplied as an object of class |
rho |
the estimate of the concentration parameter or the value supplied |
convergence |
TRUE if convergence is achieved. |
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 4.2.1, World Scientific Press, Singapore.
x <- rwrappedcauchy(n=50, mu=circular(0), rho=0.5) mle.wrappedcauchy(x) # estimation of mu and rho mle.wrappedcauchy(x, mu=circular(0)) # estimation of rho only
x <- rwrappedcauchy(n=50, mu=circular(0), rho=0.5) mle.wrappedcauchy(x) # estimation of mu and rho mle.wrappedcauchy(x, mu=circular(0)) # estimation of rho only
Computes the maximum likelihood estimates for the parameters of a Wrapped Normal distribution: mean and concentration parameter.
mle.wrappednormal(x, mu = NULL, rho = NULL, sd = NULL, K = NULL, tol = 1e-05, min.sd = 1e-3, min.k = 10, max.iter = 100, verbose = FALSE, control.circular=list()) ## S3 method for class 'mle.wrappednormal' print(x, digits = max(3, getOption("digits") - 3), ...)
mle.wrappednormal(x, mu = NULL, rho = NULL, sd = NULL, K = NULL, tol = 1e-05, min.sd = 1e-3, min.k = 10, max.iter = 100, verbose = FALSE, control.circular=list()) ## S3 method for class 'mle.wrappednormal' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
a vector. The object is coerced to class
|
mu |
if |
rho |
if |
sd |
standard deviation of the (unwrapped) normal. Used as an alternative parametrization. |
K |
number of terms to be used in approximating the density. |
tol |
precision of the estimation. |
min.sd |
minimum value should be reached by the search procedure for the standard deviation parameter. |
min.k |
minimum number of terms used in approximating the density. |
max.iter |
maximum number of iterations. |
verbose |
logical, if |
control.circular |
the attribute of the resulting objects ( |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Returns a list with the following components:
call |
the |
mu |
the estimate of the mean direction or the value supplied as an object of class |
rho |
the estimate of the concentration parameter or the value supplied |
sd |
the estimate of the standard deviation or the value supplied. |
est.mu |
TRUE if the estimator is reported. |
est.rho |
TRUE if the estimator is reported. |
convergence |
TRUE if the convergence is achieved. |
Claudio Agostinelli with a bug fix by Ana Nodehi
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 4.2.1, World Scientific Press, Singapore.
x <- rwrappednormal(n=50, mu=circular(0), rho=0.5) mle.wrappednormal(x) # estimation of mu and rho (and sd) mle.wrappednormal(x, mu=circular(0)) # estimation of rho (and sd) only
x <- rwrappednormal(n=50, mu=circular(0), rho=0.5) mle.wrappednormal(x) # estimation of mu and rho (and sd) mle.wrappednormal(x, mu=circular(0)) # estimation of rho (and sd) only
Evaluate the modal regions for a data set. Only the version for circular data is implemented.
modal.region(x, ...) ## Default S3 method: modal.region(x, ...) ## S3 method for class 'circular' modal.region(x, z=NULL, q=0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step=0.01, eps.lower=10^(-4), eps.upper=10^(-4), ...)
modal.region(x, ...) ## Default S3 method: modal.region(x, ...) ## S3 method for class 'circular' modal.region(x, z=NULL, q=0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step=0.01, eps.lower=10^(-4), eps.upper=10^(-4), ...)
x |
numeric or an object of class |
z |
numeric or object of class |
q |
numeric in the interval [0,1]. The quantile of the modal region. |
bw |
the smoothing bandwidth to be used. When the |
adjust |
the bandwidth used is actually |
type |
Not Yet Used. |
kernel |
a character string giving the smoothing kernel to be
used. This must be one of |
na.rm |
logical; if |
step |
numeric. Used in the construction of the regular grid |
eps.lower , eps.upper
|
the cut point in the density is searched in the interval [min(density)*(1+eps.lower),max(density)*(1-eps.upper)]. |
... |
further arguments passed to the next methods. |
Only the version for circular data is actually implemented.
A list of class modal.region.circular
with the following elements
zeros |
extremes of modal regions, possible as a matrix |
areas |
a list with two components: |
density |
the object from function |
q |
the modal region order as in input. |
level |
the cut point at the density scale. |
Claudio Agostinelli
L.G.R. Oliveira-Santos, C.A. Zucco and C. Agostinelli (2013) Using conditional circular kernel density functions to test hypotheses on animal circadian activity. Animal Behaviour, 85(1) 269-280.
x <- rvonmises(100, circular(pi), 10) res <- modal.region(x, bw=50) plot(res)
x <- rvonmises(100, circular(pi), 10) res <- modal.region(x, bw=50) plot(res)
In an experiment due to Ferguson et al. (1967) a number of northern cricket frogs (Acris crepitans) were collected from the mud flats of an abandoned stream meandering near Indianola, Mississippi, and taken to a test pen lying to the north west of the collection point. After 30 hours of enclosure within a dark environmental chamber, 14 of them were released and the directions taken by these frogs recorded. 0 degrees means North.
data(ncfrog)
data(ncfrog)
ncfrog
is a vector of 14 observations (in degrees).
ncfrog.rad
contains the same observations in radians (pi/180).
Collett, D. (1980) Outliers in Circular Data Applied Statistics 29, 1, 50–57.
Ferguson, D.E, Landreth, H.F. and McKeown, J.P. (1967) Sun compass orientation of the northern cricket frog, Acris crepitans. Anim. Behav., 14, 45–53.
This data set has 108 rows and 2 columns. The observations are the vanishing bearings of homing pigeons displaced and released at two unfamiliar locations. The data are pooled with respect to the home direction (home direction set in 360 grades).
data(pigeons)
data(pigeons)
This data frame contains the following columns:
treatment
, a factor with levels: c, control pigeon (unmanipulated); v1, pigeons subjected to bilateral section of the ophthalmic branch of the trigeminal nerve; on, pigeons subjected to bilateral section of the olfactory nerve
bearing
, vanishing bearing of each bird in degrees
Gagliardo A., Ioale' P., Savini M., and Wild M. (2008). Navigational abilities of homing pigeons deprived of olfactory or trigeminally mediated magnetic information when young. J. Exp. Biol., 211:2046–2051.
Creates a plot of circular data points on the current graphics device. Data points are either plotted as points on the unit circle, or the range of the circle is divided into a specified number of bins, and points are stacked in the bins corresponding to the number of observations in each bin.
## S3 method for class 'circular' plot(x, pch = 16, cex = 1, stack = FALSE, axes = TRUE, start.sep=0, sep = 0.025, shrink = 1, bins = NULL, ticks = FALSE, tcl = 0.025, tcl.text = 0.125, col = NULL, tol = 0.04, uin = NULL, xlim = c(-1, 1), ylim = c(-1, 1), digits = 2, units = NULL, template = NULL, zero = NULL, rotation = NULL, main = NULL, sub=NULL, xlab = "", ylab = "", control.circle=circle.control(), ...)
## S3 method for class 'circular' plot(x, pch = 16, cex = 1, stack = FALSE, axes = TRUE, start.sep=0, sep = 0.025, shrink = 1, bins = NULL, ticks = FALSE, tcl = 0.025, tcl.text = 0.125, col = NULL, tol = 0.04, uin = NULL, xlim = c(-1, 1), ylim = c(-1, 1), digits = 2, units = NULL, template = NULL, zero = NULL, rotation = NULL, main = NULL, sub=NULL, xlab = "", ylab = "", control.circle=circle.control(), ...)
x |
a vector, matrix or data.frame. The object is coerced to class |
pch |
point character to use. See help on |
cex |
point character size. See help on |
stack |
logical; if |
axes |
logical; if |
start.sep |
constant used to specify the distance between the center of the point and the axis. |
sep |
constant used to specify the distance between stacked points,
if |
shrink |
parameter that controls the size of the plotted circle. Default is 1. Larger values shrink the circle, while smaller values enlarge the circle. |
bins |
if |
ticks |
logical; if |
tcl |
length of the ticks. |
tcl.text |
The position of the axis labels. |
col |
color of the points. The values are recycled if needed. |
tol |
proportion of white space at the margins of plot. |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. Useful for centering the plot. |
digits |
number of digits used to print axis values. |
main , sub , xlab , ylab
|
title, subtitle, x label and y label of the plot. |
units |
the units used in the plot. |
template |
the template used in the plot. |
zero |
the zero used in the plot. |
rotation |
the rotation used in the plot. |
control.circle |
parameters passed to |
... |
further parameters passed to |
When there are many closely distributed observations, stacking is
recommended. When stacking the points, if there are many points in a particular bin, it may be necessary to shrink the plot of the circle so that all points fit. This is controlled with the parameter shrink
. Generally the parameter sep
does not need adjustment, however, when shrinking the plot, or for a very large number of observations, it may be helpful. Since version 0.3-9 the intervals are on the form [a,b).
A list with information on the plot: zero, rotation and next.points.
some codes from eqscplot
in MASS is used.
Claudio Agostinelli and Ulric Lund
axis.circular
, ticks.circular
, points.circular
, lines.circular
, rose.diag
, windrose
and curve.circular
.
# Generate 100 observations from a von Mises distribution. # with mean direction 0 and concentration 3. data.vm <- rvonmises(n=100, mu=circular(0), kappa=3) # Plot data set. All points do not fit on plot. plot(data.vm, stack=TRUE, bins=150) # Shrink the plot so that all points fit. plot(data.vm, stack=TRUE, bins=150, shrink=1.5) # Recentering the figure in a different place plot(data.vm, stack=TRUE, bins=150, xlim=c(-1,1.2), ylim=c(-1,0))
# Generate 100 observations from a von Mises distribution. # with mean direction 0 and concentration 3. data.vm <- rvonmises(n=100, mu=circular(0), kappa=3) # Plot data set. All points do not fit on plot. plot(data.vm, stack=TRUE, bins=150) # Shrink the plot so that all points fit. plot(data.vm, stack=TRUE, bins=150, shrink=1.5) # Recentering the figure in a different place plot(data.vm, stack=TRUE, bins=150, xlim=c(-1,1.2), ylim=c(-1,0))
The plot
method for density.circular
objects.
## S3 method for class 'density.circular' plot(x, main=NULL, sub=NULL, xlab=NULL, ylab="Density circular", type="l", zero.line=TRUE, points.plot=FALSE, points.col=1, points.pch=1, points.cex=1, plot.type=c("circle", "line"), axes=TRUE, ticks=FALSE, bins=NULL, offset=1, shrink=1, tcl=0.025, tcl.text = 0.125, sep=0.025, tol=0.04, digits=2, cex=1, uin=NULL, xlim=NULL, ylim=NULL, join=FALSE, nosort=FALSE, units=NULL, template=NULL, zero=NULL, rotation=NULL, control.circle=circle.control(), ...)
## S3 method for class 'density.circular' plot(x, main=NULL, sub=NULL, xlab=NULL, ylab="Density circular", type="l", zero.line=TRUE, points.plot=FALSE, points.col=1, points.pch=1, points.cex=1, plot.type=c("circle", "line"), axes=TRUE, ticks=FALSE, bins=NULL, offset=1, shrink=1, tcl=0.025, tcl.text = 0.125, sep=0.025, tol=0.04, digits=2, cex=1, uin=NULL, xlim=NULL, ylim=NULL, join=FALSE, nosort=FALSE, units=NULL, template=NULL, zero=NULL, rotation=NULL, control.circle=circle.control(), ...)
x |
an object of class |
main , sub , xlab , ylab , type
|
plotting parameters with useful defaults. |
zero.line |
logical; if |
points.plot |
logical; if |
points.col , points.pch , points.cex
|
parameters used to draw the points. |
plot.type |
type of the plot: "line": linear plot, "circle": circular plot. |
axes |
logical; if |
ticks |
logical; if |
bins |
number of ticks to plot. |
offset |
the radius of the circle |
shrink |
parameter that controls the size of the plotted function. Default is 1. |
tcl |
length of the ticks. |
tcl.text |
The position of the axis labels. |
sep |
constant used to specify the distance between stacked points. Default is 0.025; smaller values will create smaller spaces. |
tol |
proportion of white space at the margins of plot |
digits |
number of digits used to print axis values. |
cex |
point character size. See help on |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. Useful for centering the plot. |
join |
logical: should the first and the last point joined. |
nosort |
logical: should the data sort before plotting. Defaults is to sort. |
units |
units measure used in the plot. If |
template |
template used in the plot. If |
zero |
position of the zero used in the plot. If |
rotation |
rotation used in the plot. If |
control.circle |
parameters passed to |
... |
further parameters passed to |
A list with information on the plot: zero, rotation and next.points.
Claudio Agostinelli
density.circular
, lines.density.circular
, plot.circular
, lines.circular
and curve.circular
.
set.seed(1234) x <- rvonmises(n=100, mu=circular(pi), kappa=2) res25x <- density(x, bw=25) plot(res25x, points.plot=TRUE, xlim=c(-1.5,1)) res50x <- density(x, bw=25, adjust=2) lines(res50x, col=2) resp25x <- plot(res25x, points.plot=TRUE, xlim=c(-1, 1.3), ylim=c(-1.5,1.2), template="geographics", main="Plotting density estimate for two data set") y <- rvonmises(n=100, mu=circular(pi/2), kappa=2, control.circular=list(template="geographics")) res25y <- density(y, bw=25) lines(res25y, points.plot=TRUE, plot.info=resp25x, col=2, points.col=2) plot(res25x, plot.type="line", points.plot=TRUE, xlim=c(-1, 1.3), ylim=c(-1.5,1.2), template="geographics", main="Plotting density estimate for two data set") lines(res25y, plot.type="line", points.plot=TRUE, col=2, points.col=2)
set.seed(1234) x <- rvonmises(n=100, mu=circular(pi), kappa=2) res25x <- density(x, bw=25) plot(res25x, points.plot=TRUE, xlim=c(-1.5,1)) res50x <- density(x, bw=25, adjust=2) lines(res50x, col=2) resp25x <- plot(res25x, points.plot=TRUE, xlim=c(-1, 1.3), ylim=c(-1.5,1.2), template="geographics", main="Plotting density estimate for two data set") y <- rvonmises(n=100, mu=circular(pi/2), kappa=2, control.circular=list(template="geographics")) res25y <- density(y, bw=25) lines(res25y, points.plot=TRUE, plot.info=resp25x, col=2, points.col=2) plot(res25x, plot.type="line", points.plot=TRUE, xlim=c(-1, 1.3), ylim=c(-1.5,1.2), template="geographics", main="Plotting density estimate for two data set") lines(res25y, plot.type="line", points.plot=TRUE, col=2, points.col=2)
Plots the empirical distribution function of a circular data set.
## S3 method for class 'edf' plot(x, type = "s", xlim = c(0, 2 * pi), ylim = c(0, 1), ...) ## S3 method for class 'edf' lines(x, type = "s", ...)
## S3 method for class 'edf' plot(x, type = "s", xlim = c(0, 2 * pi), ylim = c(0, 1), ...) ## S3 method for class 'edf' lines(x, type = "s", ...)
x |
vector of circular data measured. |
type , xlim , ylim
|
plotting parameters with useful defaults. |
... |
optional graphical parameters. See help section on |
The vector of data is taken modulo 2*pi, and then the linear ranks are used to generate an empirical distribution function.
Creates a plot or adds a plot (lines.edf
) of the empirical
distribution function of the circular data vector.
Claudio Agostinelli and Ulric Lund
plot.ecdf
, curve.circular
and par
.
# Compare the edf's of two simulated sets of data. data1 <- rvonmises(n=10, mu=circular(0), kappa=3) data2 <- rvonmises(n=10, mu=circular(0), kappa=1) plot.edf(data1, xlab="Data", ylab="EDF", main="Plots of Two EDF's") lines.edf(data2, lty=2, col=2) #You can use standard ecdf and plot.ecdf functions ff <- function(x, data) { x <- x data <- data temp <- ecdf(data) temp(x) } plot(function(x) ff(x, data=data1), from=0, to=2*pi-3*.Machine$double.eps) #Or curve.circular plot.function.circular(function(x) ff(x, data=data1), from=0, to=(2*pi-3*.Machine$double.eps), join=FALSE, nosort=TRUE, xlim=c(-2,2), ylim=c(-2,2), modulo="asis", main="Empirical Distribution Function", n=2001, tcl.text=0.25) res <- plot.function.circular(function(x) ff(x, data=data2), from=0, to=(2*pi-3*.Machine$double.eps), join=FALSE, nosort=TRUE, modulo="asis", add=TRUE, col=2, n=2001) res1 <- points(data1, plot.info=res) points(data2, plot.info=res1, col=2, sep=0.05) legend(-1.9, 1.9, legend=c("data1", "data2"), col=c(1,2), lty=c(1,1))
# Compare the edf's of two simulated sets of data. data1 <- rvonmises(n=10, mu=circular(0), kappa=3) data2 <- rvonmises(n=10, mu=circular(0), kappa=1) plot.edf(data1, xlab="Data", ylab="EDF", main="Plots of Two EDF's") lines.edf(data2, lty=2, col=2) #You can use standard ecdf and plot.ecdf functions ff <- function(x, data) { x <- x data <- data temp <- ecdf(data) temp(x) } plot(function(x) ff(x, data=data1), from=0, to=2*pi-3*.Machine$double.eps) #Or curve.circular plot.function.circular(function(x) ff(x, data=data1), from=0, to=(2*pi-3*.Machine$double.eps), join=FALSE, nosort=TRUE, xlim=c(-2,2), ylim=c(-2,2), modulo="asis", main="Empirical Distribution Function", n=2001, tcl.text=0.25) res <- plot.function.circular(function(x) ff(x, data=data2), from=0, to=(2*pi-3*.Machine$double.eps), join=FALSE, nosort=TRUE, modulo="asis", add=TRUE, col=2, n=2001) res1 <- points(data1, plot.info=res) points(data2, plot.info=res1, col=2, sep=0.05) legend(-1.9, 1.9, legend=c("data1", "data2"), col=c(1,2), lty=c(1,1))
This is a plot method for objects of class lsfit.circle
.
## S3 method for class 'lsfit.circle' plot(x, add = FALSE, main = NULL, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, uin, tol = 0.04, plus.cex = 1, ...)
## S3 method for class 'lsfit.circle' plot(x, add = FALSE, main = NULL, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, uin, tol = 0.04, plus.cex = 1, ...)
x |
an object of class |
add |
logical: if |
main |
a main title for the plot. |
xlim |
the x limits (min,max) of the plot. |
ylim |
the y limits of the plot. |
xlab |
a label for the x axis. |
ylab |
a label for the x axis. |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
tol |
proportion of white space at the margins of plot. |
plus.cex |
dimension of the cross in the center of the circle. |
... |
further arguments passed to the next method. |
Claudio Agostinelli and Ulric Lund
data(coope) res <- lsfit.circle(x=x.coope, y=y.coope) plot(res)
data(coope) res <- lsfit.circle(x=x.coope, y=y.coope) plot(res)
Add points to a plot of circular data points on the current graphics device.
## S3 method for class 'circular' points(x, pch = 16, cex = 1, stack = FALSE, start.sep=0, sep = 0.025, shrink = 1, bins = NULL, col = NULL, next.points = NULL, plot.info = NULL, zero = NULL, rotation = NULL, ...)
## S3 method for class 'circular' points(x, pch = 16, cex = 1, stack = FALSE, start.sep=0, sep = 0.025, shrink = 1, bins = NULL, col = NULL, next.points = NULL, plot.info = NULL, zero = NULL, rotation = NULL, ...)
x |
a vector, matrix or data.frame. The object is coerced to class |
pch |
point character to use. See help on |
cex |
point character size. See help on par. |
stack |
logical: if |
start.sep |
constant used to specify the distance between the center of the point and the axis. |
sep |
constant used to specify the distance between stacked points,
if |
shrink |
parameter that controls the size of the plotted circle. Default is 1. Larger values shrink the circle, while smaller values enlarge the circle. |
bins |
if |
col |
color of the points. The values are recycled if needed. |
next.points |
if |
plot.info |
an object from |
zero |
the zero of the plot. Ignored if |
rotation |
the rotation of the plot. Ignored if |
... |
further parameters passed to |
When there are many closely distributed observations, stacking is
recommended. When stacking the points, if there are many points in a particular bin, it may be necessary to shrink the plot of the circle so that all points fit. This is controlled with the parameter shrink
. Generally the parameter sep
does not need adjustment, however, when shrinking the plot, or for a very large number of observations, it may be helpful. Since version 0.3-9 the intervals are on the form [a,b).
A list with information on the plot: zero, rotation and next.points.
Claudio Agostinelli
plot.circular
and lines.circular
.
data.1 <- rvonmises(n=100, mu=circular(0), kappa=3) data.2 <- rvonmises(n=100, mu=circular(pi/3), kappa=3) res <- plot(data.1, stack=FALSE, col=1) points(data.2, plot.info=res, col=2)
data.1 <- rvonmises(n=100, mu=circular(0), kappa=3) data.2 <- rvonmises(n=100, mu=circular(pi/3), kappa=3) res <- plot(data.1, stack=FALSE, col=1) points(data.2, plot.info=res, col=2)
Plots the empirical distribution of a data set against the best fitting von Mises distribution function.
pp.plot(x, ref.line = TRUE, tol=1e-20, xlab = "von Mises Distribution", ylab = "Empirical Distribution", control.circular = list(), ...)
pp.plot(x, ref.line = TRUE, tol=1e-20, xlab = "von Mises Distribution", ylab = "Empirical Distribution", control.circular = list(), ...)
x |
a vector. The object is coerced to class |
ref.line |
logical, if TRUE a 45 degree reference line is added to the plot. Default is TRUE. |
tol |
parameter passed to |
xlab , ylab
|
labels of the axis. |
control.circular |
the attribute of the resulting object. |
... |
parameters passed to the |
The maximum likelihood estimates of the parameters of the von Mises distribution are computed from the given data set. The empirical distribution function is plotted against a von Mises distribution function with parameters given by the MLEs computed.
a list with the estimated mean and concentration parameter for a von Mises distribution.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 10.2, World Scientific Press, Singapore.
x <- rvonmises(n=25, mu=circular(0), kappa=3) pp.plot(x) x <- c(rvonmises(n=20, mu=circular(0), kappa=7), rvonmises(n=20, mu=circular(pi), kappa=7)) pp.plot(x)
x <- rvonmises(n=25, mu=circular(0), kappa=3) pp.plot(x) x <- c(rvonmises(n=20, mu=circular(0), kappa=7), rvonmises(n=20, mu=circular(pi), kappa=7)) pp.plot(x)
Plots the empirical distribution of a data set against a uniform circular distribution function.
pp.unif.plot(x, ref.line = TRUE, frac = NULL, xlab = "Uniform Distribution", ylab = "Empirical Distribution", col = NULL, col.inf = NULL, col.sup = NULL, ...)
pp.unif.plot(x, ref.line = TRUE, frac = NULL, xlab = "Uniform Distribution", ylab = "Empirical Distribution", col = NULL, col.inf = NULL, col.sup = NULL, ...)
x |
a vector. The object is coerced to class |
ref.line |
logical, if TRUE a 45 degree reference line is added to the plot. Default is TRUE. |
frac |
a number in the [0,1] interval or |
xlab , ylab
|
labels of the axis. |
col |
color of the points. |
col.inf , col.sup
|
color of the |
... |
parameters passed to the |
Claudio Agostinelli
pp.plot for the von Mises distribution.
x <- rvonmises(n=25, mu=circular(0), kappa=3) pp.unif.plot(x) pp.unif.plot(x, frac=0.2)
x <- rvonmises(n=25, mu=circular(0), kappa=3) pp.unif.plot(x) pp.unif.plot(x, frac=0.2)
The projected normal distribution provides a flexible distribution for circular data, e.g., asymmetry and possible bimodality.
dpnorm(x, mu, sigma, log = FALSE) rpnorm(n, mu, sigma, control.circular=list())
dpnorm(x, mu, sigma, log = FALSE) rpnorm(n, mu, sigma, control.circular=list())
x |
a vector. The |
n |
number of observations. |
mu |
the mean vector of the bivariate normal. |
sigma |
the 2x2 variance and covariance matrix of the bivariate normal. |
log |
logical. If |
control.circular |
the attribute of the resulting object. |
dpnorm
gives the density, rpnorm
generates random deviates.
Claudio Agostinelli
S.R. Jammalamadaka and A. SenGupta (2001). Topics in Circular Statistics, Section 2.2.4, World Scientific Press, Singapore. K.V. Mardia (1972). Statistics of Directional Data. Academic Press. London and New York. F. Wang and A.E. Gelfand (2013). Directional data analysis under the general projected normal distribution. Stat Methodol. 10(1):113-127. doi:10.1016/j.stamet.2012.07.005.
data1 <- rpnorm(100, mu=c(0,0), sigma=diag(2), control.circular=list(units="degrees")) # Uniform on the circle plot(data1) ff <- function(x) dpnorm(x, mu=c(0,0), sigma=diag(2)) # Uniform on the circle curve.circular(ff, join=TRUE, main="Density of a Projected Normal Distribution \n mu=(0,0), sigma=diag(2)") ff <- function(x) dpnorm(x, mu=c(1,1), sigma=diag(2)) # Unimodal curve.circular(ff, join=TRUE, xlim=c(-1, 2.3), main="Density of a Projected Normal Distribution \n mu=(1,1), sigma=diag(2)") sigma <- matrix(c(1,0.9,0.9,1), nrow=2) ff <- function(x) dpnorm(x, mu=c(0.5,0.5), sigma=sigma) # Bimodal curve.circular(ff, join=TRUE, xlim=c(-1, 2.3), main="Density of a Projected Normal Distribution \n mu=(0.5,0.5), rho=0.9")
data1 <- rpnorm(100, mu=c(0,0), sigma=diag(2), control.circular=list(units="degrees")) # Uniform on the circle plot(data1) ff <- function(x) dpnorm(x, mu=c(0,0), sigma=diag(2)) # Uniform on the circle curve.circular(ff, join=TRUE, main="Density of a Projected Normal Distribution \n mu=(0,0), sigma=diag(2)") ff <- function(x) dpnorm(x, mu=c(1,1), sigma=diag(2)) # Unimodal curve.circular(ff, join=TRUE, xlim=c(-1, 2.3), main="Density of a Projected Normal Distribution \n mu=(1,1), sigma=diag(2)") sigma <- matrix(c(1,0.9,0.9,1), nrow=2) ff <- function(x) dpnorm(x, mu=c(0.5,0.5), sigma=sigma) # Bimodal curve.circular(ff, join=TRUE, xlim=c(-1, 2.3), main="Density of a Projected Normal Distribution \n mu=(0.5,0.5), rho=0.9")
The function quantile.circular
produces sample circular quantiles
corresponding to the given probabilities for a circular data set.
## S3 method for class 'circular' quantile(x, probs = seq(0, 1, 0.25), na.rm=FALSE, names = TRUE, type = 7, ...)
## S3 method for class 'circular' quantile(x, probs = seq(0, 1, 0.25), na.rm=FALSE, names = TRUE, type = 7, ...)
x |
numeric circular vector whose sample quantiles are wanted. |
probs |
numeric vector of probabilities with values in
|
na.rm |
logical; if true, any |
names |
logical; if true, the result has a |
type |
an integer between 1 and 9 selecting one of the nine quantile algorithms detailed below to be used. |
... |
further arguments passed to or from other methods.
Like |
A vector of length length(probs)
is returned;
if names = TRUE
, it has a names
attribute.
NA
and NaN
values in probs
are
propagated to the result.
The algorithm will proceed how described below: 1) Linearize the circular observations. 2) Calculate the linear median like type establish. 3) The value it will transformed in circular.
See description on documentation of quantile
.
Claudio Agostinelli and Alessandro Gagliardi.
x <- rvonmises(1001, mu=circular(pi), kappa=5) quantile.circular(x) # Extremes & Quartiles by default
x <- rvonmises(1001, mu=circular(pi), kappa=5) quantile.circular(x) # Extremes & Quartiles by default
Converts degrees to radians.
rad(x)
rad(x)
x |
vector or matrix of degree measurements. |
This function is available for compatibility with the CircStats
package, please use conversion.circular
.
Returns a vector or matrix of radian measurements corresponding to the data in degrees.
Claudio Agostinelli and Ulric Lund
Computes the circular range of a data set and performs a test of uniformity if specified.
## S3 method for class 'circular' range(x, test=FALSE, na.rm = FALSE, finite = FALSE, control.circular=list(), ...)
## S3 method for class 'circular' range(x, test=FALSE, na.rm = FALSE, finite = FALSE, control.circular=list(), ...)
x |
a vector. The object is coerced to class |
test |
logical flag: if TRUE then the test of uniformity is performed; otherwise the test is not performed. Default is FALSE. |
na.rm |
logical, indicating if |
finite |
logical, indicating if all non-finite elements should be omitted. |
control.circular |
the attribute of the resulting object. |
... |
further parameter passed from/to the method. |
The circular range is the shortest arc on the circle containing the entire set of data. The p-value is computed using the exact distribution of the circular range under the hypothesis of uniformity, details can be found in Mardia and Jupp (1999) pag. 107.
Returns the circular range as a circular
object. If the significance test is requested the p-value of the test is returned as p.value.
Claudio Agostinelli and Ulric Lund
K.V. Mardia and P.E. Jupp (1999) Directional Statistics, Wiley.
kuiper.test
, rao.spacing.test
,
rayleigh.test
and watson.test
.
data <- rvonmises(n=50, mu=circular(0), kappa=2) range(data, test=TRUE) data <- circular(runif(50, 0, 2*pi)) range(data, test=TRUE)
data <- rvonmises(n=50, mu=circular(0), kappa=2) range(data, test=TRUE) data <- circular(runif(50, 0, 2*pi)) range(data, test=TRUE)
Performs Rao's spacing test of uniformity.
rao.spacing.test(x, alpha=0) ## S3 method for class 'rao.spacing.test' print(x, digits = 4, ...)
rao.spacing.test(x, alpha=0) ## S3 method for class 'rao.spacing.test' print(x, digits = 4, ...)
x |
a vector. The object is coerced to class
|
alpha |
numeric value specifying the significance level of the test. The default value is 0, in which case, a range for the p-value will be returned. Valid significance levels are 0.10, 0.05, 0.01 and 0.001. |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
If alpha is specified, critical values are determined (using the print
function) from a table of simulated critical points (see reference below); in this case the print
function return a further value accepted
which is TRUE
if the null hypothesis is accepted and FALSE
otherwise. If alpha is not specified, a range for the p-value is determined using the table of simulated critical points in the print
function but not reported.
a list with the statistic, alpha and the number of observations.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 7.4, World Scientific Press, Singapore.
Rao, J.S. (1976). Some tests based on arc-lengths for the circle. Sankhya, The Indian Journal of Statistics, Serial B(4), 38, 329-338.
Russell, G.S. and Levitin, D.J. (1995). An expanded table of probability values for Rao's Spacing Test. Communications in Statistics - Simulation and Computation, 24, 4, 879-888.
range.circular
, kuiper.test
, rayleigh.test
and watson.test
x <- circular(runif(200, 0, 2*pi)) rao.spacing.test(x) res <- print(rao.spacing.test(x, alpha=0.1)) res$accepted x <- rvonmises(100, circular(0), 20) rao.spacing.test(x)
x <- circular(runif(200, 0, 2*pi)) rao.spacing.test(x) res <- print(rao.spacing.test(x, alpha=0.1)) res$accepted x <- rvonmises(100, circular(0), 20) rao.spacing.test(x)
Table for Rao's spacing test of uniformity
data(rao.table)
data(rao.table)
Ulric Lund
Performs Rao's test for homogeneity on k populations of angular data.
rao.test(..., alpha=0) ## S3 method for class 'rao.test' print(x, digits = 4, ...)
rao.test(..., alpha=0) ## S3 method for class 'rao.test' print(x, digits = 4, ...)
... |
a sequence of |
alpha |
numeric value specifying the significance level of the test. Default is 0, in which case p-values for the test statistic is printed. |
x |
an object from the |
digits |
integer indicating the precision to be used. |
Critical values and p-values are determined according to the chi-squared approximation of the test statistic.
A list with the statistic and p.value for the mean and the dispersion and the value of alpha.
The test is performed, and the results are written to the screen. Test results are given for both the test of equality of polar vectors, and of dispersions. If alpha is specified, the test statistic is printed, along with the level critical value. If alpha is not specified, a p-value for the test is printed.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 7.6.1, World Scientific Press, Singapore.
Rao, J.S. (1967). Large sample tests for the homogeneity of angular data, Sankhya, Ser, B., 28.
x <- rvonmises(100, circular(0), kappa=10) y <- rvonmises(100, circular(0), kappa=10) rao.test(x, y)
x <- rvonmises(100, circular(0), kappa=10) y <- rvonmises(100, circular(0), kappa=10) rao.test(x, y)
Performs a Rayleigh test of uniformity, assessing the significance of
the mean resultant length. The alternative hypothesis is a unimodal
distribution with unknown mean direction and unknown mean resultant
length if mu
is NULL
otherwise the alternative hypothesis is a unimodal distribution with a specified mean direction and unknown mean resultant length.
rayleigh.test(x, mu = NULL) ## S3 method for class 'rayleigh.test' print(x, digits=4, ...)
rayleigh.test(x, mu = NULL) ## S3 method for class 'rayleigh.test' print(x, digits=4, ...)
x |
a vector. The object is coerced to class
|
mu |
Specified mean direction in alternative hypothesis as a |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Returns a list with three components: the mean resultant length, statistic
, the p-value of the test statistic, p.value
and
the value of the alternative mean direction mu
.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Sections 3.3.2 and 3.4.1, World Scientific Press, Singapore.
range.circular
, kuiper.test
,
rao.spacing.test
and watson.test
x <- rvonmises(n=25, mu=circular(pi), kappa=2) # General alternative rayleigh.test(x) # Specified alternative rayleigh.test(x, mu=circular(0))
x <- rvonmises(n=25, mu=circular(pi), kappa=2) # General alternative rayleigh.test(x) # Specified alternative rayleigh.test(x, mu=circular(0))
Returns the mean resultant length of a vector of circular data.
rho.circular(x, na.rm = FALSE)
rho.circular(x, na.rm = FALSE)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
Each observation is treated as a unit vector, or point on the unit circle. The resultant vector of the observations is found, and the length of the resultant vector divided by the sample size is returned.
Returns the mean resultant length of data.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
mean.circular
, var.circular
,
summary.circular
and mle.vonmises
.
# Compute the mean resultant length of a random sample of observations. data <- circular(runif(100, 0, 2*pi)) rho.circular(data)
# Compute the mean resultant length of a random sample of observations. data <- circular(runif(100, 0, 2*pi)) rho.circular(data)
Creates a rose diagram of a circular data set on the current graphics device.
rose.diag(x, pch = 16, cex = 1, axes = TRUE, shrink = 1, bins = NULL, upper = TRUE, ticks = TRUE, tcl = 0.025, tcl.text = 0.125, radii.scale = c("sqrt", "linear"), border=NULL, col=NULL, tol = 0.04, uin = NULL, xlim = c(-1, 1), ylim = c(-1, 1), prop = 1, digits = 2, plot.info = NULL, units = NULL, template = NULL, zero = NULL, rotation = NULL, main = NULL, sub = NULL, xlab = "", ylab = "", add = FALSE, control.circle = circle.control(), ...)
rose.diag(x, pch = 16, cex = 1, axes = TRUE, shrink = 1, bins = NULL, upper = TRUE, ticks = TRUE, tcl = 0.025, tcl.text = 0.125, radii.scale = c("sqrt", "linear"), border=NULL, col=NULL, tol = 0.04, uin = NULL, xlim = c(-1, 1), ylim = c(-1, 1), prop = 1, digits = 2, plot.info = NULL, units = NULL, template = NULL, zero = NULL, rotation = NULL, main = NULL, sub = NULL, xlab = "", ylab = "", add = FALSE, control.circle = circle.control(), ...)
x |
a vector, matrix or data.frame. The object is coerced to class |
pch |
point character to use. See help on |
cex |
point character size. See help on |
axes |
logical: if |
shrink |
parameter that controls the size of the plotted circle. Default is 1. Larger values shrink the circle, while smaller values enlarge the circle. |
bins |
number of arcs to partition the circle with. |
upper |
therose diagram cells are "upper"-closed intervals. |
ticks |
logical: if |
tcl |
length of the ticks. |
tcl.text |
the position of the axis labels. |
radii.scale |
make possible to choose sector radius form:
square-root of relative frequency ( |
border |
the color to draw the border. The default, |
col |
the color for filling the rose diagram. The default,
|
tol |
proportion of white space at the margins of plot. |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. Useful for centering the plot. |
prop |
numerical constant determining the radii of the sectors. By default, prop = 1. |
digits |
number of digits used to print axis values. |
plot.info |
an object from |
units |
the |
template |
the template of the plot. Ignored if |
zero |
the zero of the plot. Ignored if |
rotation |
the rotation of the plot. Ignored if |
main , sub , xlab , ylab
|
title, subtitle, x label and y label of the plot. |
add |
add the rose diag to an existing plot. |
control.circle |
parameters passed to |
... |
further parameters passed to |
The circumference of the circle is split into groups, the number of groups specified by bins. For each group, a sector is drawn. The radii of the sectors are by default equal to the square root of the relative frequencies of observations in each group. This ensures that the area of the sector is proportional to the group frequency. The length of the radii can be controlled by varying the parameter prop. Since version 0.3-9 the intervals are on the form [a,b).
a list with information on the plot: zero, rotation and next.points.
some codes from eqscplot
in MASS is used. Since
version 0.4-1 the meaning of the col
parameter is changed.
Claudio Agostinelli, Ulric Lund and Hiroyoshi Arai
# Generate uniform data and create several rose diagrams. # Some optional parameters may be needed to optimize plots. x <- circular(runif(50, 0, 2*pi)) rose.diag(x, bins = 18, main = 'Uniform Data') points(x) # Generate von Mises data and create several rose diagrams. x <- rvonmises(n=50, mu=circular(0), kappa=5, control.circular=list(zero=pi/4)) y <- rose.diag(x, bins=18) # Points fall out of bounds. points(x, plot.info=y, stack=TRUE) y <- rose.diag(x, bins=18, prop=1.5, shrink=1.5) # Adjust optional parameters to fit ######## all points on plot. points(x, plot.info=y, stack=TRUE) # Add the rose diag to a plot plot(x) rose.diag(x, bins=12, add=TRUE, col=2) # Examples on using radii.scale and prop with a dummy dataset where # highest proportion is 50% in bin 2 x <- c(2, 2, 2, 2, 5, 5, 10, 20) circ.x <- circular::circular(x, units = "hours", template = "clock24") old_par <- par(mfrow = c(2, 2)) rose.diag(circ.x, bins=24, main="radii.scale=linear, prop=1", radii.scale="linear", prop=1) rose.diag(circ.x, bins=24, main = "radii.scale=linear, prop=2", radii.scale="linear", prop=2) rose.diag(circ.x, bins=24, main = "radii.scale=sqrt, prop=1", radii.scale="sqrt", prop=1) rose.diag(circ.x, bins=24, main = "radii.scale=sqrt, prop=sqrt(2)", radii.scale="sqrt", prop=sqrt(2)) par(old_par)
# Generate uniform data and create several rose diagrams. # Some optional parameters may be needed to optimize plots. x <- circular(runif(50, 0, 2*pi)) rose.diag(x, bins = 18, main = 'Uniform Data') points(x) # Generate von Mises data and create several rose diagrams. x <- rvonmises(n=50, mu=circular(0), kappa=5, control.circular=list(zero=pi/4)) y <- rose.diag(x, bins=18) # Points fall out of bounds. points(x, plot.info=y, stack=TRUE) y <- rose.diag(x, bins=18, prop=1.5, shrink=1.5) # Adjust optional parameters to fit ######## all points on plot. points(x, plot.info=y, stack=TRUE) # Add the rose diag to a plot plot(x) rose.diag(x, bins=12, add=TRUE, col=2) # Examples on using radii.scale and prop with a dummy dataset where # highest proportion is 50% in bin 2 x <- c(2, 2, 2, 2, 5, 5, 10, 20) circ.x <- circular::circular(x, units = "hours", template = "clock24") old_par <- par(mfrow = c(2, 2)) rose.diag(circ.x, bins=24, main="radii.scale=linear, prop=1", radii.scale="linear", prop=1) rose.diag(circ.x, bins=24, main = "radii.scale=linear, prop=2", radii.scale="linear", prop=2) rose.diag(circ.x, bins=24, main = "radii.scale=sqrt, prop=1", radii.scale="sqrt", prop=1) rose.diag(circ.x, bins=24, main = "radii.scale=sqrt, prop=sqrt(2)", radii.scale="sqrt", prop=sqrt(2)) par(old_par)
Returns random deviates from the stable family of probability distributions.
rstable(n, scale = 1, index = stop("no index arg"), skewness = 0)
rstable(n, scale = 1, index = stop("no index arg"), skewness = 0)
n |
sample size. |
index |
number from the interval (0, 2]. An index of 2 corresponds to the normal, 1 to the Cauchy. Smaller values mean longer tails. |
skewness |
number giving the modified skewness (see Chambers et al., 1976). Negative values correspond to skewness to the left (the median is smaller than the mean, if it exists), and positive values correspond to skewness to the right (the median is larger than the mean). The absolute value of skewness should not exceed 1. |
scale |
the scale of the distribution. |
This function return random variates from the Levy skew stable
distribution with index
=,
scale
= and
skewness
=. The
skewness
parameter must lie in the range [-1,1] while the index
parameter must lie in the range (0,2]. The Levy skew stable probability distribution is defined by a Fourier transform,
When the term
is replaced by
. For
the distribution reduces to a Gaussian distribution with
and the skewness parameter has no effect. For
the tails of the distribution become extremely wide. The symmetric distribution corresponds to
.
The Levy alpha-stable distributions have the property that if alpha-stable variates are drawn from the distribution
then the sum
will also be distributed as an alpha-stable variate,
.
There is no explicit solution for the form of and there are no density, probability or quantile functions supplied for this distribution.
random sample from the specified stable distribution.
Claudio Agostinelli
Chambers, J. M., Mallows, C. L. and Stuck, B. W. (1976). A Method for Simulating Stable Random Variables. Journal of the American Statistical Association 71, 340-344.
Logaeve, M. (1977). Probability Theory I. (fourth edition) Springer-Verlag, New York.
hist(rstable(200, 1.5, .5)) #fairly long tails, skewed right
hist(rstable(200, 1.5, .5)) #fairly long tails, skewed right
Generates pseudo-random numbers from a wrapped stable distribution.
rwrappedstable(n, scale=1, index, skewness, control.circular=list())
rwrappedstable(n, scale=1, index, skewness, control.circular=list())
n |
number of random numbers to generate. |
scale |
the scale of the distribution. |
index |
number from the interval (0, 2]. An index of 2 corresponds to the normal, 1 to the Cauchy. Smaller values mean longer tails. |
skewness |
number giving the modified skewness. Negative values correspond to skewness to the left (the median is smaller than the mean, if it exists), and positive values correspond to skewness to the right (the median is larger than the mean). The absolute value of skewness should not exceed 1. |
control.circular |
the attribute of the resulting object. |
n random numbers are generated from a stable distribution with with parameters index, skewness and scale. The function returns these values modulo 2*pi.
Returns a vector of n independent random numbers generated from a wrapped stable distribution.
Claudio Agostinelli
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.8, World Scientific Press, Singapore.
The sd
function from the base is replace by a new
method
in order to report the standard deviation of circular data
appropriately. sd.default
is an alias of the original function
sd
see sd
. The behavior would be the same
for objects which are not from class
data.frame
and circular
(in the last case
the standard deviation is define as in Mardia (1972)
where r
is the mean resultant length of
the data, see sd.circular
for more details). The method for
data.frame
will apply the sd
function to each columns.
sd(x, ...) ## Default S3 method: sd(x, na.rm = FALSE, ...) ## S3 method for class 'data.frame' sd(x, ...)
sd(x, ...) ## Default S3 method: sd(x, na.rm = FALSE, ...) ## S3 method for class 'data.frame' sd(x, ...)
x |
a numeric vector, matrix or data frame. |
na.rm |
logical. Should missing values be removed? |
... |
further arguments passed to or from other methods. |
sd
, sd.circular
, var.circular
and summary.circular
.
Returns the circular standard deviation of a vector of circular data which is defined as the square root of minus 2 times the log of the mean resultant length divided by the number of observations.
## S3 method for class 'circular' sd(x, na.rm = FALSE, ...)
## S3 method for class 'circular' sd(x, na.rm = FALSE, ...)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
... |
further arguments passed to or from other methods. |
Computes the circular standard deviation as defined by Mardia (1972)
where r
is the mean resultant length of the data.
Returns the circular standard deviation.
Claudio Agostinelli and Jean-Olivier Irisson
Mardia, K.V. (1972) Statistics of Directional Data. Academic Press, London, sec. 26.5, p. 617
Fisher, N.I. (1993) Statistical analysis of circular data. Cambridge University Press.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
Zar, J H (2010). Biostatistical analysis. Prentice Hall. sec. 26.5, p. 617
var.circular
, angular.deviation
, mean.circular
, rho.circular
and summary.circular
.
# Compute the circular standard deviation of a random # sample of observations from a von Mises distribution x <- rvonmises(n=100, mu=circular(0, units="degrees"), kappa=10) sd(x)
# Compute the circular standard deviation of a random # sample of observations from a von Mises distribution x <- rvonmises(n=100, mu=circular(0, units="degrees"), kappa=10) sd(x)
Computes circular summary statistics including the sample size, mean direction and mean resultant length and quartiles.
## S3 method for class 'circular' summary(object, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'circular' summary(object, digits = max(3, getOption("digits") - 3), ...)
object |
an object of class |
digits |
digits to be used in printing. |
... |
parameters passed to |
Each observation is treated as a unit vector or a point on the unit circle. The resultant vector of the observations is found, and the direction of the resultant vector is returned as well as its length divided by the sample size.
Returns a vector with the sample size, the sample mean direction and the sample mean resultant length.
Claudio Agostinelli, David Andel and Alessandro Gagliardi
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
mean.circular
, median.circular
,
quantile.circular
, var.circular
,
mle.vonmises
, rho.circular
.
# Compute summary statistics of a random sample of observations. data <- circular(runif(50, 0, pi)) summary(data) summary(data.frame(data, runif(50, 0, pi)))
# Compute summary statistics of a random sample of observations. data <- circular(runif(50, 0, pi)) summary(data) summary(data.frame(data, runif(50, 0, pi)))
The _swallows_ dataset has 114 rows and 2 columns. The observations are the headings of juvenile barn swallows (_Hirundo rustica_) tested in orientation cages (Emlen funnels) during autumn migration under simulated overcast conditions.
data(swallows)
data(swallows)
A data frame with 114 observations on the following 2 variables.
treatment
a factor with levels control
(control
group: local magnetic field) and
shifted
(shifted magnetic field, magnetic North =
geographical West)
heading
a numeric vector: modal heading of each bird
Giunchi, D., and Baldaccini N. E. (2004) Orientation of juvenile barn swallows (Hirundo rustica) tested in Emlen funnels during autumn migration. Behav. Ecol. Sociobiol. (56):124-131.
data(swallows) swallows <- split(swallows$heading, swallows$treatment) swallows <- lapply(swallows, function(x) circular(x, units='degrees', template='geographics')) plot(swallows[[1]]) points(swallows[[2]], col=2) legend('topright', legend=c('control', 'shifted'), pch=c(19,19), col=c(1,2))
data(swallows) swallows <- split(swallows$heading, swallows$treatment) swallows <- lapply(swallows, function(x) circular(x, units='degrees', template='geographics')) plot(swallows[[1]]) points(swallows[[2]], col=2) legend('topright', legend=c('control', 'shifted'), pch=c(19,19), col=c(1,2))
Draw tick-marks in a circular plot.
ticks.circular(x, template = c("none", "geographics"), zero = NULL, rotation = NULL, tcl = 0.025, col = NULL, ...)
ticks.circular(x, template = c("none", "geographics"), zero = NULL, rotation = NULL, tcl = 0.025, col = NULL, ...)
x |
the points at which tick-marks are to be drawn. |
template |
either |
zero |
the zero of the plot (in radians). |
rotation |
the rotation of the plot. |
col |
color for the tick marks. If |
tcl |
The length of tick marks. |
... |
parameters passed to |
Claudio Agostinelli
plot.circular
and axis.circular
.
The total variation distance between two circular samples is evaluated conditional on a circular modal region.
totalvariation.circular(x, y, z = NULL, q = 0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step = 0.001, eps.lower = 10^(-4), eps.upper = 10^(-4), ...)
totalvariation.circular(x, y, z = NULL, q = 0.95, bw, adjust = 1, type = c("K", "L"), kernel = c("vonmises", "wrappednormal"), na.rm = FALSE, step = 0.001, eps.lower = 10^(-4), eps.upper = 10^(-4), ...)
x |
numeric or an object of class |
y |
numeric or an object of class |
z |
numeric or object of class |
q |
numeric in the interval [0,1]. The quantile of the modal region. |
bw |
the smoothing bandwidth to be used. When the |
adjust |
the bandwidth used is actually |
type |
Not Yet Used. |
kernel |
a character string giving the smoothing kernel to be
used. This must be one of |
na.rm |
logical; if |
step |
numeric. Used in the construction of the regular grid |
eps.lower , eps.upper
|
the cut point in the density is searched in the interval [min(density)*(1+eps.lower),max(density)*(1-eps.upper)]. |
... |
further arguments passed to the
|
A list of class totalvariation.circular
with the following
components
tv |
the (conditional) total variation. |
ovl |
the (conditional) overlapping coefficient. |
q |
the order of the modal regions. |
bw |
the bandwidth value as in input. |
modal.x |
an object of class |
modal.y |
an object of class |
density.x |
an object of class |
density.y |
an object of class |
density |
a function which report the positive part of the difference between the estimated density of the two data sets. |
Claudio Agostinelli
L.G.R. Oliveira-Santos, C.A. Zucco and C. Agostinelli (2013) Using conditional circular kernel density functions to test hypotheses on animal circadian activity. Animal Behaviour, 85(1) 269-280.
x <- rvonmises(100, circular(pi), 10) y <- rvonmises(100, circular(pi+pi/8), 10) res <- totalvariation.circular(x,y,bw=50) plot(res)
x <- rvonmises(100, circular(pi), 10) y <- rvonmises(100, circular(pi+pi/8), 10) res <- totalvariation.circular(x,y,bw=50) plot(res)
Density and random generation for the Triangular circular distribution.
dtriangular(x, rho) rtriangular(n, rho, control.circular=list())
dtriangular(x, rho) rtriangular(n, rho, control.circular=list())
x |
a vector. The object is coerced to class |
n |
number of observations. |
rho |
concentration parameter of the distribution. rho must be
between 0 and |
control.circular |
the attribute of the resulting object. |
dtriangular
gives the density and rtriangular
generates
random deviates.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.3, World Scientific Press, Singapore.
data1 <- rtriangular(100, 0.3, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dtriangular(x, rho=0.3) curve.circular(ff, shrink=1.2, join=TRUE)
data1 <- rtriangular(100, 0.3, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dtriangular(x, rho=0.3) curve.circular(ff, shrink=1.2, join=TRUE)
Computes the specified order trigonometric moment for a set of directional data points.
trigonometric.moment(x, p = 1, center = FALSE, control.circular = list())
trigonometric.moment(x, p = 1, center = FALSE, control.circular = list())
x |
a vector of class |
p |
order of trigonometric moment to be computed. Default is for a first order trigonometric moment. |
center |
logical, whether to compute centered moments or not. Default is to compute an uncentered moment. |
control.circular |
the attribute of the resulting object |
Returns a list with variables mu, rho, cos, sin, p, n, call, respectively the pth trigonometric moment's direction, resultant length, real and imaginary components, the order, the number of observations and the call.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
var.circular
, mean.circular
,
summary.circular
, mle.vonmises
and rho.circular
x <- rvonmises(100, circular(0), 5) trigonometric.moment(x, control.circular=list(units="degrees"))
x <- rvonmises(100, circular(0), 5) trigonometric.moment(x, control.circular=list(units="degrees"))
The _turtles_ dataset has 10 rows and 2 columns. The observations are the directions from which 10 green sea turtles approached their nesting island (Ascension Island, South Atlantic Ocean) after having been displaced to open-sea sites.
data(turtles)
data(turtles)
A data frame with 10 observations on the following 2 variables.
id
a numeric vector: the turtle ID
arrival
a numeric vector: the direction of arrival to Ascension Island
Luschi, P., Akesson, S., Broderick, A. C., Glen, F., Godley, B. J., Papi F., and Hays, G. C. (2001) Testing the navigational abilities of ocean migrants: displacement experiments on green sea turtles (_Chelonia mydas_). Behav. Ecol. Sociobiol. (50):528-534.
data(turtles) turtles[,2] <- circular(turtles[,2], units='degrees', template='geographics') plot(turtles[,2])
data(turtles) turtles[,2] <- circular(turtles[,2], units='degrees', template='geographics') plot(turtles[,2])
unique.circular
returns a circular vector but with duplicate elements removed.
## S3 method for class 'circular' unique(x, ...)
## S3 method for class 'circular' unique(x, ...)
x |
a vector or a data frame or an array or |
... |
parameters passed to |
This is a method for circular
object. See the documentation of unique
.
An object of the same type of x
, but if
an element is equal to one with a smaller index, it is removed.
x <- rvonmises(10, circular(0), 10) unique(x)
x <- rvonmises(10, circular(0), 10) unique(x)
The var
function from the stats is replace by a new
method
in order to report the variance of circular data
appropriately. var.default
is an alias of the original function
var
see cor
. The behavior would be the same for objects which are not
from class
data.frame
and
circular
(in the last case the variance is define as one
minus the mean resultant length divided by the sample size of data, see
var.circular
for more details). The method for
data.frame
will apply the var
function to each columns.
var(x, ...) ## Default S3 method: var(x, y = NULL, na.rm = FALSE, use, ...) ## S3 method for class 'data.frame' var(x, ...)
var(x, ...) ## Default S3 method: var(x, y = NULL, na.rm = FALSE, use, ...) ## S3 method for class 'data.frame' var(x, ...)
x |
a numeric vector, matrix or data frame. |
y |
|
na.rm |
logical. Should missing values be removed? |
use |
an optional character string giving a
method for computing covariances in the presence
of missing values. This must be (an abbreviation of) one of the strings
|
... |
further arguments passed to or from other methods. |
cor
, var.circular
, rho.circular
and summary.circular
.
Returns one minus the mean resultant length divided by the sample size of a vector of circular data.
## S3 method for class 'circular' var(x, na.rm = FALSE, ...)
## S3 method for class 'circular' var(x, na.rm = FALSE, ...)
x |
a vector. The object is coerced to class
|
na.rm |
logical, indicating if |
... |
further arguments passed to or from other methods. |
Returns one minus the mean resultant length divided by the sample size of data.
Claudio Agostinelli and Ulric Lund
Mardia, K.V. (1972) Statistics of Directional Data. Academic Press, London.
Fisher, N.I. (1993) Statistical analysis of circular data. Cambridge University Press.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 1.3, World Scientific Press, Singapore.
sd.circular
, angular.variance
, mean.circular
, rho.circular
and summary.circular
.
x <- rvonmises(n=100, mu=circular(0), kappa=1) var(x)
x <- rvonmises(n=100, mu=circular(0), kappa=1) var(x)
Density, distribution function, random generation and quantiles for the von Mises circular distribution.
rvonmises(n, mu, kappa, control.circular=list()) dvonmises(x, mu, kappa, log) pvonmises(q, mu, kappa, from=NULL, tol = 1e-020) qvonmises(p, mu = circular(0), kappa=NULL, from=NULL, tol = .Machine$double.eps^(0.6), control.circular = list(), ...)
rvonmises(n, mu, kappa, control.circular=list()) dvonmises(x, mu, kappa, log) pvonmises(q, mu, kappa, from=NULL, tol = 1e-020) qvonmises(p, mu = circular(0), kappa=NULL, from=NULL, tol = .Machine$double.eps^(0.6), control.circular = list(), ...)
x , q , p
|
a vector. The |
n |
number of observations. |
mu |
mean direction of the distribution. The object is coerced to class |
kappa |
non-negative numeric value for the concentration parameter of the distribution. |
log |
logical; if TRUE, probabilities p are given as log(p). |
from |
if |
tol |
the precision in evaluating the distribution function or the quantile. |
control.circular |
the attribute of the resulting object. |
... |
parameters passed to |
dvonmises
gives the density, pvonmises
gives the
distribution function, rvonmises
generates random deviates and
qvonmises
provides quantiles.
Since version 0.3-5 the random deviates are generated using a C code.
Claudio Agostinelli, Ulric Lund and Harry Southworth
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.4, World Scientific Press, Singapore.
data1 <- rvonmises(100, circular(0), 10, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dvonmises(x, mu=circular(pi), kappa=10) curve.circular(ff, join=TRUE, xlim=c(-2.3, 1), main="Density of a VonMises Distribution \n mu=pi, kappa=10") ff <- function(x) pvonmises(x, mu=circular(pi), kappa=10) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 1), to=(2*pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a VonMises Distribution \n mu=pi, kappa=10") plot(function(x) qvonmises(x, mu=circular(0), kappa=5), from=0, to=1) ##curve do not work! plot(function(x) qvonmises(x, mu=circular(pi), kappa=5), from=0, to=1) plot(function(x) qvonmises(x, mu=circular(pi), kappa=5, from=circular(pi/2)), from=0, to=1)
data1 <- rvonmises(100, circular(0), 10, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dvonmises(x, mu=circular(pi), kappa=10) curve.circular(ff, join=TRUE, xlim=c(-2.3, 1), main="Density of a VonMises Distribution \n mu=pi, kappa=10") ff <- function(x) pvonmises(x, mu=circular(pi), kappa=10) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 1), to=(2*pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a VonMises Distribution \n mu=pi, kappa=10") plot(function(x) qvonmises(x, mu=circular(0), kappa=5), from=0, to=1) ##curve do not work! plot(function(x) qvonmises(x, mu=circular(pi), kappa=5), from=0, to=1) plot(function(x) qvonmises(x, mu=circular(pi), kappa=5, from=circular(pi/2)), from=0, to=1)
Performs the Wallraff test of angular distances or angular dispersion around the mean.
wallraff.test(x, ...) ## Default S3 method: wallraff.test(x, group, ref=NULL, ...) ## S3 method for class 'list' wallraff.test(x, ref=NULL, ...) ## S3 method for class 'formula' wallraff.test(formula, data, ref=NULL, ...)
wallraff.test(x, ...) ## Default S3 method: wallraff.test(x, group, ref=NULL, ...) ## S3 method for class 'list' wallraff.test(x, ref=NULL, ...) ## S3 method for class 'formula' wallraff.test(formula, data, ref=NULL, ...)
x |
a vector of angles (coerced to class |
group |
a vector or factor object giving the group for the corresponding elements of |
formula |
a formula of the form |
data |
an optional data.frame containing the variables in the formula |
ref |
a vector of angles used as reference to compute the angular distances from, in each group. It should contain as many elements as there are groups, in the same order. If In the default or formula interfaces, if the grouping vector is a factor, the order is the order of its levels; if the grouping vector is not a factor, it is coerced as such but with levels in the order of their appearance in the original vector. In this case a warning is issued to make sure the order of If If |
... |
further arguments passed to or from other methods. |
The Wallraff test of angular distances between two or more groups is performed and the results are printed. The null hypothesis is that distances are equal across groups.
The test proceeds by computing the angular distances from a reference angle, in each group. The angular distance between two angles is the circular range and is computed with range.circular
. Then the distances are compared with a usual rank sum test (Kruskal-Wallis, kruskal.test
). When there are only two groups, the Wilcoxon-Mann-Whitney test could be used but wilcox.test
without continuity correction for the p-value is equivalent to kruskal.test
so only kruskal.test
is used here.
The Wallraff test is most frequently used to compare angular dispersion around the mean, between samples. In this case, the reference angle is the mean angle of each sample. This is the default here, when no reference angles are provided.
All angles should be of class circular
and will be coerced as such with the default parameters if they are not. An exception are the reference angles in ref
. For ease of use, those can be only numeric and are then considered to be in the same angular reference as x
.
A list with class "htest"
containing the following components:
statistic |
the chi-squared statistic from |
parameter |
the degrees of freedom for the chi-squared statistic. |
p.value |
the p-value for the test. |
method |
a character string containing the name of the test. |
data.name |
a character string giving the name(s) of the data. |
Jean-Olivier Irisson
Batschelet, E (1981). Circular Statistics in Biology. chap. 6.10, p. 124
Zar, J H (2010). Biostatistical analysis. sec. 27.7-8, p. 643
kruskal.test
for the Kruskal-Wallis rank sum test used on the angular distances.
wilcox.test
for the two samples alternative to the Kruskal-Wallis test.
# Homing of pigeons # Example used in Batschelet (1981) data <- list( control = circular(c(70, 80, 80, 85, 85, 90, 95, 95), units="degrees", template="geographics"), experimental = circular(c(5, 5, 15, 55, 55, 65, 105, 120, 340), units="degrees", template="geographics") ) # compare the angular dispersion between the two groups wallraff.test(data) # compare the homing performance # home azimuth is 40 degrees for both groups wallraff.test(data, ref = circular(c(40, 40), units="degrees", template="geographics") ) # we could have more simply used wallraff.test(data, ref=40) # because ref is automatically repeated and considered # in the same circular reference as the data
# Homing of pigeons # Example used in Batschelet (1981) data <- list( control = circular(c(70, 80, 80, 85, 85, 90, 95, 95), units="degrees", template="geographics"), experimental = circular(c(5, 5, 15, 55, 55, 65, 105, 120, 340), units="degrees", template="geographics") ) # compare the angular dispersion between the two groups wallraff.test(data) # compare the homing performance # home azimuth is 40 degrees for both groups wallraff.test(data, ref = circular(c(40, 40), units="degrees", template="geographics") ) # we could have more simply used wallraff.test(data, ref=40) # because ref is automatically repeated and considered # in the same circular reference as the data
Performs a Watson's goodness of fit test for the von Mises or circular uniform distribution.
watson.test(x, alpha=0, dist=c("uniform", "vonmises")) ## S3 method for class 'watson.test' print(x, digits = 4, ...)
watson.test(x, alpha=0, dist=c("uniform", "vonmises")) ## S3 method for class 'watson.test' print(x, digits = 4, ...)
x |
a vector. The object is coerced to class
|
alpha |
significance level of the test. Valid levels are 0.01, 0.05, 0.1. This argument may be omitted, in which case, a range for the p-value will be returned. |
dist |
distribution to test for. The default is the uniform
distribution. To test for the von Mises distribution, set |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
If dist
= "uniform", Watson's one-sample test for the circular uniform distribution is performed, and the results are printed. If alpha is specified and non-zero, the test statistic is printed along with the critical value and decision. If alpha is omitted, the test statistic is printed and a range for the p-value of the test is given.
If dist
= "vonmises", estimates of the population parameters are used to evaluate the von Mises distribution function at all data points, thereby arriving at a sample of approximately uniformly distributed data, if the original observations have a von Mises distribution. The one-sample Watson test is then applied to the transformed data as above.
a list with the statistic, alpha, the number of observations, the
distribution and 'row' which is used by print.watson.test
to
evaluate the p-value.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 7.2, World Scientific Press, Singapore.
Stephens, M. (1970). Use of the Kolmogorov-Smirnov, Cramer-von Mises and related statistics without extensive tables. Journal of the Royal Statistical Society, B32, 115-122.
range.circular
, kuiper.test
, rao.spacing.test
and rayleigh.test
# Generate data from the uniform distribution on the circle. x <- circular(runif(100, 0, 2*pi)) watson.test(x) # Generate data from a von Mises distribution. x <- rvonmises(n=50, mu=circular(0), kappa=4) watson.test(x, alpha=0.05, dist="vonmises")
# Generate data from the uniform distribution on the circle. x <- circular(runif(100, 0, 2*pi)) watson.test(x) # Generate data from a von Mises distribution. x <- rvonmises(n=50, mu=circular(0), kappa=4) watson.test(x, alpha=0.05, dist="vonmises")
Performs Watson's test for homogeneity on two samples of circular data.
watson.two.test(x, y, alpha=0) ## S3 method for class 'watson.two.test' print(x, digits=4, ...)
watson.two.test(x, y, alpha=0) ## S3 method for class 'watson.two.test' print(x, digits=4, ...)
x |
a vector. The object is coerced to class
|
y |
a vector. The object is coerced to class
|
alpha |
significance level of the test. Valid levels are 0.001, 0.01, 0.05, 0.1. This argument may be omitted, in which case, a range for the p-value will be returned. |
digits |
integer indicating the precision to be used. |
... |
further arguments passed to or from other methods. |
Watson's two-sample test of homogeneity is performed, and the results are printed. If alpha is specified and non-zero, the test statistic is printed along with the critical value and decision. If alpha is omitted, the test statistic is printed and a range for the p-value of the test is given.
Critical values for the test statistic are obtained using the asymptotic distribution of the test statistic. It is recommended to use the obtained critical values and ranges for p-values only for combined sample sizes in excess of 17. Tables are available for smaller sample sizes and can be found in Mardia (1972) for instance.
a list with statistic, alpha and the number of observations of the first and second sample.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 7.5, World Scientific Press, Singapore.
# Perform a two-sample test of homogeneity on two # simulated data sets. data1 <- rvonmises(n=20, mu=circular(0), kappa=3) data2 <- rvonmises(n=20, mu=circular(pi), kappa=2) watson.two.test(data1, data2, alpha=0.05) watson.two.test(data1, data2)
# Perform a two-sample test of homogeneity on two # simulated data sets. data1 <- rvonmises(n=20, mu=circular(0), kappa=3) data2 <- rvonmises(n=20, mu=circular(pi), kappa=2) watson.two.test(data1, data2, alpha=0.05) watson.two.test(data1, data2)
Performs the Watson-Wheeler test for homogeneity on two or more samples of circular data.
watson.wheeler.test(x, ...) ## Default S3 method: watson.wheeler.test(x, group, ...) ## S3 method for class 'list' watson.wheeler.test(x, ...) ## S3 method for class 'formula' watson.wheeler.test(formula, data, ...)
watson.wheeler.test(x, ...) ## Default S3 method: watson.wheeler.test(x, group, ...) ## S3 method for class 'list' watson.wheeler.test(x, ...) ## S3 method for class 'formula' watson.wheeler.test(formula, data, ...)
x |
a vector of angles (coerced to class |
group |
a vector or factor object giving the groups for the corresponding elements of |
formula |
a formula of the form |
data |
an optional data.frame containing the variables in the formula |
... |
further arguments passed to or from other methods. |
The Watson-Wheeler (or Mardia-Watson-Wheeler, or uniform score) test is a non-parametric test to compare two or several samples. The difference between the samples can be in either the mean or the variance.
The p-value is estimated by assuming that the test statistic follows a chi-squared distribution. For this approximation to be valid, all groups must have at least 10 elements.
In the default method, x
is a vector of angles and group
must be a vector or factor object of the same length as x
giving the group for the corresponding elements of x
.
If x
is a list, its elements are taken as the samples to be compared.
In the formula
method, the angles and grouping elements are identified as the left and right hand side of the formula respectively.
All angles should be of class circular
and will be coerced as such if they are not.
A list with class "htest"
containing the following components:
statistic |
W, the statistic of the test, which is approximately distributed as a chi-squared. |
parameter |
the degrees of freedom for the chi-squared approximation of the statistic. |
p.value |
the p-value for the test. |
method |
a character string containing the name of the test. |
data.name |
a character string giving the name(s) of the data. |
Jean-Olivier Irisson
Batschelet, E (1981). Circular Statistics in Biology. chap 6.3, p. 104
Zar, J H (1999). Biostatistical analysis. section 27.5, p. 640
# Example used in Zar (1999) x1 <- circular(c(35, 45, 50, 55, 60, 70, 85, 95, 105, 120), units="degrees", template="geographics") x2 <- circular(c(75, 80, 90, 100, 110, 130, 135, 140, 150, 160, 165), units="degrees", template="geographics") watson.wheeler.test(list(x1,x2))
# Example used in Zar (1999) x1 <- circular(c(35, 45, 50, 55, 60, 70, 85, 95, 105, 120), units="degrees", template="geographics") x2 <- circular(c(75, 80, 90, 100, 110, 130, 135, 140, 150, 160, 165), units="degrees", template="geographics") watson.wheeler.test(list(x1,x2))
Performs the Watson-Williams test for homogeneity of means between several samples of circular data.
watson.williams.test(x, ...) ## Default S3 method: watson.williams.test(x, group, ...) ## S3 method for class 'list' watson.williams.test(x, ...) ## S3 method for class 'formula' watson.williams.test(formula, data, ...)
watson.williams.test(x, ...) ## Default S3 method: watson.williams.test(x, group, ...) ## S3 method for class 'list' watson.williams.test(x, ...) ## S3 method for class 'formula' watson.williams.test(formula, data, ...)
x |
a vector of angles (coerced to class |
group |
a vector or factor object giving the group for the corresponding elements of |
formula |
a formula of the form |
data |
an optional data.frame containing the variables in the formula |
... |
further arguments passed to or from other methods. |
The Watson-Williams test for the homogeneity of means between two or more groups is performed and the results are printed. The null hypothesis is that means are equal across groups.
The assumptions are that: (1) the samples are drawn from populations with a von Mises distribution; (2) the parameter of concentration has the same value in all populations; (3) this parameter is sufficiently large (i.e. > 1). Assumptions 2 and 3 are checked and a warning is issued if they are not met.
In the default method, x
is a vector of angles and group
must be a vector or factor object of the same length as x
giving the group for the corresponding elements of x
.
If x
is a list, its elements are taken as the samples to be compared.
In the formula
method, the angles and grouping elements are identified as the left and right hand side of the formula respectively.
All angles should be of class circular
and will be coerced as such if they are not.
A list with class "htest"
containing the following components:
statistic |
the F statistic of the test. |
parameter |
the degrees of freedom for the F statistic. |
p.value |
the p-value for the test. |
estimate |
a vector of the means of each group. |
method |
a character string containing the name of the test. |
data.name |
a character string giving the name(s) of the data. |
Jean-Olivier Irisson
Batschelet, E (1981). Circular Statistics in Biology. chap. 6.2, p. 99
Mardia, KV and Jupp, PE (2000). Directional statistics. p. 135
# Ant orientation from Duelli and Wehner (1973) # Example used in Batschelet (1981) data <- list( exp = circular(rep(c(-20, -10, 0), c(1,7,2)), units="degrees", template="geographics"), control = circular(rep(c(-10, 0, 10, 20), c(3,3,3,1)), units="degrees", template="geographics") ) watson.williams.test(data)
# Ant orientation from Duelli and Wehner (1973) # Example used in Batschelet (1981) data <- list( exp = circular(rep(c(-20, -10, 0), c(1,7,2)), units="degrees", template="geographics"), control = circular(rep(c(-10, 0, 10, 20), c(3,3,3,1)), units="degrees", template="geographics") ) watson.williams.test(data)
Returns the weighetd mean direction of a vector of circular data.
## S3 method for class 'circular' weighted.mean(x, w, na.rm=FALSE, control.circular=list(), ...)
## S3 method for class 'circular' weighted.mean(x, w, na.rm=FALSE, control.circular=list(), ...)
x |
a vector. The object is coerced to class
|
w |
a numerical vector of weights the same length as |
na.rm |
logical, indicating if |
control.circular |
the attribute of the resulting object. |
... |
further arguments passed to or from other methods. |
Each observation is treated as a unit vector, or point on the unit
circle. The resultant vector of the observations is found, and the
direction of the resultant vector is returned. An NA
is
returned if the weighted resultant length is less than
.Machine
.
If w
is missing then all elements of x
are given the same
weight, otherwise the weights coerced to numeric by as.numeric
and normalized to sum to one.
Missing values in w
are not handled specially and so give a
missing value as the result. However, zero weights are handled
specially and the corresponding x
values are omitted from the
computation.
Returns the weighted mean direction of the data as an object of class circular
with the attribute given by control.circular
or from x
if missed in control.circular
.
Claudio Agostinelli
# Compute the weighted mean direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) w <- runif(50, 0, 1) weighted.mean(x, w)
# Compute the weighted mean direction of a random sample of observations. x <- circular(runif(50, circular(0), pi)) w <- runif(50, 0, 1) weighted.mean(x, w)
In a place named "Col de la Roa" in the Italian Alps there is a meteorological station that records via data-logger several parameters. Measures are made every 15 minutes, in this dataset we report the wind direction recorded every day from January 29, 2001 to March 31, 2001 from 3.00am to 4.00am included. Which means 5 observations every day for a total of 310 measures.
data(wind)
data(wind)
This data frame contains one variables (wind direction) in radians.
http://www.tesaf.unipd.it/SanVito/dati.htm
C. Agostinelli (2007) Robust estimation for circular data, Computational Statistics and Data Analysis, 51(12), 5867-5875, doi = doi:10.1016/j.csda.2006.11.002
data(wind) wind <- circular(wind, template='geographics') par(mfcol=c(1,2)) plot(wind) plot(density(wind, bw=40), main='')
data(wind) wind <- circular(wind, template='geographics') par(mfcol=c(1,2)) plot(wind) plot(density(wind, bw=40), main='')
This function creates a windrose used to visualize the direction and magnitude of wind. The pedals of a windrose indicate the proportion of time wind comes from a given direction. Bands on the windrose indicate the proportions of winds of each magnitude.
windrose(x, y=NULL, breaks=NULL, bins=12, increment = 10, main='Wind Rose', cir.ind = 0.05, fill.col=NULL, plot.mids=TRUE, mids.size=1.2, osize=0.1, axes=TRUE, ticks=TRUE, tcl=0.025, tcl.text=-0.15, cex=1, digits=2, units=NULL, template=NULL, zero=NULL, rotation=NULL, num.ticks=12, xlim=c(-1.2, 1.2), ylim=c(-1.2, 1.2), uin, tol=0.04, right=FALSE, shrink=NULL, label.freq=FALSE, calm=c("0", "NA"), ...)
windrose(x, y=NULL, breaks=NULL, bins=12, increment = 10, main='Wind Rose', cir.ind = 0.05, fill.col=NULL, plot.mids=TRUE, mids.size=1.2, osize=0.1, axes=TRUE, ticks=TRUE, tcl=0.025, tcl.text=-0.15, cex=1, digits=2, units=NULL, template=NULL, zero=NULL, rotation=NULL, num.ticks=12, xlim=c(-1.2, 1.2), ylim=c(-1.2, 1.2), uin, tol=0.04, right=FALSE, shrink=NULL, label.freq=FALSE, calm=c("0", "NA"), ...)
x |
a vector contains direction or a two columns data frame, where the first component is the direction and the second the magnitude. The vector or the first column in the case of data frame is coerced to class |
y |
a vector contains magnitude. If 'y' is not NULL and 'x' is a dataframe, only the first column of 'x' is used for direction. |
breaks |
the extremes of the pedals. The biggest value (in 2*pi) is recycled for building the first pedal. The vector is coerced to class |
bins |
Number of pedals. Ignored if 'breaks' is not NULL. |
increment |
Grouping size of magnitude. These are the bins of the magnitudes displayed on each pedal. |
main |
Title for plot. |
cir.ind |
Percent intervals expressed on each circle if the pedals are equally spaced, otherwise values of density |
fill.col |
colors used to fill the pedals for each magnitude. The colors are recycled if necessary. The default is to use 'blue' and 'red'. |
plot.mids |
plot lines at the midpoints of the pedals. |
mids.size |
length of the lines for midpoints. |
osize |
radius of the circle draws at the center of the plot. |
axes |
if TRUE axes are added to the plot. The function |
ticks |
if TRUE ticks are added to the plot. The function |
tcl |
length of the ticks. |
tcl.text |
The position of the axis labels. |
cex |
point character size. See help on |
digits |
number of digits used to print axis values and other numbers. |
units |
the units used in the plot. |
template |
the template used in the plot. |
zero |
the zero used in the plot. |
rotation |
the rotation used in the plot. |
num.ticks |
number of tick marks draw. |
tol |
proportion of white space at the margins of plot |
uin |
desired values for the units per inch parameter. If of length 1, the desired units per inch on the x axis. |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. Useful for centering the plot. |
right |
logical; if TRUE, the pedals are right-closed (left open) intervals. |
shrink |
maximum length of the pedals, it can be used to plot several graphics with the same scale. |
label.freq |
logical; if TRUE, the relative frequencies are used in the magnitude instead of intensities, when the breaks are equally spaced. |
calm |
"0" or "NA", see details below. |
... |
further parameters ignored for now. |
Following the convention of the National Weather Service, winds
with a direction of 0 are considered calm, while winds with a
direction of 360 degrees (2*pi radians) are assumed to be from the north. Calm winds
are excluded from the wind rose creation. We allow, in direction, to use NA
to indicate calm wind (argument calm
).
This wind rose preserve areas of pedals, that is counts are proportional to the area of the pedals rather than to the length of the pedals. This is also for the slides created for the magnitudes.
x |
directions |
y |
magnitudes |
table |
Matrix output of the counts of wind direction and magnitude. Columns are in the same units as the data, according to step size, and rows are based on the increment size. |
number.obs |
Total number of observations. |
number.calm |
The number of calm observations omitted from the wind rose plot. |
breaks |
extremes of the pedals. |
mids |
midpoints of pedals. |
call |
the |
some codes from eqscplot
in 'MASS' is used.
Matt Pocernich <[email protected]>, ported in the package 'circular' by Claudio Agostinelli
# Random distribution of direction and magnitude in degrees dir <- circular(runif(100, 0, 360), units="degrees") mag <- rgamma(100, 15) sample <- data.frame(dir=dir, mag=mag) par(mfrow=c(2,2)) res <- windrose(sample) ## we join two pedals and keep the same shrink (scale of the plot) breaks <-circular(seq(0, 2 * pi, by = pi/6)) breaks <- breaks[-2] windrose(sample, breaks=breaks, main="The same but with two pedals joined", shrink=res$shrink) ## change the rotation sample <- data.frame(dir=circular(dir, units="degrees", rotation="clock"), mag=mag) windrose(sample, breaks=breaks, main="Change the rotation", shrink=res$shrink) ## use geographics template sample <- data.frame(dir=circular(dir, units="degrees", template="geographics"), mag=mag) windrose(sample, breaks=breaks, main="Use the template 'geographics'", shrink=res$shrink) ## do the same plot but in radians dir <- conversion.circular(dir) windrose(x=dir, y=mag, xlim=c(-1.3, 1.3)) ## magnify some part of the plot windrose(x=dir, y=mag, xlim=c(0, 1.3))
# Random distribution of direction and magnitude in degrees dir <- circular(runif(100, 0, 360), units="degrees") mag <- rgamma(100, 15) sample <- data.frame(dir=dir, mag=mag) par(mfrow=c(2,2)) res <- windrose(sample) ## we join two pedals and keep the same shrink (scale of the plot) breaks <-circular(seq(0, 2 * pi, by = pi/6)) breaks <- breaks[-2] windrose(sample, breaks=breaks, main="The same but with two pedals joined", shrink=res$shrink) ## change the rotation sample <- data.frame(dir=circular(dir, units="degrees", rotation="clock"), mag=mag) windrose(sample, breaks=breaks, main="Change the rotation", shrink=res$shrink) ## use geographics template sample <- data.frame(dir=circular(dir, units="degrees", template="geographics"), mag=mag) windrose(sample, breaks=breaks, main="Use the template 'geographics'", shrink=res$shrink) ## do the same plot but in radians dir <- conversion.circular(dir) windrose(x=dir, y=mag, xlim=c(-1.3, 1.3)) ## magnify some part of the plot windrose(x=dir, y=mag, xlim=c(0, 1.3))
Density, and random generation for the wrapped Cauchy circular distribution.
dwrappedcauchy(x, mu = circular(0), rho = exp(-1)) rwrappedcauchy(n, mu = circular(0), rho = exp(-1), control.circular=list())
dwrappedcauchy(x, mu = circular(0), rho = exp(-1)) rwrappedcauchy(n, mu = circular(0), rho = exp(-1), control.circular=list())
x |
a vector. The object is coerced to class
|
n |
number of observations. |
mu |
mean direction of the distribution as a |
rho |
concentration parameter of the distribution. |
control.circular |
the attribute of the resulting object. |
dwrappedcauchy
gives the density and rwrappedcauchy
generates random deviates.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.7, World Scientific Press, Singapore.
data1 <- rwrappedcauchy(100, mu=circular(0), rho=0.7, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dwrappedcauchy(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=TRUE, xlim=c(-2, 1), main="Density of a Wrapped Cauchy Distribution \n mu=pi, rho=0.7")
data1 <- rwrappedcauchy(100, mu=circular(0), rho=0.7, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dwrappedcauchy(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=TRUE, xlim=c(-2, 1), main="Density of a Wrapped Cauchy Distribution \n mu=pi, rho=0.7")
Density, and random generation for the wrapped normal circular distribution.
rwrappednormal(n, mu = circular(0), rho = NULL, sd = 1, control.circular = list()) dwrappednormal(x, mu = circular(0), rho = NULL, sd = 1, K = NULL, min.k = 10) pwrappednormal(q, mu = circular(0), rho = NULL, sd = 1, from = NULL, K = NULL, min.k = 10, ...) qwrappednormal(p, mu = circular(0), rho = NULL, sd = 1, from = NULL, K = NULL, min.k = 10, tol = .Machine$double.eps^(0.6), control.circular = list(), ...)
rwrappednormal(n, mu = circular(0), rho = NULL, sd = 1, control.circular = list()) dwrappednormal(x, mu = circular(0), rho = NULL, sd = 1, K = NULL, min.k = 10) pwrappednormal(q, mu = circular(0), rho = NULL, sd = 1, from = NULL, K = NULL, min.k = 10, ...) qwrappednormal(p, mu = circular(0), rho = NULL, sd = 1, from = NULL, K = NULL, min.k = 10, tol = .Machine$double.eps^(0.6), control.circular = list(), ...)
x , q
|
vector of quantiles. The object is coerced to class
|
p |
vector of probabilities. |
n |
number of observations. |
mu |
mean direction of the distribution as a |
rho |
concentration parameter of the distribution. |
sd |
standard deviation of the (unwrapped) normal distribution. |
from |
if |
K |
number of terms to be used in approximating the density. |
min.k |
minimum number of terms used in approximating the density. |
tol |
passed to |
control.circular |
the attribute of the resulting object. |
... |
parameters passed to |
dwrappednormal
gives the density and rwrappednormal
generates random deviates, pwrappednormal
gives the
distribution function, and qwrappednormal
provides quantiles.
Claudio Agostinelli and Ulric Lund
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 2.2.7, World Scientific Press, Singapore.
data1 <- rwrappednormal(100, mu=circular(0), rho=0.7, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dwrappednormal(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=TRUE, xlim=c(-1.5, 1), main="Density of a Wrapped Normal Distribution \n mu=pi, rho=0.7") ff <- function(x) pwrappednormal(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 2), to=(2*pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a Wrapped Normal Distribution \n mu=pi, rho=0.7, from=0") ff <- function(x) pwrappednormal(x, mu=circular(pi), rho=0.7, from=circular(pi)) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 2), from=-pi, to=(pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a Wrapped Normal Distribution \n mu=pi, rho=0.7, from=pi") plot(qwrappednormal, from=0, to=1) plot(function(x) qwrappednormal(p=x, mu=circular(pi)), from=0, to=1)
data1 <- rwrappednormal(100, mu=circular(0), rho=0.7, control.circular=list(units="degrees")) plot(data1) ff <- function(x) dwrappednormal(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=TRUE, xlim=c(-1.5, 1), main="Density of a Wrapped Normal Distribution \n mu=pi, rho=0.7") ff <- function(x) pwrappednormal(x, mu=circular(pi), rho=0.7) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 2), to=(2*pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a Wrapped Normal Distribution \n mu=pi, rho=0.7, from=0") ff <- function(x) pwrappednormal(x, mu=circular(pi), rho=0.7, from=circular(pi)) curve.circular(ff, join=FALSE, xlim=c(-2, 2), ylim=c(-2, 2), from=-pi, to=(pi-3*.Machine$double.eps), modulo="asis", nosort=TRUE, main="Probability of a Wrapped Normal Distribution \n mu=pi, rho=0.7, from=pi") plot(qwrappednormal, from=0, to=1) plot(function(x) qwrappednormal(p=x, mu=circular(pi)), from=0, to=1)