\Header{5.LinearModels}{Linear Models for Microarrays}
\keyword{documentation}{5.LinearModels}
\begin{Description}\relax
This page gives an overview of the LIMMA functions available to fit linear models and to interpret the results.

The core of this package is the fitting of gene-wise linear models to microarray data.
The basic idea is to estimate log-ratios between two or more target RNA samples simultaneously.
See the \emph{\link[limma:../doc/usersguide]{LIMMA User's Guide}} for several case studies.\end{Description}
\begin{Section}{Forming the Design Matrix}
The function \code{\Link{designMatrix}} is provided to assist with creation of an appropriate design matrix for two-color microarray experiments using a common reference.
Design matrices for Affymetrix or single-color arrays can be easily created using the ordinary R command \code{\Link{model.matrix}}.
For the direct two-color designs the design matrix needs to be created by hand.\end{Section}
\begin{Section}{Fitting Models}
There are four functions in the package which fit linear models:

\describe{
\item[ \code{\Link{lmFit}} ] This is a high level function which accepts objects and provides an entry point to the following three functions.

\item[ \code{\Link{lm.series}} ] Straightforward least squares fitting of a linear model for each gene.

\item[ \code{\Link{rlm.series}} ] An alternative to \code{lm.series} using robust regression as implemented by the \code{rlm} function in the MASS package.

\item[ \code{\Link{gls.series}} ] Generalized least squares taking into account correlations between duplicate spots (i.e., replicate spots on the same array).
The functions \code{\Link{duplicateCorrelation}} or \code{\Link{dupcor.series}} are used to estimate the inter-duplicate correlation before using \code{gls.series}.
}
Each of these functions accepts essentially the same argument list and produces a fitted model object of the same form.
The first function \code{lmFit} formally produces an object of class \code{\Link{MArrayLM}}.
The other three functions are lower level functions which produce similar output but in unclassed lists.

The main argument is the \bold{design matrix} which specifies which target RNA samples were applied to each channel on each array.
There is considerable freedom to choose the design matrix - there is always more than one choice which is correct provided it is interpreted correctly.
The fitted model object consists of coefficients, standard errors and residual standard errors for each gene.

All the functions which fit linear models use \code{\Link{unwrapdups}} which provides an unified method for handling duplicate spots.\end{Section}
\begin{Section}{Making Comparisons of Interest}
Once a linear model has been fit using an appropriate design matrix, the command \code{\Link{makeContrasts}} may be used to form a contrast matrix to make comparisons of interest.
The fit and the contrast matrix are used by \code{\Link{contrasts.fit}} to compute fold changes and t-statistics for the contrasts of interest.
This is a way to compute all possible pairwise comparisons between treatments for example in an experiment which compares many treatments to a common reference.\end{Section}
\begin{Section}{Assessing Differential Expression}
After fitting a linear model, the standard errors are moderated using a simple empirical Bayes model using \code{\Link{ebayes}} or \code{\Link{eBayes}}.
A moderated t-statistic and a log-odds of differential expression is computed for each contrast for each gene.

\code{\Link{ebayes}} and \code{\Link{eBayes}} use internal functions \code{\Link{fitFDist}}, \code{\Link{tmixture.matrix}} and \code{\Link{tmixture.vector}}.

The function \code{\Link{zscoreT}} is sometimes used for computing z-score equivalents for t-statistics so as to place t-statistics with different degrees of freedom on the same scale.
\code{\Link{zscoreGamma}} is used the same way with standard deviations instead of t-statistics.
These functions are for research purposes rather than for routine use.\end{Section}
\begin{Section}{Summarizing Model Fits}
After the above steps the results may be displayed or further processed using:
\describe{
\item[ \code{\Link{toptable}} ] Presents a list of the genes most likely to be differentially expressed for a given contrast.

\item[ \code{\Link{classifyTests}} ] Uses nested F-tests to classify the genes as up, down or even over the contrasts in the linear model with special attention to genes which are significant in more than one contrast.
\code{\Link{classifyTestsT}} and \code{\Link{classifyTestsP}} are simpler methods using cutoffs for the t-statistics or p-values individually.

\item[ \code{\Link{heatdiagram}} ] Allows visual comparison of the results across many different conditions in the linear model.
Not the same as heatdiagrams produced by other packages!
This function accepts a classification matrix produced by \code{classifyTests}.

\item[ \code{\Link{vennCounts}} ] Accepts output from \code{classifyTests} and counts the number of genes in each classification.

\item[ \code{\Link{vennDiagram}} ] Accepts output from \code{classifyTests} or \code{vennCounts} and produces a Venn diagram plot.
}\end{Section}
\begin{Author}\relax
Gordon Smyth
\end{Author}
\begin{References}\relax
Smyth, G. K. (2003). Linear models and empirical Bayes methods for assessing differential expression in microarray experiments. \url{http://www.statsci.org/smyth/pubs/ebayes.pdf}

Smyth, G. K., Michaud, J., and Scott, H. (2003). The use of within-array duplicate spots for assessing differential expression in microarray experiments.
\url{http://www.statsci.org/smyth/pubs/dupcor.pdf}\end{References}

