aboutsummaryrefslogtreecommitdiff
path: root/R/coef.sparsestep.R
blob: 713bcb26eb0115f7ea981552480a2a15cd2cfcd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#' @title Get the coefficients of a fitted SparseStep model
#'
#' @description Returns the coefficients of the SparseStep model.
#'
#' @param object a "sparsestep" object
#' @param ... further argument are ignored
#'
#' @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(object, ...)
{
  if (object$intercept) {
    beta <- rbind(object$a0, object$beta)
  } else {
    beta <- object$beta
  }
  nbeta <- drop0(Matrix(as.matrix(beta)))

  return(nbeta)
}