Learn R Programming

USP (version 0.1.2)

USP: Permutation test of independence.

Description

Carry out an independence test of the independence of two samples, give two kernel matrices \(J\) and \(K\), as described in Section 7.1 of BKS2020USP. We calculate the test statistic and null statistics using the function KernStat, before comparing them to produce a p-value. For the featured examples considered these matrices can be calculated using FourierKernel or InfKern. Alternatively, if a different basis is to be used, then the kernels can be entered separately.

Usage

USP(J, K, B = 999, ties.method = "standard", nullstats = FALSE)

Arguments

J

\(n \times n \) kernel matrix corresponding to first sample.

K

\(n \times n \) kernel matrix corresponding to second sample.

B

The number of permutation used to calibrate the test.

ties.method

If "standard" then calculate the p-value as in (5) of BKS2020USP, which is slightly conservative. If "random" then break ties randomly. This preserves Type I error control.

nullstats

If TRUE, returns a vector of the null statistic values.

Value

Returns the p-value for this independence test and the value of the test statistic, \(D_n\), as defined in BKS2020USP. If nullstats=TRUE is used, then the function also returns a vector of the null statistics.

References

BKS2020USP

Examples

Run this code
# NOT RUN {
x=runif(100); y=runif(100); M=3
J=FourierKernel(x,M); K=FourierKernel(y,M)
USP(J,K,999)

n=50; r=0.6; Ndisc=1000; t=1/Ndisc
X=matrix(rep(0,Ndisc*n),nrow=n); Y=matrix(rep(0,Ndisc*n),nrow=n)
for(i in 1:n){
 x = rnorm(Ndisc, mean=0, sd= 1)
 se = sqrt(1 - r^2) #standard deviation of error
 e = rnorm(Ndisc, mean=0, sd=se)
 y = r*x + e
 X[i,] = cumsum(x*sqrt(t))
 Y[i,] = cumsum(y*sqrt(t))
}
J=InfKern(X,2,1); K=InfKern(Y,2,1)
USP(J,K,999)
# }

Run the code above in your browser using DataLab