R/predict.lognet.R

Defines functions predict.lognet

Documented in predict.lognet

#' @method predict lognet
#' @export
predict.lognet=function(object,newx,s=NULL,type=c("link","response","coefficients","class","nonzero"),exact=FALSE,newoffset,...){
  type=match.arg(type)
    ### remember that although the C++ lognet makes predictions
  ### for the first class, we make predictions for the second class
  ### to avoid confusion with 0/1 responses.
  ### glmnet flipped the signs of the coefficients
nfit=NextMethod("predict")
  switch(type,
         response={
           pp=exp(-nfit)
           1/(1+pp)
         },
         class={
           cnum=ifelse(nfit>0,2,1)
           clet=object$classnames[cnum]
           if(is.matrix(cnum))clet=array(clet,dim(cnum),dimnames(cnum))
           clet
         },
         nfit
         )
}

Try the glmnet package in your browser

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

glmnet documentation built on Aug. 22, 2023, 9:12 a.m.