mercredi 23 décembre 2015

Generate random numbers from mixture and put outcome of each distribution in sequence

I want to put random numbers come from first gamma [gamma with shape=2 , rate=4] in vector and from second gamma [gamma with shape=3 , rate=4] in another vector

x <- rep(0,20)
for (i in 1:20){
    U[i] <- runif(1,0,1)
    if( U[i] < 0.8){
        x[i] <- rgamma(1,shape=2,rate=4)
    } else { 
        x[i] <- rgamma(1,shape=3,rate=4)
    }
}




Aucun commentaire:

Enregistrer un commentaire