R/pweibull_mix.R

Defines functions pweibull_mix

Documented in pweibull_mix

pweibull_mix <- function(q, pi, shape, scale, lower.tail = TRUE, log.p = FALSE){
  if(length(q) == 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]*pweibull(q,shape=shape[j], scale = scale[j])}
      if(!lower.tail){
        aux = 1 - aux
      }
      if(!log.p){
        return(aux)
      }else{
        return(log(aux))
      }
    }else{
      stop("The parametric space must be respected.")
    }
  }
  else{
    h = function(q){pweibull_mix(q, pi, shape, scale, lower.tail, log.p)}
    return(sapply(q, h))
  }
}
matheuscastro43/finiteMix documentation built on March 30, 2022, 12:49 p.m.