KStest(object, group, nperm=1000)
npermrandom permutations of sample labels.
npermtimes and calculating the test statistic for each. P-value is calculated as
nperm+ 1) where
bis the number of permutations giving a more extreme statistic than the observed test statistic.
Friedman J. and Rafsky L. (1979) Multivariate generalization of the Wald-Wolfowitz and Smirnov two-sample tests. Ann. Stat. 7, 697--717.
## generate a feature set of length 20 in two conditions ## each condition has 20 samples ## use multivariate normal distribution library(MASS) ngenes <- 20 nsamples <- 40 ## let the mean vector have zeros of length 20 both conditions zero_vector <- array(0,c(1,ngenes)) ## set the covariance matrix to be an identity matrix for both conditions cov_mtrx <- diag(ngenes) gp <- mvrnorm(nsamples, zero_vector, cov_mtrx) ## apply a mean shift of 3 to half of the features under condition 2 gp[1:20,1:10] <- gp[1:20,1:10] + 3 dataset <- aperm(gp, c(2,1)) ## first 20 samples belong to group 1 ## second 20 samples belong to group 2 result <- KStest(object=dataset, group=c(rep(1,20),rep(2,20))) pvalue <- result$p.value