R/vec2pro.R

Defines functions vec2pro

Documented in vec2pro

#' Transfer an informative vector to a probability vector
#'
#' Transfer an informative vector to a probability vector
#' @param vec An informative vector
#' @return pro A probability vector
#' @export

vec2pro <- function(vec){
  g <- length(vec)+1
  pro <- numeric(g)
  z <- numeric(g)
  for (h in 1:(g-1)){
    z[h] <- 1/(1+exp(-vec[h]-log(1/(g-h))))
  }
  pro[1] <- z[1]
  if (g > 2){
    for (h in 2:(g-1)){
      pro[h] <- (1-sum(pro[1:(h-1)]))*z[h]
    }
  }
  pro[g] <- 1-sum(pro[-g])
  return(pro)
}

Try the gmmsslm package in your browser

Any scripts or data that you put into this service are public.

gmmsslm documentation built on June 8, 2025, 2 p.m.