2
0
Fork 0
CVE/CVE_C/R/predict.R

37 lines
1014 B
R
Raw Normal View History

#' Predict method for CVE Fits.
#'
#' Predict responces using reduced data with \code{\link{mars}}.
#'
#' @param object instance of class \code{cve} (result of \code{cve},
#' \code{cve.call}).
#' @param newdata Matrix of the new data to be predicted.
#' @param dim dimension of SDR space to be used for data projecition.
#' @param ... further arguments passed to \code{\link{mars}}.
#'
#' @return prediced response of data \code{newdata}.
#'
#' @seealso \code{\link{cve}}, \code{\link{cve.call}} or \pkg{\link{mars}}.
#'
#' @rdname predict.cve
#'
#' @importFrom mda mars
#' @method predict cve
#' @export
predict.cve <- function(object, newdata, dim, ...) {
if (missing(newdata)) {
stop("No data supplied.")
}
if (missing(dim)) {
stop("No dimension supplied.")
}
if (!is.matrix(newdata)) {
newdata <- matrix(newdata, nrow = 1L)
}
B <- object$res[[as.character(dim)]]$B
model <- mda::mars(object$X %*% B, object$Y)
predict(model, newdata %*% B)
}