Two-Group t Tests of Every Row, With Permutation p-Values on a GPU
gpuRowTtest.RdTests every row of x (every gene of an expression matrix, say)
for a difference in mean between two groups of columns, as
t.test does one row at a time, and optionally gives each
test a permutation p-value and a p-value adjusted for testing all the
rows, by Westfall and Young's maxT. The permutations run on the GPU,
every row under every relabelling of the samples at once.
Usage
gpuRowTtest(x, group, var.equal = FALSE, B = 0L,
precision = getOption("gputools.precision", "single"))Arguments
- x
a numeric matrix, a row per variable (gene), a column per sample, with no missing values.
- group
the samples' groups: a vector or factor with one entry per column of
xand exactly two levels, at least two samples in each.- var.equal
FALSEfor Welch's test,TRUEfor Student's with the variances pooled, as int.test.- B
the number of permutations, or 0 for none.
- precision
"single"or"double": the floating point precision the GPU computes the permutations in; seegpuCor.
Details
The t statistics, degrees of freedom and parametric p-values are those
of t.test(x[i, group == level1], x[i, group == level2],
var.equal = var.equal), the first level's mean minus the second's.
They are computed in double precision on the CPU: a t test of each row
is too little work to be worth sending to the GPU.
With B > 0, the samples' labels are permuted B times
(drawn with sample.int, so set.seed makes them
reproducible) and every row's t statistic is computed under each
permutation, on the GPU: two matrix products give every row's group
sums and sums of squares under all the labellings. A row's permutation
p-value is \((1 + b) / (1 + B)\) with \(b\) the permutations giving
\(|t_b| \ge |t|\) (Phipson and Smyth 2010); its
adjusted p-value counts the permutations whose largest \(|t_b|\) over
all the rows reaches \(|t|\): single-step maxT, which controls the
family-wise error rate (Westfall and Young 1993). Permuting the labels
keeps the dependence between genes, which the adjustment exploits, and
makes no assumption of normality.
A constant row, or one constant within both groups, has no test:
its statistic is NaN and its p-values NA.
Value
A data frame, a row per row of x, named as x's rows:
- mean1, mean2
the groups' means.
- statistic
the t statistic.
- df
its degrees of freedom.
- p.value
the two-sided p-value from the t distribution.
- p.perm
with
B > 0, the permutation p-value.- p.adjusted
with
B > 0, the maxT adjusted p-value.
References
Westfall, P. H. and Young, S. S. (1993) Resampling-Based Multiple Testing. Wiley.
Phipson, B. and Smyth, G. K. (2010) Permutation p-values should never be zero. Statistical Applications in Genetics and Molecular Biology 9, 39.
Examples
if (FALSE) { # gpuAvailable()
set.seed(1)
genes <- matrix(rnorm(2000 * 12), 2000, 12,
dimnames = list(paste0("g", 1:2000), NULL))
group <- rep(c("treated", "control"), each = 6)
genes[1:5, group == "treated"] <- genes[1:5, group == "treated"] + 3
res <- gpuRowTtest(genes, group, B = 5000)
head(res[order(res$p.adjusted), ])
}