\HeaderA{pamr.decorrelate}{A function to decorrelate (adjust) the feature matrix with respect
to some additional predictors}{pamr.decorrelate}
\begin{Description}\relax
A function to decorrelate (adjust) the feature matrix with respect
to some additional predictors
\end{Description}
\begin{Usage}
\begin{verbatim}
 pamr.decorrelate(x, adjusting.predictors, xtest=NULL, adjusting.predictors.test=NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] Matrix of training set feature values,  with
genes in the rows, samples in the columns
\item[\code{adjusting.predictors}] List of training set predictors to be used for adjustment
\item[\code{xtest}] Optional matrix of test set feature values, to be adjusted
in the same way as the training set
\item[\code{adjusting.predictors.test}] Optional list of test set predictors to be used for adjustment
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{pamr.decorrelate}
Does a least squares regression of each row of x on the adjusting
predictors, and returns the residuals. If xtest is provided, it also
returns the adjusted version of  xtest, using the
training set  least squares regression model for adjustment
\end{Details}
\begin{Value}
A list with components
\begin{ldescription}
\item[\code{x.adj}] Adjusted x matrix
\item[\code{xtest.adj}] Adjusted xtest matrix, if xtest we provided
\end{ldescription}
\end{Value}
\begin{Author}\relax
Trevor Hastie,Robert Tibshirani, Balasubramanian Narasimhan, and Gilbert Chu
\end{Author}
\begin{References}\relax
Robert Tibshirani, Trevor Hastie, Balasubramanian Narasimhan, and Gilbert Chu 
Diagnosis of multiple cancer types by shrunken centroids of gene expression 
PNAS 99: 6567-6572.   Available at www.pnas.org
\end{References}
\begin{Examples}
\begin{ExampleCode}
#generate some data
set.seed(120)

x<-matrix(rnorm(1000*20),ncol=20)
y<-c(rep(1,10),rep(2,10))
adjusting.predictors=list(pred1=rnorm(20), pred2=as.factor(sample(c(1,2),replace
=TRUE,size=20)))
xtest=matrix(rnorm(1000*10),ncol=10)
adjusting.predictors.test=list(pred1=rnorm(10), pred2=as.factor(sample(c(1,2),replace
=TRUE,size=10)))

# decorrelate training x wrt adjusting predictors

x.adj=pamr.decorrelate(x,adjusting.predictors)$x.adj
# train classifier with adjusted x

d=list(x=x.adj,y=y)
a<-pamr.train(d)

# decorrelate training and test x wrt adjusting predictors, then make
#predictions for test set

temp<-pamr.decorrelate(x,adjusting.predictors, xtest=xtest, adjusting.predictors.test=adjusting.predictors.test)

d=list(x=temp$x.adj,y=y)
a<-pamr.train(d)
aa<-pamr.predict(a,temp$xtest.adj, threshold=.5)
\end{ExampleCode}
\end{Examples}

