X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=R%2FmodelSelection.R;h=bc7eeaeda3d6732426dc8f6cfabb28e7b88711f2;hp=5a79bb6326299e8d852aef47566288f24a2bbb25;hb=e166ed4e1370aa7961f0d8609936591cfc6808cc;hpb=0b216f854a21821f9be375d07c2932b31e227e78 diff --git a/R/modelSelection.R b/R/modelSelection.R index 5a79bb6..bc7eeae 100644 --- a/R/modelSelection.R +++ b/R/modelSelection.R @@ -3,34 +3,34 @@ #' the likelihood if there were several with the same dimension #' #' @param LLF a matrix, the first column corresponds to likelihoods for several models -#' the second column corresponds to the dimensions of the corresponding models. +#' the second column corresponds to the dimensions of the corresponding models. #' #' @return a list with indices, a vector of indices selected models, -#' and D1, a vector of corresponding dimensions +#' and D1, a vector of corresponding dimensions #' @export #' modelSelection = function(LLF) { - D = LLF[,2] - D1 = unique(D) - - indices = rep(1, length(D1)) - #select argmax MLE - if (length(D1)>2) - { - for (i in 1:length(D1)) - { - A = c() - for (j in 1:length(D)) - { - if(D[[j]]==D1[[i]]) - a = c(a, LLF[j,1]) - } - b = max(a) - #indices[i] : first indices of the binary vector where u_i ==1 - indices[i] = which.max(vec_bin(LLF,b)[[1]]) - } - } - - return (list(indices=indices,D1=D1)) + D = LLF[,2] + D1 = unique(D) + + indices = rep(1, length(D1)) + #select argmax MLE + if (length(D1)>2) + { + for (i in 1:length(D1)) + { + A = c() + for (j in 1:length(D)) + { + if(D[[j]]==D1[[i]]) + a = c(a, LLF[j,1]) + } + b = max(a) + #indices[i] : first indices of the binary vector where u_i ==1 + indices[i] = which.max(vec_bin(LLF,b)[[1]]) + } + } + + return (list(indices=indices,D1=D1)) }