cramer.test {cramer} | R Documentation |
Perform Cramer-test for two-sample-problem. Both univariate and multivariate data is possible. For calculation of the critical value bootstrap-methods are used. Ordinary and permutation methods can be chosen as well as the number of bootstrap-replicates taken.
cramer.test(x,y,conf.level=0.95,replicates=1000, sim="ordinary",just.statistic=FALSE)
x |
First set of observations. Either in vector form (univariate) or in a matrix with one observation per row (multivariate). |
y |
Second set of observations. Same dimension as x .
|
conf.level |
Confidence level of test. |
replicates |
Number of bootstrap-replicates taken to obtain critical value. |
sim |
Type of bootstrap method. Possible values are "ordinary" for normal
bootstrap and "permutation" for a permutation test.
|
just.statistic |
Boolean variable. If TRUE just the value of the Cramer-statistic
is calculated and no bootstrap-replicates are produced.
|
The Cramer-statistic is given by
T=mn/(m+n) ( 1/(mn) Sum[i=1..m,j=1..n] ||X_i-Y_j|| - 1/(2m^2) Sum[i=1..m,j=1..m] ||X_i-X_j|| - 1/(2n^2) Sum[i=1..n,j=1..n] ||Y_i-Y_j|| )
The critical value is obtained by using the bootstrap-method with this statistic.
The proof that this procedure yields in a working test is given in the reference
listed below.
The idea of using this statistic is due to L. Baringhaus, University of Hanover.
The returned value is an object of class "cramertest"
, containing the following
components:
method |
Describing the test in words. |
d |
Dimension of the observations. |
m |
Number of x observations.
|
n |
Number of y observations.
|
statistic |
Value of the Cramer-statistic for the given observations. |
conf.level |
Confidence level for the test. |
crit.value |
Critical value calculated by bootstrap method. |
p.value |
Estimated p-value of the test. |
result |
Contains 1 if the hypothesis of equal distributions should not be accepted and
0 otherwise.
|
sim |
Method used for obtaining the critical value. |
replicates |
Number of bootstrap-replicates taken. |
The test and its properties is described in :
Baringhaus, L. and Franz, C. (2001) On a new multivariate two-sample test, submitted
Franz, C. (2000) Ein statistischer Test fuer das mehrdimensionale Zweistichproben-Problem, German, Diploma thesis, University of Hanover.
# comparison of two univariate normal distributions x<-rnorm(20,mean=0,sd=1) y<-rnorm(50,mean=0.5,sd=1) cramer.test(x,y) # comparison of two multivariate normal distributions with permutation test library(MASS) x<-mvrnorm(n=20,mu=c(0,0),Sigma=diag(c(1,1))) y<-mvrnorm(n=50,mu=c(0.3,0),Sigma=diag(c(1,1))) cramer.test(x,y,sim="permutation")