#' 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.