The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Type: Package
Title: Tests of Randomness and Tests of Independence
Version: 1.2.0
Description: Functions for testing randomness for a univariate time series with arbitrary distribution (discrete, continuous, mixture of both types) and for testing independence between random variables with arbitrary distributions. The test statistics are based on the multilinear empirical copula and multipliers are used to compute P-values. The test of independence between random variables appeared in Genest, Nešlehová, Rémillard & Murphy (2019) and the test of randomness appeared in Nasri (2022).
License: GPL-3
Encoding: UTF-8
LazyData: true
Depends: R (≥ 3.5.0), doParallel, parallel, foreach, stats, copula
Imports: ggplot2,survey
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2024-02-13 12:43:42 UTC; Utilisateur
Author: Bouchra R. Nasri [aut, cre, cph], Bruno N Remillard [aut], Johanna G Neslehova [aut], Christian Genest [aut]
Maintainer: Bouchra R. Nasri <bouchra.nasri@umontreal.ca>
Repository: CRAN
Date/Publication: 2024-02-14 00:04:09 UTC

Dependogram for Kendall's tau and Spearman's rho

Description

This function, used in EstDepSerial, draws the P-values of Kendall's tau and Spearman's rho for a given number of lags.

Usage

AutoDep(out)

Arguments

out

List of the output of EstDepSerial (P-values, subsets)

References

B.R Nasri (2021). Tests of serial dependence for arbitrary distributions

Examples

out <-EstDepSerial(SimAR1Poisson(c(5,0.4),100),10)
AutoDep(out)


Dependogram for Cramer-von Mises statistics

Description

This function, used in EstDep, TestIndCopula and TestIndSerCopula, draws the P-values of the Moebius Cramer-von Mises statistics from the multilinear copula and their combination for a tests of randomness for k consectives values X(1), ..., X(k) or for a test of independence between random variables.

Usage

Dependogram(out, stat = "CVM")

Arguments

out

List of the output from EstDep, EstDepSerial, TestIndCopula or TestIndSerCopula (P-values, subsets)

stat

Name of statistics to be used (default is "CVM")

References

Genest, Neslehova, Remillard & Murphy (2019). Testing for independence in arbitrary distributions

Examples

x <- matrix(rnorm(250),ncol=5)
out <-TestIndCopula(x)
Dependogram(out)


Dependogram for Moebius correlations

Description

This function, used in EstDepMoebius and EstDepSerialMoebius plot the graphs of the correlation statistics of Spearman, van der Waerden and Savage as a function of the subsets for tests of randomness or test of independence between random variables. Under the null hypothesis, the statistics should be independent N(0,1).

Usage

DependogramZ(out, n)

Arguments

out

List of the output from EstDep, EstDepSerial, TestIndCopula or TestIndSerCopula (P-values, subsets)

n

Number of observations

References

Nasri & Remillard (2023). Tests of independence and randomness for arbitrary data using copula-based covariances

Examples

x <- matrix(rnorm(250),ncol=5)
out <-EstDepMoebius(x)
DependogramZ(out,50)


Kendall's tau and Spearman's rho statistics for testing independence between random variables

Description

This function computes the matrix of pairs of Kendall's tau and Spearman's rho statistics between random variables with arbitrary distributions.

Usage

EstDep(x, graph = FALSE)

Arguments

x

Data matrix

graph

Set to TRUE for a dependogram for all pairs of Kendall's taus and Spearman's rhos.

Value

stat

List of Kendall's tau and Spearman's rho statistics from multilinear copula, and test combinations LB

pvalue

P-values for the tests statistics

References

Genest, Neslehova, Remillard & Murphy (2018). Testing for independence in arbitrary distributions

Examples

x <- matrix(rnorm(500),ncol=10)
out <-EstDep(x)

Dependence measures and statistics for test of independence between random variables

Description

This function computes copula-based dependence measures for Moebius versions of Spearmans's rho, van der Waerden's coefficient, and Savage's coefficient, as well as their combination for tests of independence between random variables.

Usage

EstDepMoebius(x, trunc.level = 2, graph = FALSE)

Arguments

x

Data matrix

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

graph

Set to TRUE if one wants the dependogram of P-values for the Moebius statistics

Value

stat

List of statistics (spearman, vdw, savage) and test combinations Ln and Ln2 (only pairs)

pvalue

P-values for the tests

cardA

Cardinaly of the subsets for the Moebius statistics

subsets

Subsets for the Moebius statistics

References

B.R Nasri & B.N. Remillard (2023). Tests of independence and randomness for arbitrary data using copula-based covariances

Examples

x <- matrix(rnorm(250),ncol=5)
out <-EstDepMoebius(x,3)

Kendall's tau and Spearman's rho statistics for testing randomness in a univariate time series

Description

This function computes Kendall's tau and Spearman's rho statistics for tests of randomness in a time series with arbitrary distribution for pairs (X[i],X[i+k]), k=1:lags

Usage

EstDepSerial(x, lag, graph = FALSE)

Arguments

x

Time series

lag

Number of lags

graph

Set to TRUE for a dependogram for Kendall's tau and Spearman;s rho

Value

stat

List of Kendall's tau and Spearman's rho statistics from multilinear copula, and test combinations LB

pvalue

P-values for the tests statistics

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

Examples

out <-EstDepSerial(SimAR1Poisson(c(5,0.4),100),10)

Dependence measures and statistics for test of randomness for a univariate time series

Description

This function computes copula-based dependence measures for Moebius versions of Spearmans's rho, van der Waerden's coefficient, and Savage's coefficient, as well as their combination for tests of randomness for p consecutive values Y(1), ..., Y(p).

Usage

EstDepSerialMoebius(y, p, trunc.level = 2, graph = FALSE)

Arguments

y

Time series

p

Number of consecutive observations

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

graph

Set to TRUE if one wants the dependogram of P-values for the Moebius statistics

Value

stat

List of statistics (spearman, vdw, savage) and test combinations Ln and Ln2 (only pairs)

pvalue

P-values for the tests

card

Cardinaly of the subsets for the Moebius statistics

subsets

Subsets for the Moebius statistics

References

B.R Nasri & B.N. Remillard (2023). Tests of independence and randomness for arbitrary data using copula-based covariances

Examples

y<- SimAR1Poisson(c(5,0.2),100)
out <- EstDepSerialMoebius(y,4,4)

Quantile function of margins

Description

This function computes the quantile of seven cdf used in the simulatuons of Nasri (2022).

Usage

Finv(u, k)

Arguments

u

Vector of probabilities

k

Marginal distribution: [1] Bernoulli(0.8), [2] Poisson(6), [3] Negative binomial with r = 1.5, p = 0.2, [4] Zero-inflated Poisson (10) with w = 0.1 and P(6.67) otherwise, [5] Zero-inflated Gaussian, [6] Discretized Gaussian, [7] Discrete Pareto(1)

Value

x

Vector of quantiles

Author(s)

Bouchra R. Nasri January 2021

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

Examples

x = Finv(runif(100),2)

Simulation of a AR(1) Poisson process

Description

Conditionally on the past, X[t] is Poisson with lambda[t] = a+bX[t-1]

Usage

SimAR1Poisson(param, n)

Arguments

param

Param[1] = a>0, param[2] = b, 0<=b <1 (for stationarity)

n

Length of the series.

Value

X

Simulated series

Examples

data <- SimAR1Poisson(c(5,0.4),500)

Simulation of a copula-based time series

Description

This function simulates a Markovian time series (p-Markov for the Farlie-Gumbel-Morgenstern copula) with uniform margins using a copula family for the joint distribution of U[t], U[t-1].

Usage

SimCopulaSeries(family, n, tau = 0, param = NULL)

Arguments

family

"ind", "tent", "gaussian", "t" , "clayton", "fgm", "frank", "gumbel", joe" , "plackett"

n

length of the time series

tau

Kendall's tau of the copula family

param

extra copula parameter: for "fgm", param is the dimension of the copula; for "t", param = nu

Value

U

Simulated time series

Author(s)

Bouchra R. Nasri January 2021

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

Examples

U = SimCopulaSeries("fgm",100,0.2, 3) # for the FGM, |tau|<= 2/9

Computes the Moebius Cramer-von Mises statistics for the test of independence between random variables

Description

This function computes Moebius Cramer-von Mises statistics for a tests of independence for matrix of data x.

Usage

Sn_A(x, trunc.level)

Arguments

x

Matrix of observations.

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

Value

stats

Cramer-von Mises Moebius statistics

cardA

Cardinality of subsets

M

Matrix for multitpliers bootstrap for stats

Asets

Vector of (0,1) for Moebius subsets

Sn

Cramer-von Mises Sn statistic

J

Matrix for multipliers bootstrap for Sn

References

Genest, Neslehova, Remillard & Murphy (2019). Testing for independence in arbitrary distributions

#'@examples X <- rnorm(100,5) out <- Sn_A(X,3)


Computes the Moebius Cramer-von Mises statistics for the test of randomness

Description

This function computes Moebius Cramer-von Mises statistics for a tests of randomness for observations X(1), ..., X(p).

Usage

Sn_Aserial(x, p, trunc.level)

Arguments

x

Time series.

p

Number of consecutive observations for the test.

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

Value

stats

Cramer-von Mises Moebius statistics

cardA

Cardinality of subsets

M

Matrix for multitpliers bootstrap for stats

Asets

Vector of (0,1) for Moebius subsets

Sn

Cramer-von Mises Sn statistic

J

Matrix for multipliers bootstrap for Sn

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

#'@examples X <- SimAR1Poisson(c(5,0.2),100) out <- Sn_Aserial(X,5,3)


Computes the Moebius Cramer-von Mises statistics for the test of randomness

Description

This function he Moebius Cramer-von Mises statistics for a tests of randomness for random vectors Y(1), ...l, X(p).

Usage

Sn_AserialVec(Y, p, trunc.level = 2)

Arguments

Y

Time series.

p

Number of consecutive observations for the test.

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

Value

stats

Cramer-von Mises Moebius statistics

cardA

Cardinality of subsets

M

Matrix for multitpliers bootstrap for stats

Asets

vector of (0,1) for Moebius subsets

Sn

Cramer-von Mises Sn statistic

J

Matrix for multipliers bootstrap for Sn

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

#'@examples Y <- data(Y) out <- Sn_Aserial(Y,5,2)


Computes the Cramer-von Mises statistic Sn for the test of randomness

Description

This function computes the Cramer-von Mises statistic for a tests of randomness for p consecutives values X(1), ..., X(p). Useful for traditional bootstrapping.

Usage

Sn_serial(x, p)

Arguments

x

Time series

p

Number of consecutive observations

Value

stats

Cramer-von Mises statistics Sn

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

#'@examples X <- SimAR1Poisson(c(5,0.2),100) out <- Sn_serial(X,5,3)


Statistics and P-values for a test of independence between random variables

Description

This function computes Cramer-von Mises statistics and their combination for a tests of independence between random variables with arbitrary distributions. The P-values are computed using Gaussian multipliers.

Usage

TestIndCopula(
  x,
  trunc.level = 2,
  B = 1000,
  par = FALSE,
  ncores = 2,
  graph = FALSE
)

Arguments

x

Data matrix

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

B

Number of multipliers samples (default = 1000)

par

Set to TRUE if one prefers paraller computing (slower)

ncores

Number of cores for parallel computing (default is 2)

graph

Set to TRUE if one wants the dependogram of P-values for the Moebius statistics

Value

stat

List of Cramer-von Mises statistics cvm, Sn from the multilinear copula, and test combinations Tn and Tn2 (only pairs)

pvalue

Approximated P-values for the tests using Gaussian multipliers

card

Cardinaly of the subsets for the Moebius statistics

subsets

Subsets for the Moebius statistics

References

Genest, Neslehova, Remillard & Murphy (2019). Testing for independence in arbitrary distributions

Examples

x <- matrix(rnorm(250),ncol=5)
out <-TestIndCopula(x)

Statistics and P-values for a test of randomness for a univariate time series

Description

This function computes Cramer-von Mises statistics from the multilinear copula and their combination for tests of randomness of p consecutives values X(1), ..., X(p). The p-values are computed using Gaussian multipliers.

Usage

TestIndSerCopula(
  x,
  p,
  trunc.level = 2,
  B = 1000,
  par = FALSE,
  ncores = 2,
  graph = FALSE
)

Arguments

x

Time series

p

Number of consecutive observations

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

B

Number of multipliers samples (default = 1000)

par

Set to TRUE if one prefers paraller computing (slower)

ncores

Number of cores for parallel computing (default = 2)

graph

Set to TRUE if one wants the dependogram of P-values for the Moebius statistics

Value

stat

List of Cramer-von Mises statistics cvm, Sn, and test combinations Tn and Tn2 (only pairs)

pvalue

Approximated P-values for the tests using Gaussian multipliers

card

Cardinaly of the subsets for the Moebius statistics

subsets

Subsets for the Moebius statistics

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

Examples

X <- SimAR1Poisson(c(5,0.2),100)
out <- TestIndSerCopula(X,5,3)

Statistics and P-values for a test of randomness for a multivariate time series

Description

This function computes Cramer-von Mises statistics from the multilinear copula and their combination for a tests of randomness for p consecutives values of random vectors X(1), ..., X(p). The p-values are computed using Gaussian multipliers.

Usage

TestIndSerCopulaMulti(x, p, trunc.level = 2, B = 1000, graph = FALSE)

Arguments

x

Time series matrix

p

Number of consecutive vectors

trunc.level

Only subsets of cardinality <= trunc.level (default=2) are considered for the Moebius statistics.

B

Number of multipliers samples (default = 1000)

graph

Set to TRUE if one wants the dependogram of P-values for the Moebius statistics

Value

stat

List of Cramer-von Mises statistics cvm, tilde Sn, and test combinations tilde Tn and tilde Tn2 (only pairs), as defined in Nasri(2022).

pvalue

Approximated P-values for the tests using Gaussian multipliers

References

B.R Nasri (2022). Tests of serial dependence for arbitrary distributions

Examples


data(Y)
out <- TestIndSerCopulaMulti(Y,5,5)


AR(1) Poisson with parameters

Description

Simulated AR(1) Poisson sequence of length n=100 with parameters c(5,0.4).

Usage

data(X)

Format

Count data.

Examples

data(X)
acf(X)

Bernoulli sequence

Description

Simulated Bernoulli sequence.

Usage

data(Xbin)

Format

Count data.

Examples

data(Xbin)
plot(Xbin)

VAR(1) Poisson with parameters

Description

Simulated VAR(1) Poisson sequence of length n=100.

Usage

data(Y)

Format

Count data.

Examples

data(Y)
acf(Y)

Function to perform multiplier bootstrap for tests of randomness or independence

Description

This function simulates Cramer-von Mises statistics using Gaussian multipliers.

Usage

bootstrap(M, J, n)

Arguments

M

n x n x m vector with MM[i,j] = 1(Xi <= Xj) and C=mean(M[,j]);

J

n x n vector for bootstrapping Sn.

n

length of the series.

Value

cvm_sim

Simulated value of the Cramer-von Mises statistics

sn_sim

simulated value of the Cramer-von Mises statistic Sn

References

B.R Nasri (2021). Tests of serial dependence for arbitrary distributions


Horseshoecrabs dataset

Description

Horseshoe Crab Data from Table 3.2 of Agresti(2007). This data set consists of five variables, three of which are categorical, measured on 173 female crabs, each having a male attached in her nest.

Usage

data(horseshoecrabs)

Format

Data frame with 173 rows and 5 variables:

References

Agresti, A. (2007). An Introduction to Categorical data analysis, John Wiley & Sons, Wiley Series in Probability and Statistics, 2nd edition.

Examples

data(horseshoecrabs)
x =data.matrix(horseshoecrabs)
out = TestIndCopula(x,trunc.level=5,graph=TRUE)

Fetal lamb dataset

Description

240 body movement measurements of a fetal lamb at consecutive 5 second intervals.

Usage

data(lamb)

Format

Count data.

References

Leroux B, Putterman M (1992). Maximum Penalized Likelihood estimation for independent and Markov-dependent Mixture models.Biometrics, 48, 545–558.

Examples

data(lamb)
plot(lamb)

Computes unique values, cdf and pdf

Description

This function computes the unique values, cdf and pdf for a series of data.

Usage

preparedata(x)

Arguments

x

Vector

Value

values

Unique (sorted) values

m

Number of unique values

Fn

Empirical cdf of the unique values

fn

Empirical pdf of the unique values

References

B.R. Nasri (2022). Tests of serial dependence for arbitrary distributions

C. Genest, J.G. Neslehova, B.N. Remillard and O. Murphy (2019). Testing for independence in arbitrary distributions.

#'@examples x = c(0,0,0,2,3,1,3,1,2,0) out <- prepare_data(x)


Data-driven selection of p for the test of randomness

Description

This function uses a AIC/BIC type criterion to select p based on the data.

Usage

select_p(X, p0 = 2, d = 5, q = 2.4, lambda = 0.25)

Arguments

X

Time series

p0

Minimum value of p (default is 2)

d

Maximum value of p (default is 5)

q

Constant for selecting between AIC and BIC type penalty (default is 2.4)

lambda

Penalty term (default is 0.25); small values lead to p=d, large value lead to p=p0

Value

p

Selected value of p

References

B.R Nasri (2021). Tests of serial dependence for arbitrary distributions

Examples

X <- SimAR1Poisson(c(5,0.2),100)
out <- select_p(X)


Computes the Kendall's taus and Spearman's rho for tests of randomness

Description

This function Computes the Kendall's taus and Spearman's rho for tests of independence used in EstDep

Usage

stat_dep(x, y)

Arguments

x

Vector of length n

y

Vector of length n

Value

tau

Kendall's taus for lags 1:lag

rho

Spearman's rhos for lags 1:lag

s2

Estimated variance of Spearman's rho

References

Genest, Neslehova, & Remillard (2017). Asymptotic behavior of the empirical multilinear copula process under broad conditions

Examples

x <- SimAR1Poisson(c(5,0.2),100)
y <- SimAR1Poisson(c(5,0.2),100)
out <- stat_dep(x,y)


Computes the Kendall's taus and Spearman's rho for tests of randomness

Description

This function Computes the Kendall's taus and Spearman's rho for tests of randomness.

Usage

stat_dep_ser(x, lag)

Arguments

x

Time series

lag

Number of lags.

Value

tau

Kendall's taus for lags 1:lag

rho

Spearman's rhos for lags 1:lag

References

B.R Nasri (2021). Tests of serial dependence for arbitrary distributions

Examples

X <- SimAR1Poisson(c(5,0.2),100)
out <- stat_dep_ser(X,10)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.