\Header{lm.series}{Linear Model for Series of Arrays}
\keyword{models}{lm.series}
\keyword{regression}{lm.series}
\begin{Description}\relax
Fit linear model for each gene given a series of arrays
\end{Description}
\begin{Usage}
\begin{verbatim}lm.series(M,design=NULL,ndups=1,spacing=1,weights=NULL)\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{M}] a numeric matrix containing log-ratios (M-values) for each spot on each array. Rows correspond to spots and columns to arrays.
\item[\code{design}] a numeric matrix containing the design matrix for linear model. The number of rows should agree with the number of columns of M. The number of columns will determine the number of coefficients estimated for each gene.
\item[\code{ndups}] number of duplicate spots. Each gene is printed ndups times in adjacent spots on each array.
\item[\code{spacing}] the spacing between the rows of \code{M} corresponding to duplicate spots, \code{spacing=1} for consecutive spots
\item[\code{weights}] an optional numeric matrix of the same dimension as \code{M} containing weights for each spot. If it is of different dimension to \code{M}, it will be filled out to the same size.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The linear model is fit for each gene by calling the function \code{lm.fit} or \code{lm.wfit} from the base library.
\end{Details}
\begin{Value}
A list with components
\begin{ldescription}
\item[\code{coefficients}] numeric matrix containing the estimated coefficients for each linear model. Same number of rows as \code{M}, same number of columns as \code{design}.
\item[\code{stdev.unscaled}] numeric matrix conformal with \code{coef} containing the unscaled standard deviations for the coefficient estimators. The standard errors are given by \code{stdev.unscaled * sigma}.
\item[\code{sigma}] numeric vector containing the residual standard deviation for each gene.
\item[\code{df.residual}] numeric vector giving the degrees of freedom corresponding to \code{sigma}.
\end{ldescription}
\end{Value}
\begin{Author}\relax
Gordon Smyth
\end{Author}
\begin{SeeAlso}\relax
\code{\Link{lm.fit}}.

An overview of linear model functions in limma is given by \link{5.LinearModels}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
#  Simulate gene expression data,
#  6 microarrays and 100 genes with one gene differentially expressed in first 3 arrays
M <- matrix(rnorm(100*6,sd=0.3),100,6)
M[1,1:3] <- M[1,1:3] + 2
#  Design matrix includes two treatments, one for first 3 and one for last 3 arrays
design <- cbind(First3Arrays=c(1,1,1,0,0,0),Last3Arrays=c(0,0,0,1,1,1))
fit <- lm.series(M,design=design)
eb <- ebayes(fit)
#  Large values of eb$t indicate differential expression
qqt(eb$t[,1],df=fit$df+eb$df.prior)
abline(0,1)
\end{ExampleCode}
\end{Examples}

