aboutsummaryrefslogtreecommitdiff
path: root/R/predict.sparsestep.R
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2016-02-10 15:27:35 -0500
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2016-02-10 15:27:35 -0500
commit904e559845f48f38c7eb928d65876e3a064a17c7 (patch)
tree1d4153ad46cfe94bda2bd5dc3105acf67b2dc994 /R/predict.sparsestep.R
parentredefine gamma to correspond to theory (diff)
downloadsparsestep-904e559845f48f38c7eb928d65876e3a064a17c7.tar.gz
sparsestep-904e559845f48f38c7eb928d65876e3a064a17c7.zip
add documentation, unify implementations of path and fit
Diffstat (limited to 'R/predict.sparsestep.R')
-rw-r--r--R/predict.sparsestep.R27
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)
}