\HeaderA{modelMatrix}{Construct Design Matrix}{modelMatrix}
\aliasA{uniqueTargets}{modelMatrix}{uniqueTargets}
\keyword{regression}{modelMatrix}
\begin{Description}\relax
Construct design matrix from RNA target information for a two colour microarray experiment.
\end{Description}
\begin{Usage}
\begin{verbatim}
modelMatrix(targets, parameters, ref, verbose=TRUE)
uniqueTargets(targets)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{targets}] matrix or data.frame with columns \code{Cy3} and \code{Cy5} specifying which RNA was hybridized to each array
\item[\code{parameters}] matrix specifying contrasts between RNA samples which should correspond to regression coefficients.
Row names should correspond to unique RNA sample names found in \code{targets}.
\item[\code{ref}] character string giving name of one of the RNA sources to be treated as reference.
Exactly one argument of \code{parameters} or \code{ref} should be specified.
\item[\code{verbose}] logical, if \code{TRUE} then unique names found in \code{targets} will be printed to standard output
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function computes a design matrix for input to \code{lmFit} when analysing two-color microarray experiments in terms of log-ratios.

If the argument \code{ref} is used, then the experiment is treated as a one-way layout and the coefficients measure expression changes relative to the RNA source specified by \code{ref}.
The RNA source \code{ref} is often a common reference which appears on every array or is a control sample to which all the others are compared.
There is no restriction however.
One can choose \code{ref} to be any of the RNA sources appearing the \code{Cy3} or \code{Cy5} columns of \code{targets}.

If the \code{parameters} argument is set, then the columns of this matrix specify the comparisons between the RNA sources which are of interest.
This matrix must be of size n by (n-1), where n is the number of unique RNA sources found in \code{Cy3} and \code{Cy5}, and must have row names which correspond to the RNA sources.
\end{Details}
\begin{Value}
\code{modelMatrix} produces a numeric design matrix with row names as in \code{targets} and column names as in \code{parameters}.

\code{uniqueTargets} produces a character vector of unique target names from the columns \code{Cy3} and \code{Cy5} of \code{targets}.
\end{Value}
\begin{Author}\relax
Gordon Smyth
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{model.matrix}{model.matrix}} in the stats package.

An overview of linear model functions in limma is given by \LinkA{06.LinearModels}{06.LinearModels}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
targets <- cbind(Cy3=c("Ref","Control","Ref","Treatment"),Cy5=c("Control","Ref","Treatment","Ref"))
rownames(targets) <- paste("Array",1:4)

parameters <- cbind(C=c(-1,1,0),T=c(-1,0,1))
rownames(parameters) <- c("Ref","Control","Treatment")

modelMatrix(targets, parameters)
modelMatrix(targets, ref="Ref")
\end{ExampleCode}
\end{Examples}


