Description Usage Arguments Value Author(s) References See Also Examples
This function predicts the conditional class probability for the sparse (multicategory) kernel discriminant analysis (skda
).
1 | predprob(x, y, lam, xnew, method = "Bayes")
|
x |
a matrix ( n X p ) that contains predictors. |
y |
a vector that contains the categorical response coded as 1, 2, ..., K. |
lam |
a length-K vector of inverse smoothing bandwidths. |
xnew |
a matrix (with p columns) that contains predictors of new observations. |
method |
method (mle or Bayes) to be used in the KDA classifier. |
phat |
a matrix (with K columns) that contains predicted conditional class probabilities. |
L. A. Stefanski, Y. Wu, and K. White
L. A. Stefanski, Y. Wu, and K. White (2013) Variable selection in nonparametric classification via measurement error model selection likelihoods Journal of the American Statistical Association, ??, ???-???.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # a binary example
rm(list=ls())
n=200
p=20
r=0.8
x=matrix(rnorm(n*p,mean=0,sd=1),n,p)
y=rbinom(n,1,0.5)
x[,3]=x[,3]+(2*y-1)*r
x[,11]=x[,11]+(2*y-1)*r
y=y+1
ind1=which(y>1.5)
ind0=which(y<1.5)
plot(-4:4, -4:4, type = "n")
points(x[ind1, 3], x[ind1,11],col="blue")
points(x[ind0, 3], x[ind0,11],col="red")
lam=skda(x,y,3)$lam
xtest=matrix(rnorm(10*n*p,mean=0,sd=1),10*n,p)
ytest=rbinom(10*n,1,0.5)
xtest[,3]=xtest[,3]+(2*ytest-1)*r
xtest[,11]=xtest[,11]+(2*ytest-1)*r
ytest=ytest+1
ptesthat=predprob(x,y,lam, xtest)
ytesthat=apply(ptesthat, 1,which.max)
error=sum(abs(ytesthat-ytest)>0.5)
error/length(ytest)
# a three-class example
rm(list=ls())
n=200
p=20
r=2
x=matrix(rnorm(n*p,mean=0,sd=1),n,p)
y=ceiling(runif(n,0,3))
thetas=c(0, 2*pi/3, 4*pi/3)
x[,3]=x[,3]+r*cos(thetas[y])
x[,11]=x[,11]+r*sin(thetas[y])
ind1=which(y==1)
ind2=which(y==2)
ind3=which(y==3)
plot(-6:6, -6:6, type = "n")
points(x[ind1, 3], x[ind1,11],col="blue")
points(x[ind2, 3], x[ind2,11],col="red")
points(x[ind3, 3], x[ind3,11],col="black")
lam=skda(x,y,3)$lam
xtest=matrix(rnorm(10*n*p,mean=0,sd=1),10*n,p)
ytest=ceiling(runif(10*n,0,3))
xtest[,3]=xtest[,3]+r*cos(thetas[ytest])
xtest[,11]=xtest[,11]+r*sin(thetas[ytest])
ptesthat=predprob(x,y,lam, xtest)
ytesthat=apply(ptesthat, 1,which.max)
error=sum(abs(ytesthat-ytest)>0.5)
error/length(ytest)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.