ed32731c29691931734681b301f52ca5b5c98657
[valse.git] / R / selectionmodele.R
1 vec_bin = function(X,r)
2 {
3 Z = c()
4 indice = c()
5
6 j = 1
7 for(i in 1:length(X))
8 {
9 if(X[i] == r)
10 {
11 Z[i] = 1
12 indice[j] = i
13 j=j+1
14 } else
15 Z[i] = 0
16 }
17
18 return (list(Z=Z,indice=indice))
19 }
20
21 selectionmodele = function(vraisemblance)
22 {
23 D = vraimsemblance[,2]
24 D1 = unique(D)
25
26 indice = rep(1, length(D1))
27 #select argmax MLE
28 if (length(D1)>2)
29 {
30 for (i in 1:length(D1))
31 {
32 A = c()
33 for (j in 1:length(D))
34 {
35 if(D[[j]]==D1[[i]])
36 a = c(a, vraimsemblance[j,1])
37 }
38 b = max(a)
39 #indice[i] : premier indice du vecteur binaire où u_i ==1
40 indice[i] = which.max(vec_bin(vraimsemblance,b)[[1]])
41 }
42 }
43
44 return (list(indice=indice,D1=D1))
45 }