R/predict.Ord.logreg.R

Defines functions predict.Ord.logreg

Documented in predict.Ord.logreg

predict.Ord.logreg <-
function(object, newdata, ...)
{
 if (class(object)!="Ord.logreg")
stop("object is not of class Ord.logreg")
 model<-object$model
 cat<-length(model)
 if (missing(newdata)) {newdata<-object$mod.dat[[cat]]}
 pred<-ncol(newdata)
 n<-nrow(newdata)
 pred.matrix<-matrix(0, nrow=n, ncol=cat)
 newXs<-newdata[,1:pred]
 for (i in cat:1)
   {
   fit<-model[[i]]
   pred.matrix[,i]<-predict.logreg(object=fit, newbin=newXs)
   }
 predicted.cat<-c()
 for (j in 1:n)
   {
   loc<-which(pred.matrix[j,]==1)
   if(length(loc)>0) { predicted.cat<-append(predicted.cat, max(loc)) }
   else { predicted.cat<-append(predicted.cat, 0) }
   }
 list(predicted.category=predicted.cat, prediction.matrix=pred.matrix)
}

Try the OrdLogReg package in your browser

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

OrdLogReg documentation built on May 29, 2017, 10:29 p.m.