% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predict.mvr.R
\name{predict.mvr}
\alias{predict.mvr}
\title{Predict Method for PLSR and PCR}
\usage{
\method{predict}{mvr}(
  object,
  newdata,
  ncomp = 1:object$ncomp,
  comps,
  type = c("response", "scores"),
  na.action = na.pass,
  ...
)
}
\arguments{
\item{object}{an \code{mvr} object.  The fitted model}

\item{newdata}{a data frame.  The new data.  If missing, the training data
is used.}

\item{ncomp, comps}{vector of positive integers.  The components to use in
the prediction.  See below.}

\item{type}{character.  Whether to predict scores or response values}

\item{na.action}{function determining what should be done with missing
values in \code{newdata}.  The default is to predict \code{NA}.  See
\code{\link{na.omit}} for alternatives.}

\item{\dots}{further arguments.  Currently not used}
}
\value{
When \code{type} is \code{"response"}, a three dimensional array of
predicted response values is returned.  The dimensions correspond to the
observations, the response variables and the model sizes, respectively.

When \code{type} is \code{"scores"}, a score matrix is returned.
}
\description{
Prediction for mvr (PCR, PLSR) models.  New responses or scores are
predicted using a fitted model and a new matrix of observations.
}
\details{
When \code{type} is \code{"response"} (default), predicted response values
are returned.  If \code{comps} is missing (or is \code{NULL}), predictions
for \code{length(ncomp)} models with \code{ncomp[1]} components,
\code{ncomp[2]} components, etc., are returned.  Otherwise, predictions for
a single model with the exact components in \code{comps} are returned.
(Note that in both cases, the intercept is always included in the
predictions.  It can be removed by subtracting the \code{Ymeans} component
of the fitted model.)

When \code{type} is \code{"scores"}, predicted score values are returned for
the components given in \code{comps}.  If \code{comps} is missing or
\code{NULL}, \code{ncomps} is used instead.

It is also possible to supply a matrix instead of a data frame as
\code{newdata}, which is then assumed to be the \eqn{X} data matrix.  Note
that the usual checks for the type of the data are then omitted.  Also note
that this is \emph{only} possible with \code{predict}; it will not work in
functions like \code{\link{predplot}}, \code{\link{RMSEP}} or
\code{\link{R2}}, because they also need the response variable of the new
data.
}
\note{
A warning message like \samp{'newdata' had 10 rows but variable(s)
found have 106 rows} means that not all variables were found in the
\code{newdata} data frame.  This (usually) happens if the formula contains
terms like \code{yarn$NIR}.  Do not use such terms; use the \code{data}
argument instead.  See \code{\link{mvr}} for details.
}
\examples{

data(yarn)
nir.mvr <- mvr(density ~ NIR, ncomp = 5, data = yarn[yarn$train,])

## Predicted responses for models with 1, 2, 3 and 4 components
pred.resp <- predict(nir.mvr, ncomp = 1:4, newdata = yarn[!yarn$train,])

## Predicted responses for a single model with components 1, 2, 3, 4
predict(nir.mvr, comps = 1:4, newdata = yarn[!yarn$train,])

## Predicted scores
predict(nir.mvr, comps = 1:3, type = "scores", newdata = yarn[!yarn$train,])

}
\seealso{
\code{\link{mvr}}, \code{\link{summary.mvr}},
\code{\link{coef.mvr}}, \code{\link{plot.mvr}}
}
\author{
Ron Wehrens and Bjørn-Helge Mevik
}
\keyword{multivariate}
\keyword{regression}
