Learn R Programming

nproc (version 2.1.5)

predict.npc: Predicting the outcome of a set of new observations using the fitted npc object.

Description

Predicting the outcome of a set of new observations using the fitted npc object.

Usage

# S3 method for npc
predict(object, newx = NULL, ...)

Arguments

object

fitted npc object using npc.

newx

a set of new observations.

...

additional arguments.

Value

A list containing the predicted label and score.

pred.label

Predicted label vector.

pred.score

Predicted score vector.

See Also

npc and nproc

Examples

Run this code
# NOT RUN {
n = 1000
x = matrix(rnorm(n*2),n,2)
c = 1+3*x[,1]
y = rbinom(n,1,1/(1+exp(-c)))
xtest = matrix(rnorm(n*2),n,2)
ctest = 1+3*xtest[,1]
ytest = rbinom(n,1,1/(1+exp(-ctest)))


# }
# NOT RUN {
##Use logistic classifier and the default type I error control with alpha=0.05
fit = npc(x, y, method = 'logistic')
pred = predict(fit,xtest)
fit.score = predict(fit,x)
accuracy = mean(pred$pred.label==ytest)
cat('Overall Accuracy: ',  accuracy,'\n')
ind0 = which(ytest==0)
ind1 = which(ytest==1)
typeI = mean(pred$pred.label[ind0]!=ytest[ind0]) #type I error on test set
cat('Type I error: ', typeI, '\n')
typeII = mean(pred$pred.label[ind1]!=ytest[ind1]) #type II error on test set
cat('Type II error: ', typeII, '\n')
# }

Run the code above in your browser using DataLab