R version 4.5.0 beta (2025-04-02 r88102 ucrt) -- "How About a Twenty-Six" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(oompaBase) > # a key point is to test the matrixPairedT code > # we create a simple example > suppressWarnings( RNGversion("3.5.3") ) > set.seed(372284) > nPairs <- 3 > nGenes <- 7 > m <- matrix(rnorm(2*nPairs*nGenes), ncol=2*nPairs) > v <- factor(rep(c("A","B"), each=nPairs)) > pf <- rep(1:nPairs, 2) > colnames(m) <- paste(as.character(v), pf, sep='') > round(m, 2) A1 A2 A3 B1 B2 B3 [1,] -0.08 -1.18 0.75 -1.71 0.02 0.45 [2,] -0.86 -0.62 2.65 1.79 -0.40 -2.04 [3,] -1.74 2.21 -0.55 -0.21 -0.15 0.45 [4,] 0.03 0.24 -1.25 0.24 -0.28 -0.42 [5,] -1.63 -0.22 1.35 0.06 0.18 -1.35 [6,] 1.04 -1.94 -0.72 -0.36 1.03 -1.70 [7,] 0.36 0.73 0.70 3.91 0.29 -1.00 > # Now we run the package code > mpt <- matrixPairedT(m, v, pf) > # We also loop over the standard t.test function > # for each gene > realt <- sapply(1:nGenes, function(i) { + x <- m[i, v=="A"] + y <- m[i, v=="B"] + t1 <- t.test(y, x, paired=TRUE) + t1$statistic + }) > # The differences should all be less than 1e-15 > all(round(mpt-realt, 15) == 0) [1] TRUE > > # for completeness, we also check the unpaired result > > mtt <- matrixT(m, v) > realt <- sapply(1:nGenes, function(i) { + x <- m[i, v=="A"] + y <- m[i, v=="B"] + t1 <- t.test(x, y, paired=FALSE, var.equal=TRUE) + t1$statistic + }) > # The differences should all be less than 1e-15 > all(round(mtt-realt, 15) == 0) [1] TRUE > > # and the unequal variance case > mut <- matrixUnequalT(m,v) > realt <- sapply(1:nGenes, function(i) { + x <- m[i, v=="A"] + y <- m[i, v=="B"] + t1 <- t.test(x, y, paired=FALSE, var.equal=FALSE) + t1$statistic + }) > # The differences should all be less than 1e-15 > all(round(mut$tt-realt, 15) == 0) [1] TRUE > > proc.time() user system elapsed 0.25 0.07 0.34