Learn R Programming

gTestsPair (version 0.1)

g.tests_pair: New Non-parametric Tests for Multivariate Paired Data and Pair Matching

Description

This function provides three non-parametric two-sample tests for paired data and pair matching.

Usage

g.tests_pair(E, n, test.type = "all", perm = 0)

Value

test.statistic

The value of the test statistic.

pval.approx

The approximated p-value based on asymptotic theory.

pval.perm

The permutation p-value when the argument `perm` is positive.

Arguments

E

An edge matrix representing a similarity graph on all observations with the number of edges in the similarity graph being the number of rows and 2 columns. Each row records the indices of the two ends of an edge in the similarity graph.

n

The number of pairs.

test.type

The default value is "all", which means all three tests, the orignial edge-count test, the scaled edge-count test, and the generalized edge-count test, are performed. Set this value to "original" or "o" to perform only the original edge-count test; set this value to "scaled" or "s" to perform only the scaled edge-count test; set this value to "generalized" or "g" to perform only the generalized edge-count test.

perm

The number of permutations performed to calculate the p-value of the test. The default value is 0, which means the permutation is not performed and only the approximate p-value based on asymptotic theory is provided. Doing permutation could be time consuming, so be cautious if you want to set this value to be larger than 10,000.

References

Zhang J., Chen H., and Zhou XH. A new non-parametric test for multivariate paired data from pair matching or paired designs.

Examples

Run this code
# The "example_pair" data contains the paired data 'data_pair'. 
# It is a n by 2p matrix with n being the number of pairs and p being the dimension of 
# observations. 
# For each row, the first p columns represent the observation from sample 1, and the 
# second p columns represent the paired observation from sample 2. 
# The data is generated from a paired design with mean shift. 
    data(example_pair)
    n = nrow(data_pair)
    p = ncol(data_pair)/2
    k = 5
    data1 = data_pair[,1:p]
    data2 = data_pair[,(p+1):(2*p)]
    case = rbind(data1,data2)
    dist1 = as.matrix(dist(case))
    library("ade4")
    E = mstree(as.dist(dist1),k)
    g.tests_pair(E,n)

# Get permutation p-value with 300 permutations.
    g.tests_pair(E, n, perm = 300)

Run the code above in your browser using DataLab