Learn R Programming

MATES (version 0.1)

MATES_test: MATES test statistic with pre-computed view matrices

Description

This function takes a list of view matrices (R_list) and other parameters to compute the MATES test statistic.

Usage

MATES_test(UxUy, R_list, m, n, perm = NULL)

Value

A list with the MATES test statistic (test.stat) and p-value (pval)

Arguments

UxUy

A numeric vector of length 2*S containing the Ux and Uy statistics for each view

R_list

A list of numeric matrices with length S

m

An integer representing the number of sample in X

n

An integer representing the number of sample in Y

perm

An integer indicating the number of permutation (default is NULL, which uses closed form)

Examples

Run this code
# \donttest{
# Generate simulated data
set.seed(123)
X <- matrix(rnorm(20), ncol = 2)  # 10 samples, 2 dimensions
Y <- matrix(rnorm(20), ncol = 2)  # 10 samples, 2 dimensions
Z <- rbind(X, Y)
m <- nrow(X)
n <- nrow(Y)
N <- m + n

# Compute distance and similarity matrices
D <- as.matrix(dist(Z, method = "manhattan"))
S <- max(D) - D

# Compute rank matrix (simplified NNG approach)
R <- matrix(0, N, N)
k <- 3
for(i in 1:N) {
  neighbors <- order(D[i,])[2:(k+1)]  # k nearest neighbors
  R[i, neighbors] <- 1:k
}
R <- R + t(R)

# Create list with one rank matrix
R_list <- list(R)

# Calculate test statistics (Ux and Uy)
sample1ID <- 1:m
sample2ID <- (m+1):N
Ux <- sum(R[sample1ID, sample1ID])
Uy <- sum(R[sample2ID, sample2ID])
UxUy <- c(Ux, Uy)

# Perform MATES test
result <- MATES_test(UxUy, R_list, m = m, n = n)
print(result$test.stat)
print(result$pval)
# }

Run the code above in your browser using DataLab