nvalues <- 3
nvars <- 10
nsamples <- 10000
data <- matrix( sample( 0:(nvalues - 1), nvars * nsamples, replace = TRUE ), nsamples, nvars )
dc <- rep(nvalues, nvars)
system.time( g2Test_univariate(data = data, dc = dc) )
a <- g2Test_univariate(data = data, dc = dc)
pval <- pchisq(a$statistic, a$df, lower.tail = FALSE)
g <- matrix(0, nvars, nvars)
g[ cbind(a$x, a$y) ] <- a$statistic
g <- g + t(g)
diag(g) <- 0
g ## matrix of G^2 test statistics
pv <- matrix(0, nvars, nvars)
pv[ cbind(a$x, a$y) ] <- pval
pv <- pv + t(pv)
diag(pv) <- 1
pv ## matrix of the corresponding p-values
Run the code above in your browser using DataLab