View source: R/stat_test2.2014bg.R
Biswas and Ghosh (2014)
1 | test2.2014bg(x, label, mc.iter = 999)
|
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
test2.2014bg(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] = test2.2014bg(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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.