R/predictRegsubsets.R

Defines functions predict.regsubsets

Documented in predict.regsubsets

#' Regsubsets Predict Function
#'
#' This function is used for predicting the forward selection results on a test set. This is
#' from the ISLR textbook.
#' @param object an object with a call list
#' @param newdata data used to produce predictions
#' @param id id
#' @export


predict.regsubsets <- function(object, newdata, id){
  form <- as.formula(object$call[[2]])
  mat <- model.matrix(form, newdata)
  coefi <- coef(object, id=id)
  xvars=names(coefi)
  return(mat[,xvars]%*%coefi)
}
KThompson0308/RUtilities documentation built on Dec. 8, 2019, 8:30 a.m.