USP {USP} | R Documentation |
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 (Berrett et al. 2021).
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 |
|
K |
|
B |
The number of permutation used to calibrate the test. |
ties.method |
If "standard" then calculate the p-value as in (5) of (Berrett et al. 2021), 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 (Berrett et al. 2021). If nullstats=TRUE is used, then the function also
returns a vector of the null statistics.
References
Berrett TB, Kontoyiannis I, Samworth RJ (2021). “Optimal rates for independence testing via U-statistic permutation tests.” Annals of Statistics, to appear.
Examples
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)