rsurvival-analysisweibullmixture-model

Simulation from mixture distribution in R


I would like to simulate data set which has a decreasing and then increasing hazard from 3 weibull distributions but I would like to have this hazard function more near to zerohow can I get around 0.1 or less. How can I fix my code to have this?


Solution

  • It's not necessary to use pexp and rexp, because the Exponential is a degenerate case of the Weibull distribution when the shape parameter=1. Shapes less than 1 are going to be even more "scoopy" near the origin. You could get a nice bathtubwith just two Weibull, but since you had one with three, I just made some minor alterations:

     hazmix = function(w1, w2, x) {w1*dweibull(x,.8, 1)/(1-pweibull(x, .8, 1))+ 
        + w2*dweibull(x,1,.5) + 
        ((1-(w1+w2))* dweibull(x, 6, 10)/(1-pweibull(x, 6, 10)))}
    
     png();plot(hazmix(.2,.4, seq(0, 10, by=.1)), ylim=c(0,1) ); dev.off()
    

    enter image description here

    I don't promise that it's normalized and if you needed a normalized distribution it would be much easier to just use two Weibulls with one mixing parameter.