Revision 402b10ebd4a5fac54779c103549e34599f05e972 authored by Magnus M. Münch on 30 July 2018, 12:10:03 UTC, committed by cran-robot on 30 July 2018, 12:10:03 UTC
0 parent
Raw File
predict.gren.R
# function to make predictions with the gren object
predict.gren <- function(object, newx, unpenalized=NULL, s=NULL, 
                         type=c("groupreg", "regular"), ...) {
  if(class(object)!="gren") {
    stop("object should be a gren fit")
  } else if(!is.null(s) & !is.numeric(s)) {
    stop("s is either NULL or a numeric")
  } else if(is.null(s)) {
    s <- object$lambda
  } else if(!any(type %in% c("groupreg", "regular"))) {
    stop("type is either groupreg or regular")
  }
  
  if(is.data.frame(unpenalized)) {
    unpenalized <- model.matrix(as.formula(paste("~", paste(colnames(
      unpenalized), collapse="+"))), data=unpenalized)[, -1]
  }
  x <- cbind(unpenalized, newx)
  if(type=="groupreg") {
    prob <- predict(object$freq.model$groupreg, x, s=s, type="response")
  } else {
    prob <- predict(object$freq.model$regular, x, s=s, type="response")
  }
  return(prob)
}

back to top