R/predict.robustlm.R

Defines functions predict.robustlm

Documented in predict.robustlm

#' Make predictions from a "robustlm" object.
#'
#' Returns predictions from a fitted
#' "\code{robustlm}" object.
#'
#' @param object Output from the \code{robustlm} function.
#' @param newx New data used for prediction
#' @param ... Additional arguments affecting the predictions produced.
#' 
#' @return The predicted responses.
#' 
#' @export
#'
predict.robustlm <- function(object, newx, ...) {
  if (missing(newx)) {
    stop("You need to supply a value for newx")
  }
  if (is.null(object[["alpha"]])) {
    newx <- as.matrix(newx)
    y <- newx %*% object[["beta"]]
  } else {
    newx <- as.matrix(newx)
    newx <- cbind(rep(1, nrow(newx)), newx)
    y <- newx %*% append(object[["alpha"]], object[["beta"]], after = 0)
  }
  return(y)
}

Try the robustlm package in your browser

Any scripts or data that you put into this service are public.

robustlm documentation built on March 22, 2021, 5:06 p.m.