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

Description Usage Arguments Value See Also Examples

View source: R/predict.npc.R

Description

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

Usage

1
2
## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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')

## End(Not run)

nproc documentation built on March 26, 2020, 7:30 p.m.