aboutsummaryrefslogtreecommitdiff
path: root/R/coef.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/coef.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/coef.sparsestep.R')
-rw-r--r--R/coef.sparsestep.R30
1 files changed, 30 insertions, 0 deletions
diff --git a/R/coef.sparsestep.R b/R/coef.sparsestep.R
new file mode 100644
index 0000000..3a6286c
--- /dev/null
+++ b/R/coef.sparsestep.R
@@ -0,0 +1,30 @@
+#' @title Get the coefficients of a fitted SparseStep model
+#'
+#' @description Returns the coefficients of the SparseStep model.
+#'
+#' @param obj a "sparsestep" object
+#'
+#' @return The coefficients of the SparseStep model (i.e. the betas). If the
+#' model was fitted with an intercept this will be the first value in the
+#' resulting vector.
+#'
+#' @export
+#' @aliases coef
+#'
+#' @examples
+#' x <- matrix(rnorm(100*20), 100, 20)
+#' y <- rnorm(100)
+#' fit <- sparsestep(x, y)
+#' coef(fit)
+#'
+coef.sparsestep <- function(obj, ...)
+{
+ if (obj$intercept) {
+ beta <- rbind(obj$a0, obj$beta)
+ } else {
+ beta <- obj$beta
+ }
+ nbeta <- drop0(Matrix(as.matrix(beta)))
+
+ return(nbeta)
+}