R/dweibull_mix.R

Defines functions dweibull_mix

Documented in dweibull_mix

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