ajout des commentaires Roxygen - anglicisme de certains noms de fonctions et de variables
[valse.git] / R / modelSelection.R
1 #' Among a collection of models, this function constructs a subcollection of models with
2 #' models having strictly different dimensions, keeping the model which minimizes
3 #' the likelihood if there were several with the same dimension
4 #'
5 #' @param LLF a matrix, the first column corresponds to likelihoods for several models
6 #' the second column corresponds to the dimensions of the corresponding models.
7 #'
8 #' @return a list with indices, a vector of indices selected models,
9 #' and D1, a vector of corresponding dimensions
10 #' @export
11 #'
12 #' @examples
13 modelSelection = function(LLF)
14 {
15 D = LLF[,2]
16 D1 = unique(D)
17
18 indices = rep(1, length(D1))
19 #select argmax MLE
20 if (length(D1)>2)
21 {
22 for (i in 1:length(D1))
23 {
24 A = c()
25 for (j in 1:length(D))
26 {
27 if(D[[j]]==D1[[i]])
28 a = c(a, LLF[j,1])
29 }
30 b = max(a)
31 #indices[i] : first indices of the binary vector where u_i ==1
32 indices[i] = which.max(vec_bin(LLF,b)[[1]])
33 }
34 }
35
36 return (list(indices=indices,D1=D1))
37 }