testk.mdf: MDF test

Description Usage Arguments Value References Examples

View source: R/stat_testk.mdf.R

Description

Given the distance matrix of two or more samples, it tests

H_0 : F_{g_1} = \cdots = F_{g_K} F_Y\quad vs\quad H_1 : \textrm{ not } H_0

using the procedure by Minas et al. (2011) in a nonparametric way that depends on mc.iter number of permutations.

Usage

1
testk.mdf(x, label, mc.iter = 999)

Arguments

x

an (N\times N) matrix or dist object.

label

length-N vector of class/grouping label.

mc.iter

the number of permutations to be taken.

Value

a (list) object of S3 class htest containing:

statistic

a test statistic.

p.value

p-value under H_0.

alternative

alternative hypothesis.

method

name of the test.

data.name

name(s) of provided sample data.

permvec

statistics from each permutation.

References

\insertRef

minas_distance-based_2011DAS

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## small test for CRAN submission
dat1 <- matrix(rnorm(60, mean= 1), ncol=2) # group 1 : 30 obs of mean  1
dat2 <- matrix(rnorm(50, mean=-1), ncol=2) # group 2 : 25 obs of mean -1

dmat <- as.matrix(dist(rbind(dat1, dat2)))  # Euclidean distance matrix
lab  <- c(rep(1,30), rep(2,25))             # corresponding label

testk.mdf(dmat, lab)                        # run the code !

## Not run: 
## WARNING: computationally heavy. 
#  Let's compute empirical Type 1 error at alpha=0.05
niter = 496  
pvals = rep(0,niter)
for (i in 1:niter){
  dat = matrix(rnorm(200),ncol=2)
  lab = c(rep(1,50), rep(2,50))
  pvals[i] = testk.mdf(as.matrix(dist(dat)), lab)$p.value
  print(paste("iteration ",i," complete..",sep=""))
}
print(paste("* Empirical Type 1 Error : ",sum(pvals<=0.05)/niter,sep=""))

#  Visualize the above at multiple significance levels
alphas = seq(from=0.001, to=0.999, length.out=100)
errors = rep(0,100)
for (i in 1:100){
   errors[i] = sum(pvals<=alphas[i])/niter
}
plot(alphas, errors, "b", main="Empirical Type 1 Errors", 
     xlab="alpha", ylab="error", lwd=2)
abline(v=0.05, lwd=2, col="red")

## End(Not run)

kyoustat/DAS documentation built on Jan. 6, 2020, 7:10 a.m.