library(sm)
Package 'sm', version 2.2-6.0: type help(sm) for summary information
Compute_CV=function(x,y,method,weights=NA)
{
hopt=sm.regression(x,y,method=method,display='none')$h
n=length(x)
if (is.na(weights)) weights=rep(1,n)
CV=0
for (i in 1:n)
{
CV=CV+(y[i]-sm.regression(x[-i],y[-i],h=hopt,eval.points=x[i],display='none')$estimate)^2*weights[i]
}
return(CV)
}
####
ROC=function(z,p1)
{
p=sort(unique(p1))
lp=length(p)
ROC=matrix(NA,lp,2)
for (s in 1:lp)
{
ROC[s,1]=mean(p1[z==0]>p[s])
ROC[s,2]=mean(p1[z==1]>p[s])
}
AUC=sum(ROC[-lp,2]*(ROC[-lp,1]-ROC[-1,1]))
colnames(ROC)=c("FPR","TPR")
plot(ROC,type='l',main=paste('AUC =', AUC))
return(list(ROC=ROC,AUC=AUC))
}
#######
Classif_NP=function(X,Y,X0=NA)
{
X=as.matrix(X)
n=length(Y)
V=sort(unique(Y))
n_V=length(V)
Prob=matrix(NA,n,n_V)
colnames(Prob)=V
Class=rep(NA,n)
if (!is.na(max(X0)))
{
X0=as.matrix(X0)
P0=matrix(NA,nrow(X0),n_V)
Class0=rep(NA,n)
}
for (v in 1:n_V)
{
z=as.numeric(Y==V[v])
for (i in 1:n )
{
Prob[i,v]=sm.regression(X[-i,],z[-i], eval.points=X,eval.grid=FALSE,display='none')$estimate[i]
}
if (!is.na(max(X0))) {P0[,v]=sm.regression(X,z,eval.points=X0,eval.grid=FALSE,display='none')$estimate}
}
if (n_V==2) {ROC(Y==V[2],Prob[,2])}
Class=V[apply(Prob,1,which.max)]
M_table=table(Y,Class)
if (!is.na(max(X0))) {Class0=V[apply(P0,1,which.max)]}
if (!is.na(max(X0))) {return(list(Class=Class, Prob=Prob, M_table=M_table, err=1-sum(diag(M_table))/n, Class0=Class0,Prob0=P0))}
else {return(list(Class=Class, Prob=Prob, M_table=M_table, err=1-sum(diag(M_table))/n))}
}
\[Y=10e^{-3X}+e^{-\frac{X}{2}}\epsilon, \] avec \(X \sim \mathcal{E}(1)\) et \(\epsilon \sim \mathcal{N}(0,1)\).
n=100
x=rexp(n,2)
e=rnorm(n,0,exp(-x/2))
y=10*exp(-3*x)+e
plot(function(x) 10*exp(-3*x),0,3,ylab='y')
lines(x,y,col="red",type="p")
sm.regression(x,y,h=0.01,col="blue",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=.1,col="orange",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=1,col="green",eval.points=sort(x),add=T,nbins=0)
legend(x="topright",leg=c('h=0.01','h=0.1','h=1'), col=c("blue","orange","green"),lty=1)
plot(function(x) 10*exp(-3*x),0,3)
lines(x,y,col="red",type="p")
reg3=sm.regression(x,y,method="cv",col="blue",eval.points=sort(x),add=T,nbins=0)
reg1=sm.regression(x,y,method="df",col="orange",add=T,eval.points=sort(x),nbins=0)
reg2=sm.regression(x,y,method="aicc",col="green",add=T,eval.points=sort(x),nbins=0)
legend(x="topright",leg=c('cv',"df",'aicc'), col=c("blue","orange","green"),lty=1)
plot(reg1$estimate,y[order(x)],col="orange")
lines(reg2$estimate,y[order(x)],col="green",type='p')
lines(reg3$estimate,y[order(x)],col="blue",type='p')
abline(0,1)
# Erreur quadratique
mean((reg1$estimate-y[order(x)])^2)
[1] 0.8565284
mean((reg2$estimate-y[order(x)])^2)
[1] 0.6801133
mean((reg3$estimate-y[order(x)])^2)
[1] 0.6482948
#Validation croisée
Compute_CV(x,y,'cv')/n
[1] 0.7590045
Compute_CV(x,y,'df')/n
[1] 0.9168348
Compute_CV(x,y,'aicc')/n
[1] 0.7666569
# CV avec moyenne Y
n=length(x)
CV_y=0
for (j in 1:n)
{
CV_y=CV_y+(y[j]-mean(y[-j]))^2
}
CV_y/n
[1] 9.707641
# Variance non corrigée e
var(e)*(n-1)/n
[1] 0.6912356
\[Y=7cos(7X)+10e^{-3X}+3e^{-\frac{X}{2}}\epsilon, \] avec \(X \sim \mathcal{E}(1)\) et \(\epsilon \sim \mathcal{N}(0,1)\).
n=1000
x=rexp(n,2)
e=3*rnorm(n,0,exp(-x/2))
y=7*cos(7*x)+10*exp(-3*x)+e
plot(function(x) 10*exp(-3*x)+7*cos(7*x),0,3)
lines(x,y,col="red",type="p")
sm.regression(x,y,h=0.01,col="blue",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=.1,col="orange",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=1,col="green",eval.points=sort(x),add=T,nbins=0)
legend(x="topright",leg=c('h=0.01','h=0.1','h=1'), col=c("blue","orange","green"),lty=1)
plot(function(x) 10*exp(-3*x)+7*cos(7*x),0,3)
lines(x,y,col="red",type="p")
plot(function(x) 10*exp(-3*x)+7*cos(7*x),0,3)
lines(x,y,col="red",type="p")
reg3=sm.regression(x,y,method="cv",col="blue", eval.points=sort(x),add=T,nbins=0)
legend(x="topright",leg=c('cv',"df",'aicc'), col=c("blue","orange","green"),lty=1)
reg1=sm.regression(x,y,method="df",col="orange",eval.points=sort(x),add=T,nbins=0)
reg2=sm.regression(x,y,method="aicc",col="green", eval.points=sort(x),add=T,nbins=0)
plot(reg1$estimate,y[order(x)],col="orange")
lines(reg2$estimate,y[order(x)],col="green",type='p')
lines(reg3$estimate,y[order(x)],col="blue",type='p')
abline(0,1)
# Erreur quadratique
mean((reg1$estimate-y[order(x)])^2)
[1] 19.59876
mean((reg2$estimate-y[order(x)])^2)
[1] 6.669095
mean((reg3$estimate-y[order(x)])^2)
[1] 6.658894
#Validation croisée
Compute_CV(x,y,'cv')/n
[1] 6.859725
Compute_CV(x,y,'df')/n
[1] 19.68275
Compute_CV(x,y,'aicc')/n
[1] 8.735893
# CV avec moyenne Y
n=length(x)
CV_y=0
for (j in 1:n)
{
CV_y=CV_y+(y[j]-mean(y[-j]))^2
}
CV_y/n
[1] 55.15097
# Variance non corrigée e
var(e)*(n-1)/n
[1] 6.679332
# load data
library(MASS)
Attachement du package : 'MASS'
L'objet suivant est masqué depuis 'package:sm':
muscle
data(mcycle)
head(mcycle)
times accel
1 2.4 0.0
2 2.6 -1.3
3 3.2 -2.7
4 3.6 0.0
5 4.0 -2.7
6 6.2 -2.7
x=mcycle$times
y=mcycle$accel
n=length(x)
# plot data
plot(x, y, xlab = "Time (ms)", ylab = "Acceleration (g)")
sm.regression(x,y,h=0.1,col="blue",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=1,col="orange",eval.points=sort(x),add=T,nbins=0)
sm.regression(x,y,h=10,col="green",eval.points=sort(x),add=T,nbins=0)
legend(x="topright",leg=c('h=0.1','h=1','h=10'), col=c("blue","orange","green"),lty=1)
plot(x,y,col="red",type="p")
reg3=sm.regression(x,y,method="cv",col="blue", eval.points=sort(x),add=T,nbins=0)
legend(x="topright",leg=c('cv',"df",'aicc'), col=c("blue","orange","green"),lty=1)
reg1=sm.regression(x,y,method="df",col="orange",eval.points=sort(x),add=T,nbins=0)
reg2=sm.regression(x,y,method="aicc",col="green", eval.points=sort(x),add=T,nbins=0)
plot(reg1$estimate,y[order(x)],col="orange")
lines(reg2$estimate,y[order(x)],col="green",type='p')
lines(reg3$estimate,y[order(x)],col="blue",type='p')
abline(0,1)
# Erreur quadratique
mean((reg1$estimate-y[order(x)])^2)
[1] 987.5993
mean((reg2$estimate-y[order(x)])^2)
[1] 472.0266
mean((reg3$estimate-y[order(x)])^2)
[1] 459.8602
#Validation croisée
Compute_CV(x,y,'cv')/n
[1] 570.7888
Compute_CV(x,y,'df')/n
[1] 1027.242
Compute_CV(x,y,'aicc')/n
[1] 742.0577
# CV avec moyenne Y
n=length(x)
CV_y=0
for (j in 1:n)
{
CV_y=CV_y+(y[j]-mean(y[-j]))^2
}
CV_y/n
[1] 2352.71
rmixing2=function(n,alpha,l0,l1,p0,p1)
# Generate data from a mixing model
{
z=rbinom(n,1,alpha)
f1=eval(parse(text=paste('r',l1,'(',paste(c(n,p1),collapse=','),')',sep='')))
f0=eval(parse(text=paste('r',l0,'(',paste(c(n,p0),collapse=','),')',sep='')))
x=z*f1+(1-z)*f0
return(list(x=x,z=z))
}
dmixing2=function(t,alpha,l0,l1,p0,p1)
# draw the density of the mixing model
{
mix=alpha*eval(parse(text=paste('d',l1,'(t,',paste(p1,collapse=','),')',sep='')))+(1-alpha)*eval(parse(text=paste('d',l0,'(t,',paste(p0,collapse=','),')',sep='')))
p1_t=alpha*eval(parse(text=paste('d',l1,'(t,',paste(p1,collapse=','),')',sep='')))/mix
p0_t=(1-alpha)*eval(parse(text=paste('d',l0,'(t,',paste(p0,collapse=','),')',sep='')))/mix
return(list(mix=mix,p0_t=p0_t,p1_t=p1_t))
}
#Example
n=300
alpha=0.3
l0='norm'
p0=c(4,1)
l1='norm'
p1=c(0,2)
s=seq(-10,10,0.001)
r=rmixing2(n,alpha,l0,l1,p0,p1)
x=r$x
z=r$z
p0_x=dmixing2(x,alpha,l0,l1,p0,p1)$p0_t
p1_x=dmixing2(x,alpha,l0,l1,p0,p1)$p1_t
u=sort(x)
plot(u,p0_x[order(x)],ylab='p0_x',type='l')
plot(u,p1_x[order(x)],ylab='p1_x',type='l')
Classif_NP(x,z)
$Class
[1] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0
[38] 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0
[75] 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 0 1 0 1
[112] 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0
[149] 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0 1
[186] 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0
[223] 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
[260] 1 1 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0
[297] 0 0 0 0
$Prob
0 1
[1,] 6.506685e-01 0.3493314699
[2,] 8.498042e-01 0.1501957631
[3,] 7.820879e-01 0.2179120700
[4,] 8.780196e-01 0.1219803792
[5,] 1.017022e+00 -0.0170218881
[6,] 9.992254e-01 0.0007745972
[7,] 9.904279e-01 0.0095720615
[8,] 9.103414e-01 0.0896585706
[9,] 8.953635e-01 0.1046365099
[10,] 3.683113e-01 0.6316887372
[11,] 1.008552e+00 -0.0085516655
[12,] 1.013576e+00 -0.0135762410
[13,] 9.284305e-01 0.0715695077
[14,] 9.559611e-01 0.0440389408
[15,] 2.560918e-01 0.7439081778
[16,] 8.012115e-01 0.1987885288
[17,] 6.806358e-01 0.3193641732
[18,] 7.564351e-03 0.9924356487
[19,] 5.028156e-01 0.4971843567
[20,] 9.257928e-01 0.0742072463
[21,] -3.308097e-04 1.0003308097
[22,] 7.879522e-01 0.2120478484
[23,] 2.452091e-02 0.9754790948
[24,] 9.044311e-01 0.0955688691
[25,] 9.897062e-01 0.0102938334
[26,] 4.484085e-02 0.9551591489
[27,] -7.591556e-04 1.0007591556
[28,] 9.868508e-01 0.0131491841
[29,] 7.678941e-01 0.2321058861
[30,] -1.254958e-03 1.0012549579
[31,] 1.004004e+00 -0.0040040624
[32,] 8.490073e-01 0.1509927120
[33,] 9.410170e-01 0.0589829936
[34,] 9.507190e-01 0.0492809644
[35,] -3.331907e-04 1.0003331907
[36,] 1.020100e+00 -0.0201001932
[37,] 9.920041e-01 0.0079958529
[38,] 8.793932e-01 0.1206068218
[39,] 9.713802e-01 0.0286198220
[40,] 1.011233e+00 -0.0112334929
[41,] 1.017781e+00 -0.0177807943
[42,] 9.369939e-01 0.0630060882
[43,] -1.538454e-03 1.0015384539
[44,] 1.020779e+00 -0.0207793441
[45,] 8.791011e-01 0.1208989339
[46,] 8.495930e-01 0.1504070146
[47,] 9.010542e-01 0.0989457940
[48,] 1.021153e+00 -0.0211530701
[49,] 6.803401e-01 0.3196599287
[50,] 7.883261e-01 0.2116738990
[51,] 9.660798e-01 0.0339202439
[52,] 7.080938e-01 0.2919062411
[53,] 8.527972e-02 0.9147202845
[54,] 3.593566e-02 0.9640643367
[55,] 1.027574e-02 0.9897242648
[56,] 9.722493e-01 0.0277507123
[57,] 8.943514e-01 0.1056485665
[58,] 1.136043e-03 0.9988639568
[59,] 7.683573e-02 0.9231642671
[60,] 9.364882e-01 0.0635118036
[61,] 9.632959e-01 0.0367041417
[62,] 9.561126e-01 0.0438873588
[63,] 1.000680e-01 0.8999319713
[64,] 2.727849e-03 0.9972721512
[65,] 9.395342e-01 0.0604658271
[66,] 1.015115e+00 -0.0151146626
[67,] 5.038239e-01 0.4961760913
[68,] 3.572139e-01 0.6427860906
[69,] 6.569553e-01 0.3430446516
[70,] 1.020418e+00 -0.0204181563
[71,] 6.538958e-01 0.3461041578
[72,] -6.569958e-05 1.0000656996
[73,] 9.847921e-01 0.0152078659
[74,] 9.631340e-01 0.0368660268
[75,] 1.006022e+00 -0.0060224989
[76,] 9.441988e-01 0.0558012073
[77,] 1.009009e+00 -0.0090094480
[78,] 9.237122e-01 0.0762878294
[79,] 9.197884e-01 0.0802116048
[80,] 1.295659e-01 0.8704340815
[81,] 4.111347e-01 0.5888653188
[82,] 9.355863e-01 0.0644136552
[83,] 1.006357e+00 -0.0063574578
[84,] 8.448510e-01 0.1551490232
[85,] 2.957737e-02 0.9704226297
[86,] 1.017181e+00 -0.0171808598
[87,] 2.374880e-01 0.7625119767
[88,] 9.607027e-01 0.0392972687
[89,] 9.662975e-01 0.0337024876
[90,] 1.014873e+00 -0.0148727804
[91,] -3.359135e-11 1.0000000000
[92,] 9.962749e-01 0.0037250673
[93,] 2.074056e-01 0.7925943952
[94,] -1.816182e-03 1.0018161815
[95,] 8.555064e-02 0.9144493566
[96,] 6.070888e-03 0.9939291123
[97,] 9.947017e-01 0.0052983046
[98,] 8.721036e-01 0.1278964440
[99,] 4.006894e-01 0.5993105601
[100,] 7.743626e-01 0.2256373614
[101,] -1.787052e-03 1.0017870519
[102,] 1.021197e+00 -0.0211973126
[103,] 9.514799e-01 0.0485201349
[104,] 1.013632e+00 -0.0136324738
[105,] 9.639818e-01 0.0360181689
[106,] 1.836597e-01 0.8163403491
[107,] 9.581231e-01 0.0418768569
[108,] 9.976067e-01 0.0023932751
[109,] 1.591503e-01 0.8408496637
[110,] 9.823994e-01 0.0176006070
[111,] 1.346542e-01 0.8653458386
[112,] 3.016989e-01 0.6983010940
[113,] -5.649044e-07 1.0000005649
[114,] 8.650353e-01 0.1349647309
[115,] 9.727650e-01 0.0272349598
[116,] 9.747026e-01 0.0252973788
[117,] 3.632657e-01 0.6367342683
[118,] 9.833985e-01 0.0166014888
[119,] 9.486617e-01 0.0513383046
[120,] 7.944808e-01 0.2055192368
[121,] 8.985263e-01 0.1014736721
[122,] 7.973333e-02 0.9202666712
[123,] 9.402373e-01 0.0597627448
[124,] 7.021763e-01 0.2978236875
[125,] 7.068792e-01 0.2931208421
[126,] 1.008849e+00 -0.0088487868
[127,] 8.736565e-01 0.1263435198
[128,] 9.299148e-01 0.0700851809
[129,] 9.950600e-01 0.0049400104
[130,] 9.408284e-01 0.0591716031
[131,] 1.020913e+00 -0.0209126999
[132,] 9.824134e-01 0.0175866333
[133,] 1.004836e+00 -0.0048363418
[134,] 8.911798e-01 0.1088202156
[135,] 7.772746e-01 0.2227253657
[136,] 9.034372e-01 0.0965628150
[137,] 9.922891e-01 0.0077109035
[138,] 9.881875e-02 0.9011812508
[139,] 5.910691e-01 0.4089309159
[140,] 8.936782e-01 0.1063217717
[141,] 3.408711e-02 0.9659128907
[142,] 7.791302e-02 0.9220869760
[143,] 9.899246e-01 0.0100754246
[144,] 1.011252e+00 -0.0112519099
[145,] 9.415938e-01 0.0584061853
[146,] 6.718959e-01 0.3281041037
[147,] 9.622778e-01 0.0377221929
[148,] 8.054999e-01 0.1945000830
[149,] 6.631791e-01 0.3368208964
[150,] 9.569807e-01 0.0430192753
[151,] -1.758459e-03 1.0017584591
[152,] 1.007558e+00 -0.0075579298
[153,] 9.217945e-01 0.0782055068
[154,] 9.084845e-01 0.0915155221
[155,] 1.004781e+00 -0.0047810364
[156,] 1.005380e+00 -0.0053797016
[157,] 9.569656e-01 0.0430343803
[158,] 7.617017e-01 0.2382982506
[159,] 7.022851e-01 0.2977149086
[160,] 9.066130e-01 0.0933869572
[161,] 1.002797e+00 -0.0027974472
[162,] 9.888115e-01 0.0111885029
[163,] 7.432365e-01 0.2567634843
[164,] 9.642734e-01 0.0357265714
[165,] -1.325481e-03 1.0013254806
[166,] 7.499308e-01 0.2500691935
[167,] 1.020528e+00 -0.0205282344
[168,] 9.684764e-01 0.0315235890
[169,] 1.006015e+00 -0.0060149280
[170,] 7.495422e-01 0.2504578050
[171,] 9.120490e-02 0.9087950997
[172,] 1.009109e+00 -0.0091087643
[173,] 3.829067e-01 0.6170933326
[174,] 2.507221e-02 0.9749277900
[175,] 1.012662e+00 -0.0126621596
[176,] 8.772475e-01 0.1227525020
[177,] 6.797935e-01 0.3202065427
[178,] 2.164668e-01 0.7835331547
[179,] 7.910738e-01 0.2089261941
[180,] 1.016222e+00 -0.0162215596
[181,] 9.787742e-01 0.0212258321
[182,] 9.789522e-01 0.0210477646
[183,] 7.854374e-01 0.2145625837
[184,] 1.002061e+00 -0.0020613440
[185,] 9.447806e-05 0.9999055219
[186,] 9.842409e-01 0.0157590552
[187,] 9.812468e-01 0.0187531565
[188,] 8.477265e-01 0.1522734666
[189,] 1.015177e+00 -0.0151768243
[190,] 8.653719e-01 0.1346281013
[191,] 2.223983e-01 0.7776016786
[192,] 1.020376e+00 -0.0203761018
[193,] 9.489728e-01 0.0510272246
[194,] 1.020686e+00 -0.0206858691
[195,] 8.644354e-01 0.1355646129
[196,] 9.303782e-01 0.0696217880
[197,] 8.959641e-01 0.1040358593
[198,] 9.191024e-01 0.0808975651
[199,] 1.109561e-02 0.9889043851
[200,] 4.509748e-01 0.5490252356
[201,] 4.943298e-03 0.9950567015
[202,] -9.646893e-05 1.0000964689
[203,] 7.603478e-01 0.2396521831
[204,] 9.650888e-01 0.0349112084
[205,] 1.004292e+00 -0.0042919005
[206,] 7.606192e-01 0.2393808161
[207,] 9.895512e-01 0.0104488403
[208,] 9.678834e-01 0.0321166454
[209,] 9.724497e-01 0.0275502743
[210,] -1.709129e-03 1.0017091290
[211,] 1.012050e+00 -0.0120495531
[212,] 9.697155e-01 0.0302845396
[213,] 9.218976e-01 0.0781023929
[214,] 4.968097e-01 0.5031902692
[215,] 9.335825e-01 0.0664175150
[216,] 1.000706e+00 -0.0007058693
[217,] 8.755974e-01 0.1244026082
[218,] 9.857173e-01 0.0142827287
[219,] 9.784528e-01 0.0215471920
[220,] 8.516017e-01 0.1483983177
[221,] 9.922235e-01 0.0077764762
[222,] 8.068491e-01 0.1931509281
[223,] 1.012217e+00 -0.0122170850
[224,] 5.864272e-01 0.4135727704
[225,] -2.881491e-05 1.0000288149
[226,] 9.766877e-02 0.9023312348
[227,] 9.051494e-01 0.0948505680
[228,] 5.574891e-02 0.9442510907
[229,] 9.166893e-01 0.0833106577
[230,] 9.104747e-01 0.0895252537
[231,] 8.429464e-01 0.1570535617
[232,] 9.906111e-01 0.0093889080
[233,] 9.422003e-01 0.0577996552
[234,] 8.829065e-02 0.9117093513
[235,] 9.992365e-01 0.0007635300
[236,] -1.836340e-03 1.0018363405
[237,] -1.925388e-03 1.0019253877
[238,] 8.279621e-01 0.1720379448
[239,] 7.141184e-01 0.2858816104
[240,] 7.201431e-01 0.2798568963
[241,] 9.264211e-01 0.0735789378
[242,] 1.004549e+00 -0.0045491366
[243,] 5.992433e-01 0.4007567350
[244,] -1.792635e-03 1.0017926346
[245,] 7.107754e-01 0.2892246013
[246,] 9.734445e-01 0.0265554990
[247,] 6.057024e-01 0.3942975516
[248,] 9.580852e-01 0.0419148369
[249,] 9.667511e-01 0.0332488526
[250,] 7.304381e-01 0.2695618944
[251,] 9.272375e-01 0.0727625025
[252,] 9.782870e-01 0.0217129540
[253,] 9.724934e-01 0.0275066325
[254,] 7.927734e-01 0.2072266067
[255,] 9.578864e-01 0.0421135815
[256,] 7.345013e-01 0.2654986953
[257,] -1.658707e-06 1.0000016587
[258,] 1.001526e+00 -0.0015257586
[259,] 9.592286e-01 0.0407713571
[260,] 1.294822e-01 0.8705178421
[261,] -1.472143e-03 1.0014721429
[262,] 8.768050e-01 0.1231949516
[263,] 6.339752e-01 0.3660248392
[264,] 3.782572e-01 0.6217428460
[265,] 5.499765e-01 0.4500234633
[266,] 8.305223e-01 0.1694776847
[267,] 2.962448e-01 0.7037552150
[268,] 8.154693e-03 0.9918453070
[269,] 9.583609e-01 0.0416390825
[270,] 9.596952e-01 0.0403047846
[271,] 9.381924e-01 0.0618075670
[272,] 6.403117e-01 0.3596882644
[273,] 8.998175e-01 0.1001825373
[274,] 9.483960e-01 0.0516039747
[275,] 1.006595e+00 -0.0065949830
[276,] 3.204119e-01 0.6795881225
[277,] 9.741704e-01 0.0258296105
[278,] 2.980304e-02 0.9701969582
[279,] -1.454914e-03 1.0014549138
[280,] 9.569527e-01 0.0430472834
[281,] 9.440316e-01 0.0559684254
[282,] 8.803913e-01 0.1196087350
[283,] 9.772700e-01 0.0227299689
[284,] 9.863835e-01 0.0136164925
[285,] 8.901199e-01 0.1098801130
[286,] -1.918450e-04 1.0001918450
[287,] 1.018433e+00 -0.0184329905
[288,] 7.678247e-01 0.2321752628
[289,] -1.767751e-03 1.0017677510
[290,] 9.866615e-01 0.0133385336
[291,] 4.108159e-01 0.5891841361
[292,] 8.214711e-01 0.1785288913
[293,] 8.109468e-01 0.1890532178
[294,] 9.982649e-01 0.0017351355
[295,] 9.825780e-01 0.0174220257
[296,] 7.930339e-01 0.2069660530
[297,] 5.900179e-01 0.4099821054
[298,] 9.665307e-01 0.0334692891
[299,] 1.018018e+00 -0.0180175429
[300,] 1.010246e+00 -0.0102460426
$M_table
Class
Y 0 1
0 213 3
1 14 70
$err
[1] 0.05666667
ROC(z,p1_x)
$ROC
FPR TPR
[1,] 0.995370370 1.00000000
[2,] 0.990740741 1.00000000
[3,] 0.986111111 1.00000000
[4,] 0.981481481 1.00000000
[5,] 0.976851852 1.00000000
[6,] 0.972222222 1.00000000
[7,] 0.967592593 1.00000000
[8,] 0.962962963 1.00000000
[9,] 0.958333333 1.00000000
[10,] 0.953703704 1.00000000
[11,] 0.949074074 1.00000000
[12,] 0.944444444 1.00000000
[13,] 0.939814815 1.00000000
[14,] 0.935185185 1.00000000
[15,] 0.930555556 1.00000000
[16,] 0.925925926 1.00000000
[17,] 0.921296296 1.00000000
[18,] 0.916666667 1.00000000
[19,] 0.912037037 1.00000000
[20,] 0.907407407 1.00000000
[21,] 0.902777778 1.00000000
[22,] 0.898148148 1.00000000
[23,] 0.893518519 1.00000000
[24,] 0.888888889 1.00000000
[25,] 0.884259259 1.00000000
[26,] 0.879629630 1.00000000
[27,] 0.875000000 1.00000000
[28,] 0.870370370 1.00000000
[29,] 0.865740741 1.00000000
[30,] 0.861111111 1.00000000
[31,] 0.856481481 1.00000000
[32,] 0.851851852 1.00000000
[33,] 0.847222222 1.00000000
[34,] 0.842592593 1.00000000
[35,] 0.837962963 1.00000000
[36,] 0.833333333 1.00000000
[37,] 0.828703704 1.00000000
[38,] 0.824074074 1.00000000
[39,] 0.819444444 1.00000000
[40,] 0.814814815 1.00000000
[41,] 0.810185185 1.00000000
[42,] 0.805555556 1.00000000
[43,] 0.800925926 1.00000000
[44,] 0.796296296 1.00000000
[45,] 0.791666667 1.00000000
[46,] 0.787037037 1.00000000
[47,] 0.782407407 1.00000000
[48,] 0.777777778 1.00000000
[49,] 0.773148148 1.00000000
[50,] 0.768518519 1.00000000
[51,] 0.763888889 1.00000000
[52,] 0.759259259 1.00000000
[53,] 0.754629630 1.00000000
[54,] 0.750000000 1.00000000
[55,] 0.745370370 1.00000000
[56,] 0.740740741 1.00000000
[57,] 0.736111111 1.00000000
[58,] 0.731481481 1.00000000
[59,] 0.726851852 1.00000000
[60,] 0.722222222 1.00000000
[61,] 0.717592593 1.00000000
[62,] 0.712962963 1.00000000
[63,] 0.708333333 1.00000000
[64,] 0.703703704 1.00000000
[65,] 0.699074074 1.00000000
[66,] 0.694444444 1.00000000
[67,] 0.689814815 1.00000000
[68,] 0.685185185 1.00000000
[69,] 0.680555556 1.00000000
[70,] 0.675925926 1.00000000
[71,] 0.671296296 1.00000000
[72,] 0.666666667 1.00000000
[73,] 0.662037037 1.00000000
[74,] 0.657407407 1.00000000
[75,] 0.652777778 1.00000000
[76,] 0.648148148 1.00000000
[77,] 0.643518519 1.00000000
[78,] 0.638888889 1.00000000
[79,] 0.634259259 1.00000000
[80,] 0.629629630 1.00000000
[81,] 0.625000000 1.00000000
[82,] 0.620370370 1.00000000
[83,] 0.615740741 1.00000000
[84,] 0.611111111 1.00000000
[85,] 0.606481481 1.00000000
[86,] 0.601851852 1.00000000
[87,] 0.597222222 1.00000000
[88,] 0.592592593 1.00000000
[89,] 0.587962963 1.00000000
[90,] 0.583333333 1.00000000
[91,] 0.578703704 1.00000000
[92,] 0.574074074 1.00000000
[93,] 0.569444444 1.00000000
[94,] 0.564814815 1.00000000
[95,] 0.560185185 1.00000000
[96,] 0.555555556 1.00000000
[97,] 0.550925926 1.00000000
[98,] 0.546296296 1.00000000
[99,] 0.541666667 1.00000000
[100,] 0.537037037 1.00000000
[101,] 0.532407407 1.00000000
[102,] 0.527777778 1.00000000
[103,] 0.523148148 1.00000000
[104,] 0.518518519 1.00000000
[105,] 0.513888889 1.00000000
[106,] 0.509259259 1.00000000
[107,] 0.504629630 1.00000000
[108,] 0.500000000 1.00000000
[109,] 0.495370370 1.00000000
[110,] 0.490740741 1.00000000
[111,] 0.486111111 1.00000000
[112,] 0.481481481 1.00000000
[113,] 0.476851852 1.00000000
[114,] 0.472222222 1.00000000
[115,] 0.467592593 1.00000000
[116,] 0.462962963 1.00000000
[117,] 0.458333333 1.00000000
[118,] 0.453703704 1.00000000
[119,] 0.449074074 1.00000000
[120,] 0.444444444 1.00000000
[121,] 0.439814815 1.00000000
[122,] 0.435185185 1.00000000
[123,] 0.430555556 1.00000000
[124,] 0.425925926 1.00000000
[125,] 0.421296296 1.00000000
[126,] 0.416666667 1.00000000
[127,] 0.412037037 1.00000000
[128,] 0.407407407 1.00000000
[129,] 0.402777778 1.00000000
[130,] 0.398148148 1.00000000
[131,] 0.393518519 1.00000000
[132,] 0.388888889 1.00000000
[133,] 0.388888889 0.98809524
[134,] 0.388888889 0.97619048
[135,] 0.384259259 0.97619048
[136,] 0.379629630 0.97619048
[137,] 0.375000000 0.97619048
[138,] 0.370370370 0.97619048
[139,] 0.365740741 0.97619048
[140,] 0.365740741 0.96428571
[141,] 0.361111111 0.96428571
[142,] 0.356481481 0.96428571
[143,] 0.351851852 0.96428571
[144,] 0.347222222 0.96428571
[145,] 0.342592593 0.96428571
[146,] 0.337962963 0.96428571
[147,] 0.333333333 0.96428571
[148,] 0.328703704 0.96428571
[149,] 0.324074074 0.96428571
[150,] 0.319444444 0.96428571
[151,] 0.314814815 0.96428571
[152,] 0.310185185 0.96428571
[153,] 0.305555556 0.96428571
[154,] 0.300925926 0.96428571
[155,] 0.296296296 0.96428571
[156,] 0.291666667 0.96428571
[157,] 0.287037037 0.96428571
[158,] 0.282407407 0.96428571
[159,] 0.277777778 0.96428571
[160,] 0.273148148 0.96428571
[161,] 0.268518519 0.96428571
[162,] 0.263888889 0.96428571
[163,] 0.259259259 0.96428571
[164,] 0.254629630 0.96428571
[165,] 0.250000000 0.96428571
[166,] 0.245370370 0.96428571
[167,] 0.240740741 0.96428571
[168,] 0.236111111 0.96428571
[169,] 0.231481481 0.96428571
[170,] 0.226851852 0.96428571
[171,] 0.222222222 0.96428571
[172,] 0.217592593 0.96428571
[173,] 0.212962963 0.96428571
[174,] 0.212962963 0.95238095
[175,] 0.212962963 0.94047619
[176,] 0.208333333 0.94047619
[177,] 0.203703704 0.94047619
[178,] 0.199074074 0.94047619
[179,] 0.194444444 0.94047619
[180,] 0.189814815 0.94047619
[181,] 0.185185185 0.94047619
[182,] 0.180555556 0.94047619
[183,] 0.175925926 0.94047619
[184,] 0.171296296 0.94047619
[185,] 0.166666667 0.94047619
[186,] 0.162037037 0.94047619
[187,] 0.157407407 0.94047619
[188,] 0.152777778 0.94047619
[189,] 0.148148148 0.94047619
[190,] 0.143518519 0.94047619
[191,] 0.138888889 0.94047619
[192,] 0.134259259 0.94047619
[193,] 0.129629630 0.94047619
[194,] 0.125000000 0.94047619
[195,] 0.120370370 0.94047619
[196,] 0.115740741 0.94047619
[197,] 0.115740741 0.92857143
[198,] 0.111111111 0.92857143
[199,] 0.106481481 0.92857143
[200,] 0.101851852 0.92857143
[201,] 0.097222222 0.92857143
[202,] 0.097222222 0.91666667
[203,] 0.092592593 0.91666667
[204,] 0.087962963 0.91666667
[205,] 0.087962963 0.90476190
[206,] 0.083333333 0.90476190
[207,] 0.078703704 0.90476190
[208,] 0.074074074 0.90476190
[209,] 0.069444444 0.90476190
[210,] 0.064814815 0.90476190
[211,] 0.060185185 0.90476190
[212,] 0.060185185 0.89285714
[213,] 0.060185185 0.88095238
[214,] 0.055555556 0.88095238
[215,] 0.050925926 0.88095238
[216,] 0.050925926 0.86904762
[217,] 0.046296296 0.86904762
[218,] 0.041666667 0.86904762
[219,] 0.037037037 0.86904762
[220,] 0.037037037 0.85714286
[221,] 0.032407407 0.85714286
[222,] 0.027777778 0.85714286
[223,] 0.027777778 0.84523810
[224,] 0.027777778 0.83333333
[225,] 0.023148148 0.83333333
[226,] 0.018518519 0.83333333
[227,] 0.013888889 0.83333333
[228,] 0.009259259 0.83333333
[229,] 0.004629630 0.83333333
[230,] 0.004629630 0.82142857
[231,] 0.004629630 0.80952381
[232,] 0.004629630 0.79761905
[233,] 0.000000000 0.79761905
[234,] 0.000000000 0.78571429
[235,] 0.000000000 0.77380952
[236,] 0.000000000 0.76190476
[237,] 0.000000000 0.75000000
[238,] 0.000000000 0.73809524
[239,] 0.000000000 0.72619048
[240,] 0.000000000 0.71428571
[241,] 0.000000000 0.70238095
[242,] 0.000000000 0.69047619
[243,] 0.000000000 0.67857143
[244,] 0.000000000 0.66666667
[245,] 0.000000000 0.65476190
[246,] 0.000000000 0.64285714
[247,] 0.000000000 0.63095238
[248,] 0.000000000 0.61904762
[249,] 0.000000000 0.60714286
[250,] 0.000000000 0.59523810
[251,] 0.000000000 0.58333333
[252,] 0.000000000 0.57142857
[253,] 0.000000000 0.55952381
[254,] 0.000000000 0.54761905
[255,] 0.000000000 0.53571429
[256,] 0.000000000 0.52380952
[257,] 0.000000000 0.51190476
[258,] 0.000000000 0.50000000
[259,] 0.000000000 0.48809524
[260,] 0.000000000 0.47619048
[261,] 0.000000000 0.46428571
[262,] 0.000000000 0.45238095
[263,] 0.000000000 0.44047619
[264,] 0.000000000 0.42857143
[265,] 0.000000000 0.41666667
[266,] 0.000000000 0.40476190
[267,] 0.000000000 0.39285714
[268,] 0.000000000 0.38095238
[269,] 0.000000000 0.36904762
[270,] 0.000000000 0.35714286
[271,] 0.000000000 0.34523810
[272,] 0.000000000 0.33333333
[273,] 0.000000000 0.32142857
[274,] 0.000000000 0.30952381
[275,] 0.000000000 0.29761905
[276,] 0.000000000 0.28571429
[277,] 0.000000000 0.27380952
[278,] 0.000000000 0.26190476
[279,] 0.000000000 0.25000000
[280,] 0.000000000 0.23809524
[281,] 0.000000000 0.22619048
[282,] 0.000000000 0.21428571
[283,] 0.000000000 0.20238095
[284,] 0.000000000 0.19047619
[285,] 0.000000000 0.17857143
[286,] 0.000000000 0.16666667
[287,] 0.000000000 0.15476190
[288,] 0.000000000 0.14285714
[289,] 0.000000000 0.13095238
[290,] 0.000000000 0.11904762
[291,] 0.000000000 0.10714286
[292,] 0.000000000 0.09523810
[293,] 0.000000000 0.08333333
[294,] 0.000000000 0.07142857
[295,] 0.000000000 0.05952381
[296,] 0.000000000 0.04761905
[297,] 0.000000000 0.03571429
[298,] 0.000000000 0.02380952
[299,] 0.000000000 0.01190476
[300,] 0.000000000 0.00000000
$AUC
[1] 0.9697972
Class_Bayes=as.numeric(p1_x>0.5)
(M_table=table(z,Class_Bayes))
Class_Bayes
z 0 1
0 214 2
1 14 70
(err=1-sum(diag(M_table))/n)
[1] 0.05333333
load('Dopage.RData')
x=hema
z=test
Classif_NP(x,z)
$Class
[1] "negatif" "positif" "positif" "negatif" "positif" "positif" "negatif"
[8] "positif" "negatif" "negatif" "negatif" "positif" "negatif" "negatif"
[15] "negatif" "negatif" "negatif" "negatif" "negatif" "negatif" "negatif"
[22] "negatif" "negatif" "negatif" "positif" "positif" "negatif" "negatif"
[29] "positif" "positif" "negatif" "negatif" "negatif" "negatif" "negatif"
[36] "positif" "negatif" "negatif" "positif" "negatif" "positif" "negatif"
[43] "positif" "negatif" "positif" "positif" "negatif" "positif" "negatif"
[50] "positif" "negatif" "negatif" "negatif" "negatif" "negatif" "negatif"
[57] "negatif" "negatif" "negatif" "positif" "negatif" "negatif" "positif"
[64] "positif" "negatif" "positif" "negatif" "negatif" "positif" "negatif"
[71] "negatif" "negatif" "negatif" "negatif" "negatif"
$Prob
negatif positif
[1,] 1.000016213 -1.621285e-05
[2,] -0.015399975 1.015400e+00
[3,] 0.131798629 8.682014e-01
[4,] 0.913610113 8.638989e-02
[5,] -0.007226770 1.007227e+00
[6,] -0.007434607 1.007435e+00
[7,] 0.822317428 1.776826e-01
[8,] 0.452064700 5.479353e-01
[9,] 1.000037060 -3.706033e-05
[10,] 0.984403703 1.559630e-02
[11,] 1.002079889 -2.079889e-03
[12,] 0.063393131 9.366069e-01
[13,] 0.766288803 2.337112e-01
[14,] 0.998567461 1.432539e-03
[15,] 0.981894532 1.810547e-02
[16,] 0.870295392 1.297046e-01
[17,] 0.990382634 9.617366e-03
[18,] 0.923010966 7.698903e-02
[19,] 1.002976953 -2.976953e-03
[20,] 1.004961146 -4.961146e-03
[21,] 0.851112730 1.488873e-01
[22,] 0.933663838 6.633616e-02
[23,] 0.884913425 1.150866e-01
[24,] 1.004358978 -4.358978e-03
[25,] 0.376311492 6.236885e-01
[26,] -0.014582062 1.014582e+00
[27,] 0.950271761 4.972824e-02
[28,] 0.653951737 3.460483e-01
[29,] 0.141132940 8.588671e-01
[30,] -0.009277185 1.009277e+00
[31,] 0.842818837 1.571812e-01
[32,] 0.953618386 4.638161e-02
[33,] 0.994551141 5.448859e-03
[34,] 0.981510520 1.848948e-02
[35,] 0.748594649 2.514054e-01
[36,] 0.100112801 8.998872e-01
[37,] 0.603680357 3.963196e-01
[38,] 0.966419808 3.358019e-02
[39,] 0.229610874 7.703891e-01
[40,] 1.004793373 -4.793373e-03
[41,] 0.331009187 6.689908e-01
[42,] 0.999996640 3.359742e-06
[43,] -0.007224877 1.007225e+00
[44,] 0.913058111 8.694189e-02
[45,] 0.022202558 9.777974e-01
[46,] 0.019332617 9.806674e-01
[47,] 0.938043481 6.195652e-02
[48,] 0.010994495 9.890055e-01
[49,] 0.936136018 6.386398e-02
[50,] 0.076533578 9.234664e-01
[51,] 1.003810698 -3.810698e-03
[52,] 0.984586259 1.541374e-02
[53,] 0.780585234 2.194148e-01
[54,] 0.962360848 3.763915e-02
[55,] 0.869140063 1.308599e-01
[56,] 0.649572310 3.504277e-01
[57,] 0.836751458 1.632485e-01
[58,] 0.542609205 4.573908e-01
[59,] 0.987977417 1.202258e-02
[60,] -0.015773466 1.015773e+00
[61,] 1.004855560 -4.855560e-03
[62,] 0.782654530 2.173455e-01
[63,] 0.199051930 8.009481e-01
[64,] 0.008278253 9.917217e-01
[65,] 1.001237547 -1.237547e-03
[66,] 0.369378542 6.306215e-01
[67,] 0.925590318 7.440968e-02
[68,] 0.915724000 8.427600e-02
[69,] 0.308905764 6.910942e-01
[70,] 0.995717811 4.282189e-03
[71,] 1.000003364 -3.363682e-06
[72,] 0.710345424 2.896546e-01
[73,] 0.522081041 4.779190e-01
[74,] 1.001423773 -1.423773e-03
[75,] 0.899719315 1.002807e-01
$M_table
Class
Y negatif positif
negatif 47 3
positif 5 20
$err
[1] 0.1066667
load('Dopage.RData')
x=hema
z=test
(x0=runif(7,min(x),max(x)))
[1] 34.83296 38.20512 40.45646 43.46503 36.46502 37.21142 55.32958
Classif_NP(x,z,x0)
$Class
[1] "negatif" "positif" "positif" "negatif" "positif" "positif" "negatif"
[8] "positif" "negatif" "negatif" "negatif" "positif" "negatif" "negatif"
[15] "negatif" "negatif" "negatif" "negatif" "negatif" "negatif" "negatif"
[22] "negatif" "negatif" "negatif" "positif" "positif" "negatif" "negatif"
[29] "positif" "positif" "negatif" "negatif" "negatif" "negatif" "negatif"
[36] "positif" "negatif" "negatif" "positif" "negatif" "positif" "negatif"
[43] "positif" "negatif" "positif" "positif" "negatif" "positif" "negatif"
[50] "positif" "negatif" "negatif" "negatif" "negatif" "negatif" "negatif"
[57] "negatif" "negatif" "negatif" "positif" "negatif" "negatif" "positif"
[64] "positif" "negatif" "positif" "negatif" "negatif" "positif" "negatif"
[71] "negatif" "negatif" "negatif" "negatif" "negatif"
$Prob
negatif positif
[1,] 1.000016213 -1.621285e-05
[2,] -0.015399975 1.015400e+00
[3,] 0.131798629 8.682014e-01
[4,] 0.913610113 8.638989e-02
[5,] -0.007226770 1.007227e+00
[6,] -0.007434607 1.007435e+00
[7,] 0.822317428 1.776826e-01
[8,] 0.452064700 5.479353e-01
[9,] 1.000037060 -3.706033e-05
[10,] 0.984403703 1.559630e-02
[11,] 1.002079889 -2.079889e-03
[12,] 0.063393131 9.366069e-01
[13,] 0.766288803 2.337112e-01
[14,] 0.998567461 1.432539e-03
[15,] 0.981894532 1.810547e-02
[16,] 0.870295392 1.297046e-01
[17,] 0.990382634 9.617366e-03
[18,] 0.923010966 7.698903e-02
[19,] 1.002976953 -2.976953e-03
[20,] 1.004961146 -4.961146e-03
[21,] 0.851112730 1.488873e-01
[22,] 0.933663838 6.633616e-02
[23,] 0.884913425 1.150866e-01
[24,] 1.004358978 -4.358978e-03
[25,] 0.376311492 6.236885e-01
[26,] -0.014582062 1.014582e+00
[27,] 0.950271761 4.972824e-02
[28,] 0.653951737 3.460483e-01
[29,] 0.141132940 8.588671e-01
[30,] -0.009277185 1.009277e+00
[31,] 0.842818837 1.571812e-01
[32,] 0.953618386 4.638161e-02
[33,] 0.994551141 5.448859e-03
[34,] 0.981510520 1.848948e-02
[35,] 0.748594649 2.514054e-01
[36,] 0.100112801 8.998872e-01
[37,] 0.603680357 3.963196e-01
[38,] 0.966419808 3.358019e-02
[39,] 0.229610874 7.703891e-01
[40,] 1.004793373 -4.793373e-03
[41,] 0.331009187 6.689908e-01
[42,] 0.999996640 3.359742e-06
[43,] -0.007224877 1.007225e+00
[44,] 0.913058111 8.694189e-02
[45,] 0.022202558 9.777974e-01
[46,] 0.019332617 9.806674e-01
[47,] 0.938043481 6.195652e-02
[48,] 0.010994495 9.890055e-01
[49,] 0.936136018 6.386398e-02
[50,] 0.076533578 9.234664e-01
[51,] 1.003810698 -3.810698e-03
[52,] 0.984586259 1.541374e-02
[53,] 0.780585234 2.194148e-01
[54,] 0.962360848 3.763915e-02
[55,] 0.869140063 1.308599e-01
[56,] 0.649572310 3.504277e-01
[57,] 0.836751458 1.632485e-01
[58,] 0.542609205 4.573908e-01
[59,] 0.987977417 1.202258e-02
[60,] -0.015773466 1.015773e+00
[61,] 1.004855560 -4.855560e-03
[62,] 0.782654530 2.173455e-01
[63,] 0.199051930 8.009481e-01
[64,] 0.008278253 9.917217e-01
[65,] 1.001237547 -1.237547e-03
[66,] 0.369378542 6.306215e-01
[67,] 0.925590318 7.440968e-02
[68,] 0.915724000 8.427600e-02
[69,] 0.308905764 6.910942e-01
[70,] 0.995717811 4.282189e-03
[71,] 1.000003364 -3.363682e-06
[72,] 0.710345424 2.896546e-01
[73,] 0.522081041 4.779190e-01
[74,] 1.001423773 -1.423773e-03
[75,] 0.899719315 1.002807e-01
$M_table
Class
Y negatif positif
negatif 47 3
positif 5 20
$err
[1] 0.1066667
$Class0
[1] "negatif" "negatif" "negatif" "negatif" "negatif" "negatif" "positif"
$Prob0
[,1] [,2]
[1,] 1.00000305 -3.050618e-06
[2,] 1.00013719 -1.371873e-04
[3,] 1.00219450 -2.194498e-03
[4,] 0.99929658 7.034247e-04
[5,] 1.00001215 -1.215382e-05
[6,] 1.00002958 -2.958179e-05
[7,] 0.06916545 9.308346e-01
data('iris')
attach(iris)
for (j in colnames(iris)[1:4])
{
print(j)
x=get(j)
z=Species
(x0=runif(7,min(x),max(x)))
r=Classif_NP(x,z,x0)
cat(' \n')
cat('Qualité de la classification \n')
cat('matrice de confusion: \n')
print(r$M_table)
cat('erreur:\n')
print(r$err)
cat(' \n')
cat('Estimation \n')
cat('x0:\n')
print(x0)
cat('Class0:\n ')
print(r$Class0)
cat('Prob0:\n')
print(r$Prob0)
cat(' \n')
cat(' \n')
}
[1] "Sepal.Length"
Qualité de la classification
matrice de confusion:
Class
Y setosa versicolor virginica
setosa 45 5 0
versicolor 6 28 16
virginica 1 10 39
erreur:
[1] 0.2533333
Estimation
x0:
[1] 7.383677 7.241126 5.505740 4.557938 4.421192 4.840589 6.402346
Class0:
[1] virginica virginica versicolor setosa setosa setosa virginica
Levels: setosa versicolor virginica
Prob0:
[,1] [,2] [,3]
[1,] -1.694540e-07 0.064953827 0.9350463429
[2,] -1.807488e-06 0.119120103 0.8808817048
[3,] 4.095701e-01 0.467905717 0.1225241528
[4,] 9.808421e-01 0.006999741 0.0121581895
[5,] 1.021328e+00 -0.021591860 0.0002637113
[6,] 8.821574e-01 0.090485636 0.0273570021
[7,] 5.557136e-03 0.406581415 0.5878614480
[1] "Sepal.Width"
Qualité de la classification
matrice de confusion:
Class
Y setosa versicolor virginica
setosa 38 2 10
versicolor 5 27 18
virginica 13 21 16
erreur:
[1] 0.46
Estimation
x0:
[1] 3.994071 2.327497 3.662578 3.784874 3.650477 3.901836 4.054478
Class0:
[1] setosa versicolor setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica
Prob0:
[,1] [,2] [,3]
[1,] 0.90872908 -0.0034884255 0.09475935
[2,] 0.06882036 0.7225055543 0.20867409
[3,] 0.81698693 0.0153854607 0.16762761
[4,] 0.84048795 -0.0003003085 0.15981236
[5,] 0.81384171 0.0176970021 0.16846129
[6,] 0.86993706 -0.0045291613 0.13459210
[7,] 0.93758175 -0.0022903744 0.06470862
[1] "Petal.Length"
Qualité de la classification
matrice de confusion:
Class
Y setosa versicolor virginica
setosa 50 0 0
versicolor 0 46 4
virginica 0 3 47
erreur:
[1] 0.04666667
Estimation
x0:
[1] 3.298687 6.150212 5.523241 2.971976 6.854861 5.576972 6.101808
Class0:
[1] versicolor virginica virginica versicolor virginica virginica virginica
Levels: setosa versicolor virginica
Prob0:
[,1] [,2] [,3]
[1,] 9.252868e-02 0.920079360 -0.012608036
[2,] -4.601070e-14 -0.018798569 1.018798569
[3,] -3.674481e-11 0.089642825 0.910357175
[4,] 2.917761e-01 0.706762950 0.001460953
[5,] -5.706670e-18 -0.006203513 1.006203513
[6,] -2.225391e-11 0.069280354 0.930719646
[7,] -8.178809e-14 -0.018078626 1.018078626
[1] "Petal.Width"
Qualité de la classification
matrice de confusion:
Class
Y setosa versicolor virginica
setosa 50 0 0
versicolor 0 48 2
virginica 0 4 46
erreur:
[1] 0.04
Estimation
x0:
[1] 1.6068453 2.2849280 0.1618465 1.0377594 1.4003224 0.9825604 1.7537589
Class0:
[1] versicolor virginica setosa versicolor versicolor versicolor virginica
Levels: setosa versicolor virginica
Prob0:
[,1] [,2] [,3]
[1,] 2.106430e-07 0.5597915598 4.402082e-01
[2,] -7.168606e-15 -0.0009856619 1.000986e+00
[3,] 1.000588e+00 -0.0005875111 -1.882299e-08
[4,] 5.330843e-02 0.9542377405 -7.546173e-03
[5,] 3.869350e-05 0.8575786576 1.423826e-01
[6,] 1.126288e-01 0.8933980272 -6.026845e-03
[7,] 9.313488e-09 0.3197953225 6.802047e-01