R/ClassificationResult.R

Defines functions ClassificationResult

Documented in ClassificationResult

#' Create Classification result table
#' @param X covariates to be classified
#' @param coefmat estimated coefficients
#' @export
#' @return result table
#' 
ClassificationResult = function(X,coefmat){
  if(ncol(X)+1!=nrow(coefmat)){
    stop("Dimension Error")
  }
  nlam = ncol(coefmat)
  resTable = matrix(0,nrow=nlam,ncol=3)
  colnames(resTable)=c("0","1","meanprob")
  for (i in 1:nlam){
    phat_u = predict_log(X,coefmat[,i],type="response")
    classification = 1*(phat_u>0.5)
    pT = prop.table(table(classification))
    if(length(pT)==1){
      class = as.numeric(attributes(pT)$dimnames$classification)+1
      resTable[i,class] = pT
    } else{
      resTable[i,1:2] = pT
    }
    resTable[i,3] = mean(phat_u)
    print(i)
  }
  return(resTable)
}
hsong1/PUlearning documentation built on May 16, 2017, 11:27 p.m.