\HeaderA{rowFtests}{t-tests and F-tests for rows or columns of a matrix}{rowFtests}
\aliasA{colFtests}{rowFtests}{colFtests}
\aliasA{colttests}{rowFtests}{colttests}
\aliasA{fastT}{rowFtests}{fastT}
\aliasA{rowttests}{rowFtests}{rowttests}
\keyword{math}{rowFtests}
\begin{Description}\relax
t-tests and F-tests for rows or columns of a matrix
\end{Description}
\begin{Usage}
\begin{verbatim}
rowttests(x, fac, tstatOnly = FALSE) 
colttests(x, fac, tstatOnly = FALSE)
fastT(x, ig1, ig2, var.equal = TRUE)

rowFtests(x, fac, var.equal = TRUE)
colFtests(x, fac, var.equal = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] \code{exprSet} or numeric matrix. The matrix must not
contain \code{NA} values.
\item[\code{fac}] Factor; if \code{x} is an \code{exprSet}, this may also be
a character vector of length 1 with the name of a covariate
variable in \code{x}.

For the \code{row*} functions, the length of the factor must be
the same as the number of columns of \code{x}.
For the \code{col*} functions, it must be the same as the number
of rows of \code{x}.
For the \code{*ttests} function, \code{fac} must have exactly
two levels.
\item[\code{tstatOnly}] a logical variable indicating whether to calculate
parametric p-values.  If \code{FALSE}, just the t-statistics are
returned. This can be considerably faster.
\item[\code{ig1}] The indices of the columns of \code{x} that correspond
to group 1.
\item[\code{ig2}] The indices of the columns of \code{x} that correspond
to group 2. 
\item[\code{var.equal}] a logical variable indicating whether to treat the
variances in the samples as equal.  If 'TRUE', a simple F test for
the equality of means in a one-way analysis of variance is
preformed.  If 'FALSE', an approximate method of Welch (1951) is
used, which generalizes the commonly known 2-sample Welch test to
the case of arbitrarily many samples.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{rowttests} and \code{colttests} are implemented in C and
are reasonably fast and memory-efficient.
\code{fastT} is a wrapper for \code{rowttests}, useful
for some legacy code.

If \code{fac} is specified, \code{rowttests} performs for each
row of \code{x} a two-sided, two-class t-test with equal variances.
\code{fac} must be a factor of length \code{ncol(x)} with two levels,
corresponding to the two groups. The sign of the resulting t-statistic
corresponds to "group 1 minus group 2".

If \code{fac} is missing, \code{rowttests} performs for each row of
\code{x} a two-sided one-class t-test against the null hypothesis 'mean=0'.

\code{rowFtests} and \code{colFtests} are currently implemented using
matrix algebra in R. Compared to the \code{*ttests} functions,
they are slower and use more memory.

If \code{var.equal} is 'FALSE', \code{nrow(x)+1} degree of freedoms
are given, the first one is the first degree of freedom (it is the
same for each row) and the other ones are the second degree of freedom
(one for each row).
\end{Details}
\begin{Value}
For the \code{row*} and \code{col*} functions, 
a list with the test statistics, 
p-values, and degrees of freedom.
Additonally, the t-test functions return the differences
of group means.
\end{Value}
\begin{Author}\relax
Wolfgang Huber <huber@ebi.ac.uk>
\end{Author}
\begin{References}\relax
B. L. Welch (1951), On the comparison of several mean values: an
alternative approach. Biometrika, *38*, 330-336
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{mt.teststat}{mt.teststat}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
   x  = matrix(runif(970), ncol=97)
   f2 = factor(floor(runif(ncol(x))*2))
   f7 = factor(floor(runif(ncol(x))*7))

   r1 = rowttests(x)
   r2 = rowttests(x, f2)
   r7 = rowFtests(x, f7)

   ## compare with pedestrian tests
   about.equal = function(x,y,tol=1e-10)
     stopifnot(all(abs(x-y) < tol))

   s1 = t.test(x[1,])
   about.equal(s1$statistic, r1$statistic[1])
   about.equal(s1$p.value,   r1$p.value[1])

   s2 = t.test(x[1,] ~ f2, var.equal=TRUE)
   about.equal(s2$statistic, r2$statistic[1])
   about.equal(s2$p.value,   r2$p.value[1])

   dm = -diff(tapply(x[1,], f2, mean))
   about.equal(dm, r2$dm[1])

   s7 = summary(lm(x[1,]~f7))
   about.equal(s7$statistic$value, r7$statistic[1])

   ## colttests
   c2 = colttests(t(x), f2)
   stopifnot(identical(r2, c2))
\end{ExampleCode}
\end{Examples}


