R/predict-my-lm-ridge.R

Defines functions predict.my_lm_ridge

Documented in predict.my_lm_ridge

#' @title Predict Method for Ridge Regression Model Fits
#' @description Predicted values based on linear model object
#' @param object object of class inheriting from "my_lm_ridge"
#' @param ... further arguments passed to or from other methods
#'
#' @examples
#' data(iris)
#' ridge_fit <- my_lm_ridge(form = Sepal.Length ~ ., data = iris, lambda = 0.5)
#' predict(ridge_fit, iris)
#' @export

predict.my_lm_ridge <- function(object, ...){
  dots <- list(...)
  data <- dots[[1]]
  if(!inherits(data, "data.frame")){
    stop("Second argument must be a data frame.")
  }
  m <- model.matrix(object$form, data)
  m %*% object$coefficients
}
tqchen07/bis557 documentation built on Dec. 21, 2020, 3:06 a.m.