R/dexp_mix.R

Defines functions dexp_mix

Documented in dexp_mix

dexp_mix <- function(x, pi, rate, log = FALSE){
  if(length(x) == 1){
    g = length(pi)
    pi = pi/sum(pi)
    if(min(c(pi, rate)) > 0 && length(rate) == g){
      aux = 0
      if(x >= 0){
        for(j in 1:g){aux = aux + pi[j]*dexp(x, rate=rate[j])}
      }
      if(!log){
        return(aux)
      }else{
        return(log(aux))
      }
    }else{
      stop("The parametric space must be respected.")
    }
  }else{
    h = function(x){dexp_mix(x, pi, rate, log)}
    return(sapply(x, h))
  }
}
matheuscastro43/finiteMix documentation built on March 30, 2022, 12:49 p.m.