Title: | Statistical Analysis of Circular Data using Nonnegative Trigonometric Sums (NNTS) Models |
---|---|
Description: | Includes functions for the analysis of circular data using distributions based on Nonnegative Trigonometric Sums (NNTS). The package includes functions for calculation of densities and distributions, for the estimation of parameters, for plotting and more. |
Authors: | Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez |
Maintainer: | Maria Mercedes Gregorio-Dominguez <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.3 |
Built: | 2024-12-01 08:37:10 UTC |
Source: | CRAN |
A collection of utilities for the statistical analysis of circular and spherical data using nonnegative trigonometric sum (NNTS) models
Package: | CircNNTSR |
Type: | Package |
Version: | 2.2-1 |
Date: | 2020-02-16 |
License: | GLP (>=2) |
LazyLoad: | yes |
Fernandez-Duran, J.J. (2004) proposed a new family of distributions for circular random variables based on nonnegative trigonometric sums. This package provides functions for working with circular distributions based on nonnegative trigonometric sums, including functions for estimating the parameters and plotting the densities.
The distribution function in this package is a circular distribution based on
nonnegative trigonometric sums (Fernandez-Duran, 2004). Fejer (1915)
expressed a univariate nonnegative trigonometric (Fourier) sum (series), for a variable
, as the squared modulus of a sum of complex numbers, i.e.,
where . From this result, the parameters
for
of the trigonometric sum of order
,
,
are expressed in terms of the complex parameters in Equation 1
, , for
, as
. The additional constraint,
, is imposed
to make the trigonometric sum to integrate one. Thus,
must be real and positive, and there are 2*M free parameters. Then, the probability
density function for a circular (angular) random variable is defined
as (Fernandez-Duran, 2004)
Note that Equation 1 can also be expressed as a double sum as
.
The parameters can also be expressed in polar coordinates as
for
and
; where
is the modulus of
and
is the argument of
for
.
Many functions of the packages use as parameters the squared moduli and the arguments of
,
and
, for
. We refer to the parameter
as the number of components in the NNTS.
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Maintainer: Maria Mercedes Gregorio Dominguez <[email protected]>
Fernandez-Duran, J.J. (2004). Circular Distributions Based on Nonnegative Trigonometric Sums, Biometrics, 60(2), 499-503.
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2010). A Likelihood-Ratio Test for Homogeneity in Circular Data. Journal of Biometrics & Biostatistics, 1(3), 107. doi:10.4172/2155-6180.1000107
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2010). Maximum Likelihood Estimation of Nonnegative Trigonometric Sums Models Using a Newton-Like Algorithm on Manifolds. Electronic Journal of Statistics, 4, 1402-1410. doi:10.1214/10-ejs587
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Distributions for Spherical Data Based on Nonnegative Trigonometric Sums. Statistical Papers, 55(4), 983-1000. doi:10.1007/s00362-013-0547-5
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Testing for Seasonality Using Circular Distributions Based on Nonnegative Trigonometric Sums as Alternative Hypotheses. Statistical Methods in Medical Research, 23(3), 279-292. doi:10.1177/0962280211411531.
Juan Jose Fernandez-Duran, Maria Mercedes Gregorio-Dominguez (2016). CircNNTSR: An R Package for the Statistical Analysis of Circular, Multivariate Circular, and Spherical Data Using Nonnegative Trigonometric Sums. Journal of Statistical Software, 70(6), 1-19. doi:10.18637/jss.v070.i06
set.seed(200) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data est<-nntsmanifoldnewtonestimation(Turtles_radians,3,iter=100) est #plot the estimated density nntsplot(est$cestimates[,2],3) #add the histogram to the estimated density plot plot(Turtles_hist, freq=FALSE, add=TRUE) b<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) estS<-nntsestimationSymmetric(2,b) nntsplotSymmetric(estS$coef,2) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplot(cest, M)
set.seed(200) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data est<-nntsmanifoldnewtonestimation(Turtles_radians,3,iter=100) est #plot the estimated density nntsplot(est$cestimates[,2],3) #add the histogram to the estimated density plot plot(Turtles_hist, freq=FALSE, add=TRUE) b<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) estS<-nntsestimationSymmetric(2,b) nntsplotSymmetric(estS$coef,2) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplot(cest, M)
Directions chosen by 100 ants in response to an evenly illuminated black target.
data(Ants)
data(Ants)
Directions chosen by 100 ants in degrees
Randomly selected values by Fisher (1993) from Jander (1957)
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
Direction chosen by 100 ants in response to an evenly illuminated black target.
data(Ants_radians)
data(Ants_radians)
Directions chosen by 100 ants in radians
Randomly selected values by Fisher (1993) from Jander (1957)
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
Database B3 from Fisher et al. (1987)
data(Datab3fisher)
data(Datab3fisher)
Datab3fisher
The dataset Datab3fisher consists of 148 observations of the arrival directions of low-mu showers of cosmic rays (Toyoda et al., 1965; see Fisher et al., 1987, pp. 280-281). The observations are measured in declination and right ascension coordinates.
Fisher, et al. (1987)
Toyoda, Y., Suga, K., Murakami, K., Hasegawa, H.,
Shibata, S., Domingo, V., Escobar, I., Kamata, K., Bradt, H.,
Clark, G. and La Pointe, M. (1965). Studies of Primary Cosmic Rays
in the Energy Region eV to
eV (Bolivian Air
Shower Joint Experiment), Proceedings of the International
Conference on Cosmic Rays, vol. 2,
London, September, 1965, 708–711. London: The Institute of
Physics and the Physical Society.
Fisher, N.I., Lewis, T. and Embleton, B.J.J. (1987). Statistical Analysis of Spherical Data, Cambridge U.K.: Cambridge University Press.
Data transformed from Datab3fisher
data(Datab3fisher_ready)
data(Datab3fisher_ready)
Datab3fisher_ready
datab3fisher[,2] <- 90 + datab3fisher[,2]; datab3fisher_ready <- datab3fisher*(pi/180)
Measurements of magnetic remanence from 52 specimens of red beds from the Bowen Basin, Queensland.
data(DataB5FisherSpherical)
data(DataB5FisherSpherical)
Declination -inclination in degrees
P.W. Schmidt
Fisher N.I., Lewis T. and Embleton B.J.J. (1987) Statistical Analysis of Spherical Data. Cambridge University Press, Cambridge. Data B.5.
data(DataB5FisherSpherical)
data(DataB5FisherSpherical)
datab6fisher
data(Datab6fisher)
data(Datab6fisher)
The coordinates are declination and inclination measured in degrees
The data-set Datab6fisher contains 107 measurements of magnetic remanence in samples of Precambrian volcanics collected in Northwest Australia. (Schmidt and Embleton, 1985; see Fisher et al., 1987, pp. 285).
Fisher, et al. (1987)
Schmidt, P.W. and Embleton, B.J.J. (1985). Pre-folding and overprint magnetic signatures in Precambrian (~2.9-2.7ga) igneous rocks from the Pilbara Craton and Hamersley Basin, N.W. Australia, Journal of Geophysical Research, 90 (B4), 2967–2984.
Fisher, N.I., Lewis, T. and Embleton, B.J.J. (1987). Statistical Analysis of Spherical Data, Cambridge U.K.: Cambridge University Press.
Data transformed from datab6fisher
data(Datab6fisher_ready)
data(Datab6fisher_ready)
Datab6fisher_ready
dataaux <- datab6fisher; datab6fisher[,1] <- dataaux[,2]; datab6fisher[,2] <- dataaux[,1]; datab6fisher[,1] <- 360 - datab6fisher[,1]; datab6fisher[,2] <- 90 + datab6fisher[,2]; datab6fisher_ready <- datab6fisher*(pi/180)
200 realizations of a uniform distribution on the torus
data(DataUniformBivariate200obs)
data(DataUniformBivariate200obs)
Angles in radians
The time of occurrence of earthquakes of intensity greater than Richter with an epicenter occurring in the coast
of the Pacific Ocean in Mexico from 1920 to 2002.
There is a total of 241 observations.
data(EarthquakesPacificMexicogt6)
data(EarthquakesPacificMexicogt6)
Time in years. All observations in the interval (0,1]
Mexican Database of Strong Earthquakes. CENAPRED.
The time of occurrence of earthquakes of intensity greater than Richter with an epicenter occurring in the coast
of the Pacific Ocean in Mexico from 1920 to 2002.
There are a total of 76 observations.
data(EarthquakesPacificMexicogt7)
data(EarthquakesPacificMexicogt7)
Time in years. All observations in the interval (0,1]
Mexican Database of Strong Earthquakes. CENAPRED.
Monthly number of homicides in Mexico during 2005
data(HomicidesMexico2005)
data(HomicidesMexico2005)
Integer values
INEGI (Mexican National Statistical Agency) www.inegi.gob.mx
The time of occurrence (starting times) of hurricanes in the Gulf of Mexico for the 1951-1970 period. There are a total of 196 observations.
data(HurricanesGulfofMexico1951to1970)
data(HurricanesGulfofMexico1951to1970)
Time in years. All observations in the interval (0,1]
http://weather.unisys.com/hurricane/atlantic/1978/index.html
The time of occurrence (starting times) of hurricanes in the Gulf of Mexico for the 1971-2008 period. There are a total of 417 observations
data(HurricanesGulfofMexico1971to2008)
data(HurricanesGulfofMexico1971to2008)
Time in years. All observations in the interval (0,1]
http://weather.unisys.com/hurricane/atlantic/1978/index.html
Density function for the MNNTS model
mnntsdensity(data, cpars = 1/sqrt(2 * pi), M = 0, R=1)
mnntsdensity(data, cpars = 1/sqrt(2 * pi), M = 0, R=1)
data |
Matrix of angles in radians, a column for each dimension, a row for each data point |
cpars |
Parameters of the model. A vector of complex numbers of dimension prod(M+1). The first
element is a real and positive number. The first M[1]+1 elements correspond to dimension one, the next M[2]+1
elements correspond to dimension two, and so on. The sum of the SQUARED moduli of the c parameters must be
equal to |
M |
Vector of length R with number of components in the MNNTS for each dimension |
R |
Number of dimensions |
The function returns the density function evaluated at each row in data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Juan Jose Fernandez-Duran, Maria Mercedes Gregorio-Dominguez (2016). CircNNTSR: An R Package for the Statistical Analysis of Circular, Multivariate Circular, and Spherical Data Using Nonnegative Trigonometric Sums. Journal of Statistical Software, 70(6), 1-19. doi:10.18637/jss.v070.i06
set.seed(200) M<-c(2,3) R<-length(M) data<-c(0,pi,pi/2,pi,pi,3*pi/2,pi,2*pi,2*pi,pi) data<-matrix(data,ncol=2,byrow=TRUE) data ccoef<-mnntsrandominitial(M,R) mnntsdensity(data,ccoef,M,R) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est ccoef<-est$cestimates[,3] mnntsdensity(data,ccoef,M,R)
set.seed(200) M<-c(2,3) R<-length(M) data<-c(0,pi,pi/2,pi,pi,3*pi/2,pi,2*pi,2*pi,pi) data<-matrix(data,ncol=2,byrow=TRUE) data ccoef<-mnntsrandominitial(M,R) mnntsdensity(data,ccoef,M,R) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est ccoef<-est$cestimates[,3] mnntsdensity(data,ccoef,M,R)
Computes the log-likelihood function with MNNTS density for data
mnntsloglik(data, cpars = 1/sqrt(2 * pi), M = 0, R = 1)
mnntsloglik(data, cpars = 1/sqrt(2 * pi), M = 0, R = 1)
data |
Matrix of angles in radians, a column for each dimension, a row for each data point. |
cpars |
Parameters of the model. A vector of complex numbers of dimension prod(M+1). The first element is a real and positive number.
The first M[1]+1 elements correspond to dimension one, next M[2]+1 elements correspond to dimension two, and so on.
The sum of the SQUARED moduli of the c parameters must be equal to |
M |
Vector of length R with number of components in the MNNTS for each dimension. |
R |
Number of dimensions. |
The function returns the value of the log-likelihood function for the data.
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
M<-c(2,3) R<-length(M) data<-c(0,pi,pi/2,pi,pi,3*pi/2,pi,2*pi,2*pi,pi) data<-matrix(data,ncol=2,byrow=TRUE) data ccoef<-mnntsrandominitial(M,R) mnntsdensity(data,ccoef,M,R) mnntsloglik(data,ccoef,M,R)
M<-c(2,3) R<-length(M) data<-c(0,pi,pi/2,pi,pi,3*pi/2,pi,2*pi,2*pi,pi) data<-matrix(data,ncol=2,byrow=TRUE) data ccoef<-mnntsrandominitial(M,R) mnntsdensity(data,ccoef,M,R) mnntsloglik(data,ccoef,M,R)
Computes the maximum likelihood estimates of the MNNTS parameters using a Newton algorithm on the hypersphere
mnntsmanifoldnewtonestimation(data,M=0,R=1,iter=1000,initialpoint=FALSE,cinitial)
mnntsmanifoldnewtonestimation(data,M=0,R=1,iter=1000,initialpoint=FALSE,cinitial)
data |
Matrix of angles in radians, a column for each dimension, a row for each data point |
M |
Vector of length R with number of components in the MNNTS for each dimension |
R |
Number of dimensions |
iter |
Number of iterations for the Newton algorithm |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Initial value for cpars (parameters of the model) for the optimization algorithm.
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number.
The first M[1]+1 elements correspond to dimension one, the next M[2]+1 elements correspond to dimension two, and so on.
The sum of the SQUARED moduli of the c parameters must be equal to |
cestimates |
Matrix of prod(M+1)*(R+1). The first R columns are the parameter number, and the last column is the c parameter's estimators |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after the last iteration |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest*(pi/180) est<-mnntsmanifoldnewtonestimation(data,M,R,100) est
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest*(pi/180) est<-mnntsmanifoldnewtonestimation(data,M,R,100) est
Marginal density function for one dimension of the MNNTS model evaluated at a point
mnntsmarginal(cestimatesarray, M, component, theta)
mnntsmarginal(cestimatesarray, M, component, theta)
cestimatesarray |
Matrix of prod(M+1)*(R+1). The first R columns are the parameter number, and the last column is the c parameter's estimators |
M |
Vector of length R with number of components in the MNNTS for each dimension |
component |
Number of the dimension for computing the marginal |
theta |
An angle in radians (or a vector of angles) |
The function returns the density function evaluated at theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsmarginal(cest,M,1,pi)
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsmarginal(cest,M,1,pi)
Plots the MNNTS bivariate density function
mnntsplot(cestimates, M, ...)
mnntsplot(cestimates, M, ...)
cestimates |
Matrix of prod(M+1)*(R+1). The first R columns are the parameter number, and the last column is the c parameter's estimators. R=2 for a bivariate distribution |
M |
Vector with the number of components in the MNNTS for each dimension |
... |
Arguments passed to the function plot |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplot(cest, M)
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplot(cest, M)
Plots the MNNTS marginal density function
mnntsplotmarginal(cestimates, M, component, ...)
mnntsplotmarginal(cestimates, M, component, ...)
cestimates |
Matrix of prod(M+1)*(R+1). The first R columns are the parameter number, and the last column the c parameter's estimators. The matrix could be the output of mnntsmanifoldnewtonestimation $cestimates |
M |
Vector with number of components in the MNNTS for each dimension |
component |
Number of the dimension for computing the marginal density |
... |
Arguments passed to the function plot |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplotmarginal(cest, M, 1) mnntsplotmarginal(cest, M, 2)
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplotmarginal(cest, M, 1) mnntsplotmarginal(cest, M, 2)
Plots the MNNTS bivariate density function together with the marginals
mnntsplotwithmarginals(cestimates, M, ...)
mnntsplotwithmarginals(cestimates, M, ...)
cestimates |
Matrix of prod(M+1)*(R+1). The first R columns are the parameter number, and the last column the c parameter's estimators. The matrix could be the output of mnntsmanifoldnewtonestimation $cestimates. |
M |
Vector of length R with number of components in the MNNTS for each dimension |
... |
Arguments passed to the function plot |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2014). Modeling Angles in Proteins and Circular Genomes Using Multivariate Angular Distributions Based on Nonnegative Trigonometric Sums. Statistical Applications in Genetics and Molecular Biology, 13(1), 1-18. doi:10.1515/sagmb-2012-0012
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplotwithmarginals(cest, M)
set.seed(200) M<-c(2,3) R<-length(M) data(Nest) data<-Nest est<-mnntsmanifoldnewtonestimation(data,M,R,100) est cest<-est$cestimates mnntsplotwithmarginals(cest, M)
This function generates a random point on the surface of the prod(M+1)-dimensional unit hypersphere
mnntsrandominitial(M = 1, R = 1)
mnntsrandominitial(M = 1, R = 1)
M |
Vector of length R with number of components in the MNNTS for each dimension |
R |
Number of dimensions |
Returns a valid initial point for estimation functions
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
M<-c(2,3) R<-length(M) mnntsrandominitial(M,R)
M<-c(2,3) R<-length(M) mnntsrandominitial(M,R)
Simulation for the density function for the MNNTS model
mnntssimulation(nsim=1, cpars = 1/(2 * pi), M = c(0,0), R=2)
mnntssimulation(nsim=1, cpars = 1/(2 * pi), M = c(0,0), R=2)
nsim |
Number of simulations |
cpars |
Parameters of the model. A vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The first M[1]+1 elements correspond to dimension one, next M[2]+1 elements correspond to dimension two, and so on. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Vector of length R with number of components in the MNNTS for each dimension |
R |
Number of dimensions |
simulations |
The function generates nsim random values from the MNNTS density function |
conteo |
Number of uniform random numbers used for simulations |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. and Gregorio-Dominguez, M.M. (2009) Multivariate Angular Distributions Based on Multiple Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C09.1
M<-c(2,3) R<-length(M) ccoef<-mnntsrandominitial(M,R) data<-mnntssimulation(10,ccoef,M,R) data
M<-c(2,3) R<-length(M) ccoef<-mnntsrandominitial(M,R) data<-mnntssimulation(10,ccoef,M,R) data
Orientation of nests of 50 noisy scrub birds (theta) along the bank of a creek bed, together with the corresponding directions (phi) of creek flow at the nearest point to the nest.
data(Nest)
data(Nest)
Orientation of 50 nests (vectors)
Data supplied by Dr. Graham Smith
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
This function transforms the complex parameters c to the parameters ab for a reparameterization of the density function
nntsABcoefficients(cpars = 1/sqrt(2 * pi), M = 0)
nntsABcoefficients(cpars = 1/sqrt(2 * pi), M = 0)
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the parameters ab associated with the parameters cpars and returns a vector of real numbers of size 2*M, where the first M elements are the a_k, k=1,...,M, and the next M elements are the b_k, k=1,...,M
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
#random generation of c parameters ccoef<-nntsrandominitial(3) ccoef ab<-nntsABcoefficients(ccoef,3) ab
#random generation of c parameters ccoef<-nntsrandominitial(3) ccoef ab<-nntsABcoefficients(ccoef,3) ab
This function transforms the complex parameters c to the parameters ab for a reparameterization of the density function
nntsABcoefficientsSymmetric(cpars = c(0,0), M = 0)
nntsABcoefficientsSymmetric(cpars = c(0,0), M = 0)
cpars |
Vector of complex numbers of dimension 2*M |
M |
Number of components in the NNTS |
The function returns the parameters ab associated with the pararameters cpars
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Density function expressed in terms of the ab parameters at theta
nntsABDensity(theta, cpars = 1/sqrt(2 * pi), M = 0)
nntsABDensity(theta, cpars = 1/sqrt(2 * pi), M = 0)
theta |
Vector of angles in radians |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi) |
M |
Number of components in the NNTS |
Returns the density function in terms of the ab coefficients evaluated at theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
ccoef<-nntsrandominitial(3) nntsABDensity(1,ccoef,3) nntsABDensity(1+2*pi,ccoef,3)
ccoef<-nntsrandominitial(3) nntsABDensity(1,ccoef,3) nntsABDensity(1+2*pi,ccoef,3)
Density function expressed in terms of the ab parameters at theta
nntsABDensitySymmetric(cpars = c(0, 0), M = 0, theta)
nntsABDensitySymmetric(cpars = c(0, 0), M = 0, theta)
theta |
Vector of angles in radians |
cpars |
Vector of complex numbers of dimension 2*M |
M |
Number of components in the NNTS |
Returns the density function in terms of the ab coefficients evaluated at theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Density function for the NNTS model
nntsdensity(data, cpars = 1/sqrt(2 * pi), M = 0)
nntsdensity(data, cpars = 1/sqrt(2 * pi), M = 0)
data |
Vector of angles in radians |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the density function evaluated at each point in data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. (2004). Circular Distributions Based on Nonnegative Trigonometric Sums, Biometrics, 60(2), 499-503.
Juan Jose Fernandez-Duran, Maria Mercedes Gregorio-Dominguez (2016). CircNNTSR: An R Package for the Statistical Analysis of Circular, Multivariate Circular, and Spherical Data Using Nonnegative Trigonometric Sums. Journal of Statistical Software, 70(6), 1-19. doi:10.18637/jss.v070.i06
ccoef<-nntsrandominitial(3) nntsdensity(1,ccoef,3) nntsdensity(1+pi,ccoef,3) nntsdensity(c(1,1+pi),ccoef,3)
ccoef<-nntsrandominitial(3) nntsdensity(1,ccoef,3) nntsdensity(1+pi,ccoef,3) nntsdensity(c(1,1+pi),ccoef,3)
Computes the density function at theta for a variable defined in the interval [0,1))
nntsDensityInterval0to1(S, cpars = 1/sqrt(2 * pi), M = 0)
nntsDensityInterval0to1(S, cpars = 1/sqrt(2 * pi), M = 0)
S |
Vector of values defined in the interval [0,1) at which the density function is computed |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to 1/(2*pi) |
M |
Number of components in the NNTS |
This function computes the density function of a variable S (S in the interval [0,1)). If theta is defined in radians (theta in the interval [0,2*pi)), the relation between S and theta is theta=2*pi*S.
Value of the density function at each component of S
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
ccoef<-nntsrandominitial(3) nntsDensityInterval0to1(c(.8,1.8),ccoef,3)
ccoef<-nntsrandominitial(3) nntsDensityInterval0to1(c(.8,1.8),ccoef,3)
Cumulative distribution function in terms of the c parameters at theta, measured in radians [0,2*pi).
nntsDistribution(theta, cpars = 1/sqrt(2 * pi), M = 0)
nntsDistribution(theta, cpars = 1/sqrt(2 * pi), M = 0)
theta |
Vector of angles in radians at which the distribution is computed |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the value of the distribution function evaluated at each component of theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
ccoef<-nntsrandominitial(3) nntsDistribution(c(0,pi/2,pi,2*pi-0.00000001,2*pi),ccoef,3)
ccoef<-nntsrandominitial(3) nntsDistribution(c(0,pi/2,pi,2*pi-0.00000001,2*pi),ccoef,3)
Computes the distribution function at theta for the incidence data (number of observed values in certain intervals defined in the interval [0,1))
nntsDistributioninterval0to1(theta, cpars = 1/sqrt(2 * pi), M = 0)
nntsDistributioninterval0to1(theta, cpars = 1/sqrt(2 * pi), M = 0)
theta |
Value at which the distribution function is computed |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the value of the distribution function at theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
cpars<-nntsrandominitial(2) nntsDistributioninterval0to1(pi, cpars, 2)
cpars<-nntsrandominitial(2) nntsDistributioninterval0to1(pi, cpars, 2)
Computes the distribution function for the data at theta
nntsDistributioninterval0to2pi(theta, cpars = 1/sqrt(2 * pi), M = 0)
nntsDistributioninterval0to2pi(theta, cpars = 1/sqrt(2 * pi), M = 0)
theta |
Value at which the distribution function is computed |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the value of the distribution function at theta
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
cpars<-nntsrandominitial(3) nntsDistributioninterval0to2pi(0, cpars, 3) nntsDistributioninterval0to2pi(pi, cpars, 3) nntsDistributioninterval0to2pi(2*pi-0.00000001, cpars, 3) nntsDistributioninterval0to2pi(2*pi, cpars, 3) nntsDistributioninterval0to2pi(3*pi, cpars, 3)
cpars<-nntsrandominitial(3) nntsDistributioninterval0to2pi(0, cpars, 3) nntsDistributioninterval0to2pi(pi, cpars, 3) nntsDistributioninterval0to2pi(2*pi-0.00000001, cpars, 3) nntsDistributioninterval0to2pi(2*pi, cpars, 3) nntsDistributioninterval0to2pi(3*pi, cpars, 3)
Computes the maximum likelihood estimates of the symmetric NNTS parameters
nntsestimationSymmetric(M = 0, data, maxit = 500)
nntsestimationSymmetric(M = 0, data, maxit = 500)
M |
Number of components in the NNTS |
data |
Vector of angles in radians |
maxit |
Maximum number of iterations in the optimization algorithm |
coef |
Vector of length M+1. The first M components are the squared moduli of the c parameters, and the last number is the mean of symmetry |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
convergence |
An integer code: zero indicates successful convergence; error codes are the following: one indicates that the iteration limit maxit has been reached, and 10 indicates degeneracy of the Nelder-Mead simplex |
For the maximization of the loglikelihood function the function constrOptim from the package stats is used
Juan Jose Fernandez-Duran y Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2009) Symmetric Circular Distributions Based on Nonnegative Trigonometric Sums. Working Paper, DE-C09.12, Department of Statistics, ITAM, Mexico
b<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) estS<-nntsestimationSymmetric(2,b) nntsplotSymmetric(estS$coef,2)
b<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) estS<-nntsestimationSymmetric(2,b) nntsplotSymmetric(estS$coef,2)
Computes the log-likelihood function with NNTS density for data
nntsloglik(data, cpars = 1/sqrt(2 * pi), M = 0)
nntsloglik(data, cpars = 1/sqrt(2 * pi), M = 0)
data |
Vector with observed angles in radians. |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the value of the log-likelihood function for the data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J. (2004). Circular Distributions Based on Nonnegative Trigonometric Sums, Biometrics, 60(2), 499-503.
a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) est<-nntsmanifoldnewtonestimation(a,2) ccoef<-est$cestimates[,2] nntsloglik(a,ccoef,2)
a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) est<-nntsmanifoldnewtonestimation(a,2) ccoef<-est$cestimates[,2] nntsloglik(a,ccoef,2)
Computes the log-likelihood function for incidence data (number of observed values in certain intervals defined in the interval [0,1))
nntsloglikInterval0to1(data, cutpoints, cpars = 1/sqrt(2 * pi), M = 0)
nntsloglikInterval0to1(data, cutpoints, cpars = 1/sqrt(2 * pi), M = 0)
data |
Number of observations in each interval |
cutpoints |
Vector of size length(data)+1 with the limits of the intervals |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
The function returns the value of the log-likelihood function for data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
data<-c(1,2,6,4,1) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.9999999) cpars<-nntsrandominitial(1) nntsloglikInterval0to1(data, cutpoints, cpars, 1)
data<-c(1,2,6,4,1) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.9999999) cpars<-nntsrandominitial(1) nntsloglikInterval0to1(data, cutpoints, cpars, 1)
Computes the log-likelihood function for incidence data (number of observed values in certain intervals defined in the interval [0,2*pi))
nntsloglikInterval0to2pi(data, cutpoints, cpars = 1/sqrt(2 * pi), M = 0)
nntsloglikInterval0to2pi(data, cutpoints, cpars = 1/sqrt(2 * pi), M = 0)
data |
Number of observations in each interval |
cutpoints |
Vector of size length(data)+1 with the limits of the exhaustive and mutually exclusive intervals in which the interval [0,2*pi) is divided. |
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS density |
The function returns the value of the log-likelihood function for the data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
data<-c(2,3,6,4) cutpoints<-c(0,pi/2,pi,3*pi/2,2*pi-0.00000001) est<-nntsmanifoldnewtonestimationinterval0to2pi(data,cutpoints,M=1) cpars<-est$cestimates[,2] nntsloglikInterval0to2pi(data,cutpoints,cpars,M=1)
data<-c(2,3,6,4) cutpoints<-c(0,pi/2,pi,3*pi/2,2*pi-0.00000001) est<-nntsmanifoldnewtonestimationinterval0to2pi(data,cutpoints,M=1) cpars<-est$cestimates[,2] nntsloglikInterval0to2pi(data,cutpoints,cpars,M=1)
Computes the log-likelihood function with NNTS symmetric density for the data
nntsloglikSymmetric(cpars = c(0, 0), M = 0, data)
nntsloglikSymmetric(cpars = c(0, 0), M = 0, data)
cpars |
Vector of real numbers of dimension M+1. The first M numbers are the squared moduli of the c parameters. The sum must be less than 1/(2*pi). The last number is the mean of symmetry |
M |
Number of components in the NNTS |
data |
Vector with angles in radians. The first column is used if data are a matrix |
The function returns the value of the log-likelihood function for the data
The default values provide the Uniform circular log-likelihood for the data
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2009) Symmetric Circular Distributions Based on Nonnegative Trigonometric Sums. Working Paper, DE-C09.12, Department of Statistics, ITAM, Mexico
nntsloglikSymmetric(c(.01,.02,2),2,t(c(pi,pi/2,2*pi,pi)))
nntsloglikSymmetric(c(.01,.02,2),2,t(c(pi,pi/2,2*pi,pi)))
Computes the maximum likelihood estimates of the NNTS parameters, using a Newton algorithm on the hypersphere
nntsmanifoldnewtonestimation(data, M=0, iter=1000, initialpoint = FALSE, cinitial)
nntsmanifoldnewtonestimation(data, M=0, iter=1000, initialpoint = FALSE, cinitial)
data |
Vector of angles in radians |
M |
Number of components in the NNTS |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Vector of size M+1. The first element is real and the next M elements are complex (values for $c_0$ and $c_1, ...,c_M$). The sum of the squared moduli of the parameters must be equal to 1/(2*pi) |
cestimates |
Matrix of (M+1)x2. The first column is the parameter numbers, and the second column is the c parameter's estimators |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after the last iteration |
Juan Jose Fernandez-Duran y Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2010). Maximum Likelihood Estimation of Nonnegative Trigonometric Sums Models by Using a Newton-like Algorithm on Manifolds, Working Paper, Department of Statistics, ITAM, DE-C10.8
set.seed(200) a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) #Estimation of the NNTSdensity with 2 components for data and 200 iterations nntsmanifoldnewtonestimation(a,2,iter=200) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data nntsmanifoldnewtonestimation(Turtles_radians,3,iter=200)
set.seed(200) a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) #Estimation of the NNTSdensity with 2 components for data and 200 iterations nntsmanifoldnewtonestimation(a,2,iter=200) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data nntsmanifoldnewtonestimation(Turtles_radians,3,iter=200)
Computes the maximum likelihood estimates of the NNTS parameters, using a Newton algorithm on the hypersphere with the option to specify a minimum value of the norm of the gradient error to stop the algorithm
nntsmanifoldnewtonestimationgradientstop(data, M = 0, iter = 1000, initialpoint = FALSE, cinitial,gradientstop=1e-10)
nntsmanifoldnewtonestimationgradientstop(data, M = 0, iter = 1000, initialpoint = FALSE, cinitial,gradientstop=1e-10)
data |
Vector of angles in radians |
M |
Number of components in the NNTS |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Vector of size M+1. The first element is real and the next M elements are complex (values for |
gradientstop |
The value of the norm of the gradient error of the Newton algorithm at which the algorithms stops |
cestimates |
Matrix of (M+1)x2. The first column is the parameter numbers, and the second column is the c parameter???s estimators |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike???s Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after the last iteration |
Juan Jose Fernandez-Duran y Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2010). Maximum Likelihood Estimation of Nonnegative Trigonometric Sums Models by Using a Newton-like Algorithm on Manifolds, Working Paper, Department of Statistics, ITAM, DE-C10.8
set.seed(200) a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) #Estimation of the NNTSdensity with 2 components for data and gradientstop at 1e-12 nntsmanifoldnewtonestimationgradientstop(a,2,gradientstop=1e-12) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data and gradientstop at 1e-12 nntsmanifoldnewtonestimationgradientstop(Turtles_radians,3,gradientstop=1e-12)
set.seed(200) a<-c(runif(10,3*pi/2,2*pi-0.00000001),runif(10,pi/2,pi-0.00000001)) #Estimation of the NNTSdensity with 2 components for data and gradientstop at 1e-12 nntsmanifoldnewtonestimationgradientstop(a,2,gradientstop=1e-12) data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data and gradientstop at 1e-12 nntsmanifoldnewtonestimationgradientstop(Turtles_radians,3,gradientstop=1e-12)
Parameter estimation for incidence data (number of observed values in certain intervals defined over [0,1))
nntsmanifoldnewtonestimationinterval0to1(data, cutpoints, subintervals, M = 0, iter=1000, initialpoint = FALSE, cinitial)
nntsmanifoldnewtonestimationinterval0to1(data, cutpoints, subintervals, M = 0, iter=1000, initialpoint = FALSE, cinitial)
data |
Frequency of data on each interval |
cutpoints |
Vector with the limits of intervals. The length of cutpoints must be one plus the length of the data |
subintervals |
Number of intervals |
M |
Number of components in the NNTS |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Vector of size M+1. The first element is real and the next M elements are complex (values for $c_0$ and $c_1, ...,c_M$).The sum of the squared moduli of the parameters must be equal to 1/(2*pi) |
cestimates |
Matrix of M+1 * 2. The first column is the parameter numbers and the second column is the c parameter's estimators |
loglik |
Optimum loglikelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after the last iteration |
Juan Jose Fernandez-Duran y Maria Mercedes Gregorio-Dominguez
data<-c(1,2,4,6,1) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.999999999) nntsmanifoldnewtonestimationinterval0to1(data, cutpoints, length(data), 1)
data<-c(1,2,4,6,1) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.999999999) nntsmanifoldnewtonestimationinterval0to1(data, cutpoints, length(data), 1)
Parameter estimation for incidence data (number of observed values in certain intervals defined over [0,2*pi))
nntsmanifoldnewtonestimationinterval0to2pi(data, cutpoints, subintervals,M = 0, iter=1000, initialpoint = FALSE, cinitial)
nntsmanifoldnewtonestimationinterval0to2pi(data, cutpoints, subintervals,M = 0, iter=1000, initialpoint = FALSE, cinitial)
data |
Frequency of data on each interval |
cutpoints |
Vector with the limits of intervals. The length of cutpoints has to be one plus the length of the data |
subintervals |
Number of intervals |
M |
Number of components in the NNTS |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
A vector of size M+1. The first element is real, and the next M elements are complex (values for $c_0$ and $c_1, ...,c_M$).The sum of the squared moduli of the parameters must be equal to 1/(2*pi) |
cestimates |
Matrix of M+1 * 2. The first column is the parameter numbers, and the second column is the c parameter's estimators |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after last iteration |
Juan Jose Fernandez-Duran y Maria Mercedes Gregorio-Dominguez
data<-c(1,2,6,4) cutpoints<-c(0,pi/2,pi,3*pi/2,2*pi-0.00000001) nntsmanifoldnewtonestimationinterval0to2pi(data, cutpoints, length(data),1)
data<-c(1,2,6,4) cutpoints<-c(0,pi/2,pi,3*pi/2,2*pi-0.00000001) nntsmanifoldnewtonestimationinterval0to2pi(data, cutpoints, length(data),1)
Plots the NNTS density
nntsplot(cpars = 1/sqrt(2 * pi), M = 0, ...)
nntsplot(cpars = 1/sqrt(2 * pi), M = 0, ...)
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
... |
Arguments passed to the function curve |
data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data est<-nntsmanifoldnewtonestimation(Turtles_radians,3,iter=200) est #plot the histogram plot(Turtles_hist, freq=FALSE) #add the estimated density to the histogram nntsplot(est$cestimates[,2],3,add= TRUE)
data(Turtles_radians) #Empirical analysis of data Turtles_hist<-hist(Turtles_radians,breaks=10,freq=FALSE) #Estimation of the NNTS density with 3 componentes for data est<-nntsmanifoldnewtonestimation(Turtles_radians,3,iter=200) est #plot the histogram plot(Turtles_hist, freq=FALSE) #add the estimated density to the histogram nntsplot(est$cestimates[,2],3,add= TRUE)
Plots the NNTS density for a variable defined in the interval [0,1)
nntsplotInterval0to1(cpars = 1/sqrt(2 * pi), M = 0, ...)
nntsplotInterval0to1(cpars = 1/sqrt(2 * pi), M = 0, ...)
cpars |
Vector of complex numbers of dimension M+1. The first element is a real and positive number. The sum of the SQUARED moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS |
... |
Arguments passed to the function curve |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
data<-c(1,2,4,6,2) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.9999999) est<-nntsmanifoldnewtonestimationinterval0to1(data,cutpoints,5,1) cpars<-est$cestimates[,2] nntsplotInterval0to1(cpars, 1)
data<-c(1,2,4,6,2) cutpoints<-c(0,0.2,0.4,0.6,0.8,0.9999999) est<-nntsmanifoldnewtonestimationinterval0to1(data,cutpoints,5,1) cpars<-est$cestimates[,2] nntsplotInterval0to1(cpars, 1)
Plots the Symmetric NNTS density function
nntsplotSymmetric(cpars = c(0, 0), M = 0, ...)
nntsplotSymmetric(cpars = c(0, 0), M = 0, ...)
cpars |
Vector of real numbers of dimension 2M. The first 2M-1 numbers are the squared moduli of the c parameters. The sum must be less than 1/(2*pi). The last number is the mean of symmetry |
M |
Number of components in the NNTS |
... |
Arguments passed to the function curve |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2009) Symmetric Circular Distributions Based on Nonnegative Trigonometric Sums. Working Paper, DE-C09.12, Department of Statistics, ITAM, Mexico
This function generates a random point on the surface of the (M+1)-dimensional unit hypersphere
nntsrandominitial(M=1)
nntsrandominitial(M=1)
M |
Number of components in the NNTS |
Returns a valid initial point for the estimation functions
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
nntsrandominitial(3) nntsrandominitial(7)
nntsrandominitial(3) nntsrandominitial(7)
This function generates a random point on the surface of the (M+1)-dimensional unit hypersphere
nntsrandominitialSymmetric(M)
nntsrandominitialSymmetric(M)
M |
Number of components in the NNTS |
Returns a valid initial point for the estimation functions nntsestimation and nntsestimationSymmetric
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Simulation for the density function for the NNTS model
nntssimulation(nsim=1, cpars = 1/(2 * pi), M = 0)
nntssimulation(nsim=1, cpars = 1/(2 * pi), M = 0)
nsim |
Number of simulations |
cpars |
Parameters of the model. A vector of complex numbers of dimension M+1. The sum of the squared moduli of the c parameters must be equal to 1/(2*pi). |
M |
Number of components in the NNTS model |
simulations |
The function generates nsim random values from the MNNTS density function |
conteo |
Number of uniform random numbers used for simulations |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
M<-3 ccoef<-nntsrandominitial(M) data<-nntssimulation(10,ccoef,M) data
M<-3 ccoef<-nntsrandominitial(M) data<-nntssimulation(10,ccoef,M) data
Density function for the Symmetric NNTS
nntsSymmetricDensity(cpars = c(0, 0), M = 0, theta)
nntsSymmetricDensity(cpars = c(0, 0), M = 0, theta)
cpars |
Vector of real numbers of dimension 2*M. The first M numbers are the squared moduli of the c parameters. The sum must be less than 1/(2*pi). The last number is the mean of symmetry |
M |
Number of components in the NNTS |
theta |
Angle in radians |
The function returns the density function evaluated at theta
The default values provide the uniform circular density
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran, J.J., Gregorio-Dominguez, M.M. (2009) Symmetric Circular Distributions Based on Nonnegative Trigonometric Sums. Working Paper, DE-C09.12, Department of Statistics, ITAM, Mexico
Computes the statistic and critical values at 10%, 5% and 1% of the circular uniformity test based on the NNTS likelihood ratio for M values from 1 to 7 and any sample size.
nntsuniformitytestlikelihoodratio(data,M=1, iter=1000, initialpoint = FALSE, cinitial,gradientstop=1e-10)
nntsuniformitytestlikelihoodratio(data,M=1, iter=1000, initialpoint = FALSE, cinitial,gradientstop=1e-10)
data |
Vector of angles in radians |
M |
Number of components in the NNTS |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Vector of size M+1. The first element is real and the next M elements are complex (values for |
.
gradientstop |
The value of the gradient of the Newton algorithm at which the algorithms stops |
gradient |
Gradient error after the last iteration |
likratiounifstat |
Value of the likelihood ratio NNTS circular uniformity test statistic |
criticalvalue10percent |
Critical value at a 10% significance level of the likelihood ratio NNTS circular uniformity test |
criticalvalue05percent |
Critical value at a 5% significance level of the likelihood ratio NNTS circular uniformity test |
criticalvalue01percent |
Critical value at a 1% significance level of the likelihood ratio NNTS circular uniformity test |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran and J. J. and Gregorio-Dominguez and M. M (2022). Sums of Independent Circular Random Variables and Maximum Likelihood Circular Uniformity Tests Based on Nonnegative Trigonometric Sums Distributions, arXiv preprint arXiv:2212.01416
set.seed(200) a<-2*pi*runif(50) #NNTS likelihood ratio circular uniformity test for M=2 and gradientstop at 1e-09 nntsuniformitytestlikelihoodratio(data=a,M=2,gradientstop=1e-09) data(Turtles_radians) #NNTS likelihood ratio circular uniformity test for M=5 and gradientstop at 1e-12 nntsuniformitytestlikelihoodratio(data=Turtles_radians,M=5,gradientstop=1e-09)
set.seed(200) a<-2*pi*runif(50) #NNTS likelihood ratio circular uniformity test for M=2 and gradientstop at 1e-09 nntsuniformitytestlikelihoodratio(data=a,M=2,gradientstop=1e-09) data(Turtles_radians) #NNTS likelihood ratio circular uniformity test for M=5 and gradientstop at 1e-12 nntsuniformitytestlikelihoodratio(data=Turtles_radians,M=5,gradientstop=1e-09)
Dataset of the dihedral angles in a protein between three consecutive Alanine (Ala) amino acids. This dataset was constructed from the recommended July 2003 list of proteins via the algorithm in Hobohm et al. (1992). This algorithm selects a representative sample of proteins from the vast Protein Data Bank (PDB, Berman et al., 2000). The dataset contains 233 pairs of dihedral angles.
data(ProteinsAAA)
data(ProteinsAAA)
Two columns of angles in radians
Protein Data Bank (PDB)
Hobohm, U. and Scharf, M. and Schneider, R. and Sander, C. (1992) Selection of a Representative Set of Structures from the Brookhaven Protein Data Bank, Protein Science, 1, 409-417. Berman, H. M. and Westbrook, J. and Feng, Z. and Gilliand, G. and Bhat, T. N. and Weissing, H. and Shyndialov, I. N. and Bourne, P. E. (2000) The Protein Data Bank, Nucleic Acids Research, 28, 235-242.
Density function for the SNNTS model for spherical data
snntsdensity(data, cpars = 1, M = c(0,0))
snntsdensity(data, cpars = 1, M = c(0,0))
data |
Matrix of angles in radians. The first column contains longitude data (between zero and 2*pi), and second column contains latitude data (between zero and pi), with one row for each data point |
cpars |
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to one. |
M |
Vector with the number of components in the SNNTS for each dimension |
The function returns the density function evaluated for each row in the data
The parameters cinitial and cestimates used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Juan Jose Fernandez-Duran, Maria Mercedes Gregorio-Dominguez (2016). CircNNTSR: An R Package for the Statistical Analysis of Circular, Multivariate Circular, and Spherical Data Using Nonnegative Trigonometric Sums. Journal of Statistical Software, 70(6), 1-19. doi:10.18637/jss.v070.i06
data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(2,3) cpars<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpars[1]<-Re(cpars[1]) cpars<- cpars/sqrt(sum(Mod(cpars)^2)) snntsdensity(data, cpars, M)
data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(2,3) cpars<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpars[1]<-Re(cpars[1]) cpars<- cpars/sqrt(sum(Mod(cpars)^2)) snntsdensity(data, cpars, M)
Computes the points needed to plot the SNNTS density function for spherical data
snntsdensityplot(long, lat, cpars = 1, M = c(0,0))
snntsdensityplot(long, lat, cpars = 1, M = c(0,0))
long |
Grid for longitude. Vector with values between zero and 2*pi |
lat |
Grid for latitude. Vector with values between zero and pi |
cpars |
Vector of complex numbers of dimension prod(M+1). The sum of the squared moduli of the c parameters must be equal to one |
M |
Vector with the number of components in the SNNTS for each dimension |
The points needed to plot the SNNTS density function
The parameters cpars used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran J. J. y Gregorio Dominguez, M. M. (2008) Spherical Distributions Based on Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C08.6
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cest<-snntsmanifoldnewtonestimation(data, M, iter=150) cpars<-cest$cestimates[,3] longitud<-seq(0,360,10)*(pi/180) latitud<-seq(0,180,5)*(pi/180) z<-outer(longitud,latitud,FUN="snntsdensityplot",cpars,M) persp(longitud,latitud,z,theta=45,phi=30) contour(longitud,latitud,z) points(data[,1],data[,2])
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cest<-snntsmanifoldnewtonestimation(data, M, iter=150) cpars<-cest$cestimates[,3] longitud<-seq(0,360,10)*(pi/180) latitud<-seq(0,180,5)*(pi/180) z<-outer(longitud,latitud,FUN="snntsdensityplot",cpars,M) persp(longitud,latitud,z,theta=45,phi=30) contour(longitud,latitud,z) points(data[,1],data[,2])
Computes the log-likelihood function with SNNTS density for spherical data
snntsloglik(data, cpars = 1, M = c(0,0))
snntsloglik(data, cpars = 1, M = c(0,0))
data |
Matrix of angles in radians. The first column contains longitude data (between zero and 2*pi), and the second column containslatitude data (between zero and pi), with one row for each data point |
cpars |
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The first M[1]+1 elements correspond to longitude, the next M[2]+1 elements correspond to latitude. The sum of the squared moduli of the c parameters must be equal to 1 |
M |
Vector with number of components in the SNNTS for each dimension |
The function returns the value of the log-likelihood function for the data
The parameters cpars used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran J. J. y Gregorio Dominguez, M. M. (2008) Spherical Distributions Based on Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C08.6
data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cpars<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpars[1]<-Re(cpars[1]) cpars<- cpars/sqrt(sum(Mod(cpars)^2)) snntsdensity(data, cpars, M) snntsloglik(data, cpars, M)
data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cpars<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpars[1]<-Re(cpars[1]) cpars<- cpars/sqrt(sum(Mod(cpars)^2)) snntsdensity(data, cpars, M) snntsloglik(data, cpars, M)
Computes the maximum likelihood estimates of the SNNTS model parameters using a Newton algorithm on the hypersphere
snntsmanifoldnewtonestimation(data, M = c(0,0), iter = 1000, initialpoint = FALSE, cinitial)
snntsmanifoldnewtonestimation(data, M = c(0,0), iter = 1000, initialpoint = FALSE, cinitial)
data |
Matrix of angles in radians, with one row for each data point. The first column contains longitude data (between zero and 2*pi), and second column contains latitude data (between zero and pi), with one row for each data point |
M |
Vector with number of components in the SNNTS for each dimension |
iter |
Number of iterations |
initialpoint |
TRUE if an initial point for the optimization algorithm will be used |
cinitial |
Initial value for cpars for the optimization algorithm, avector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to one. |
cestimates |
Matrix of prod(M+1)*(3). The first two columns are the parameter numbers, and the last column is the c parameter's estimators |
loglik |
Optimum log-likelihood value |
AIC |
Value of Akaike's Information Criterion |
BIC |
Value of Bayesian Information Criterion |
gradnormerror |
Gradient error after the last iteration |
The parameters cinitial and cestimates used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran J. J. y Gregorio Dominguez, M. M. (2008) Spherical Distributions Based on Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C08.6
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cpar<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpar[1]<-Re(cpar[1]) cpar<- cpar/sqrt(sum(Mod(cpar)^2)) cest<-snntsmanifoldnewtonestimation(data,c(4,4),100,TRUE,cpar) cest cest<-snntsmanifoldnewtonestimation(data,c(1,2),100) cest
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(4,4) cpar<-rnorm(prod(M+1))+rnorm(prod(M+1))*complex(real=0,imaginary=1) cpar[1]<-Re(cpar[1]) cpar<- cpar/sqrt(sum(Mod(cpar)^2)) cest<-snntsmanifoldnewtonestimation(data,c(4,4),100,TRUE,cpar) cest cest<-snntsmanifoldnewtonestimation(data,c(1,2),100) cest
Marginal density function for latitude of the SNNTS model for spherical data
snntsmarginallatitude(data, cpars = 1, M = c(0,0))
snntsmarginallatitude(data, cpars = 1, M = c(0,0))
data |
Vector of angles in radians, with one row for each data point. The data must be between zero and pi. |
cpars |
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The sum of the squared moduli of the c parameters must be equal to one |
M |
Vector with the number of components in the SNNTS for each dimension |
The function returns the SNNTS marginal density function for latitude evaluated at data
The parameters cpars used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran J. J. y Gregorio Dominguez, M. M. (2008) Spherical Distributions Based on Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C08.6
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(1,2) cest<-snntsmanifoldnewtonestimation(data, M,iter=150) lat<-snntsmarginallatitude(seq(0,pi,.1),cest$cestimates[,3],M) plot(seq(0,pi,.1),lat,type="l")
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(1,2) cest<-snntsmanifoldnewtonestimation(data, M,iter=150) lat<-snntsmarginallatitude(seq(0,pi,.1),cest$cestimates[,3],M) plot(seq(0,pi,.1),lat,type="l")
Marginal density function for the longitude of the SNNTS model for spherical data
snntsmarginallongitude(data, cpars = 1, M = c(0,0))
snntsmarginallongitude(data, cpars = 1, M = c(0,0))
data |
Vector of angles in radians, with one row for each data point. The data must be between zero and 2*pi |
cpars |
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The first M[1]+1 elements correspond to longitude, and the next M[2]+1 elements correspond to latitude. The sum of the squared moduli of the c parameters must be equal to one. |
M |
Vector with number of components in the SNNTS for each dimension |
The function returns the density function evaluated for the data
The parameters cpars used by this function are the transformed parameters of the SNNTS density function, which lie on the surface of the unit hypersphere
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
Fernandez-Duran J. J. y Gregorio Dominguez, M. M. (2008) Spherical Distributions Based on Nonnegative Trigonometric Sums, Working Paper, Statistics Department, ITAM, DE-C08.6
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(1,2) cest<-snntsmanifoldnewtonestimation(data, M,iter=150) long<-snntsmarginallongitude(seq(0,2*pi,.1),cest$cestimates[,3],M) plot(seq(0,2*pi,.1),long,type="l")
set.seed(200) data(Datab6fisher_ready) data<-Datab6fisher_ready M<-c(1,2) cest<-snntsmanifoldnewtonestimation(data, M,iter=150) long<-snntsmarginallongitude(seq(0,2*pi,.1),cest$cestimates[,3],M) plot(seq(0,2*pi,.1),long,type="l")
Simulation for the density function for the SNNTS model
snntssimulation(nsim=1, cpars =(1/(2*pi))^2, M = c(0,0))
snntssimulation(nsim=1, cpars =(1/(2*pi))^2, M = c(0,0))
nsim |
Number of simulations |
cpars |
Vector of complex numbers of dimension prod(M+1). The first element is a real and positive number. The first M[1]+1 elements correspond to longitude, the next M[2]+1 elements correspond to latitude. The sum of the squared moduli of the c parameters must be equal to one |
M |
Vector with the number of components in the SNNTS for each dimension |
simulations |
The function generates nsim random values from the SNNTS density function |
conteo |
Number of uniform random numbers used for simulations |
Juan Jose Fernandez-Duran and Maria Mercedes Gregorio-Dominguez
M<-c(2,3) R<-length(M) ccoef<-mnntsrandominitial(M,R) data<-mnntssimulation(10,ccoef,M,R) data
M<-c(2,3) R<-length(M) ccoef<-mnntsrandominitial(M,R) data<-mnntssimulation(10,ccoef,M,R) data
Monthly number of suicides in Mexico during 2005
data(SuicidesMexico2005)
data(SuicidesMexico2005)
Integer values
INEGI (Mexican National Statistical Agency) www.inegi.gob.mx
Data measurement of the directions taken by 76 turtles after treatment
data(Turtles)
data(Turtles)
Directions of turtles in degrees
Stephens (1969) Techniques for directional data. Technical Report 150. Dept. of Statistics, Stanford University. Stanford, CA.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
Data measurement of the directions taken by 76 turtles after treatment
data(Turtles_radians)
data(Turtles_radians)
Directions of turtles in radians
Stephens (1969) Techniques for directional data. Technical Report 150. Dept. of Statistics, Stanford University. Stanford, CA.
N.I. Fisher (1993) Statistical analysis of circular data. Cambridge University Press.
Wind directions registered at the monitoring stations of San Agustin located in the north, Pedregal in the southwest, and Hangares in the southeast of the Mexico Central Valley's at 14:00 on days between January 1, 1993 and February 29, 2000. There are a total of 1,682 observations
data(WindDirectionsTrivariate)
data(WindDirectionsTrivariate)
Three columns of angles in radians
Mexico Central Valleys pollution monitoring network. RAMA SIMAT (Red Automatica de Monitoreo Ambiental)