R/predict.erpath.R

Defines functions predict.erpath

Documented in predict.erpath

##' @export
predict.erpath <- function(object, newx, s = NULL, type = c("link"), ...) {
  type <- match.arg(type)
  b0 <- t(as.matrix(object$b0))
  rownames(b0) <- "(Intercept)"
  nbeta <- rbind2(b0, object$beta)
  if (!is.null(s)) {
    vnames <- dimnames(nbeta)[[1]]
    dimnames(nbeta) <- list(NULL, NULL)
    lambda <- object$lambda
    lamlist <- lambda.interp(lambda, s)
    nbeta <- nbeta[, lamlist$left, drop = FALSE] %*%
      Diagonal(x = lamlist$frac) +
      nbeta[, lamlist$right, drop = FALSE] %*%
      Diagonal(x = 1-lamlist$frac)
    dimnames(nbeta) <- list(vnames, paste(seq(along = s)))
  }
  nfit <- as.matrix(as.matrix(cbind2(1, newx)) %*% nbeta)
  nfit
}

Try the gcdnet package in your browser

Any scripts or data that you put into this service are public.

gcdnet documentation built on Aug. 14, 2022, 9:05 a.m.