diff options
Diffstat (limited to 'R/predict.sparsestep.R')
| -rw-r--r-- | R/predict.sparsestep.R | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/R/predict.sparsestep.R b/R/predict.sparsestep.R index 5f8898e..8a4be1a 100644 --- a/R/predict.sparsestep.R +++ b/R/predict.sparsestep.R @@ -1,4 +1,27 @@ -predict.sparsestep <- function(object, newx) +#' @title Make predictions from a SparseStep model +#' +#' @description Predicts the outcome variable for the SparseStep model for +#' each value of lambda supplied to the model. +#' +#' @param object Fitted "sparsestep" object +#' @param newx Matrix of new values for `x` at which predictions are to be made. +#' +#' @return a matrix of numerical predictions of size nobs x nlambda +#' +#' @export +#' @aliases predict +#' +#' @examples +#' x <- matrix(rnorm(100*20), 100, 20) +#' y <- rnorm(100) +#' fit <- sparsestep(x, y) +#' yhat <- predict(fit) +#' +predict.sparsestep <- function(obj, newx) { - NULL + yhat <- newx %*% as.matrix(obj$beta) + if (obj$intercept) { + yhat <- yhat + rep(1, nrow(yhat)) %*% obj$a0 + } + return(yhat) } |
