From 904e559845f48f38c7eb928d65876e3a064a17c7 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Wed, 10 Feb 2016 15:27:35 -0500 Subject: add documentation, unify implementations of path and fit --- R/predict.sparsestep.R | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'R/predict.sparsestep.R') 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) } -- cgit v1.2.3