#' Return predictions of a ridgereg object
#' @description \code{pred} returns the predictions of a ridgereg object.
#' @param object A ridgereg object.
#' @param ... Further arguments passed to or from other methods.
#' @param newdata A data frame with new data for predictions.
#' @return Return a named vector with predictions.
#' @examples
#' pred(ridgereg(formula = Petal.Length ~ Species, data = iris, lambda = 0))
#' @export
# pred
pred.ridgereg <- function(object, newdata = NULL, ...){
if(is.null(newdata)){
res <- c(object[[5]])
names(res) <- rownames(object[[5]])
return(res)
} else {
data <- stats::model.frame(object$formula, newdata)
y <- stats::model.response(data)
X <- stats::model.matrix(attr(data,"terms"),data)
preds <- X %*% object$beta_hat
res <- c(preds)
names(res) <- rownames(preds)
return(res)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.