Draw random samples from a generalized gamma distribution using the
parameterization from flexsurv. Written in C++
for speed. Equivalent to flexsurv::rgengamma.
fast_rgengamma(n, mu = 0, sigma = 1, Q)A vector of random samples from the generalized gamma distribution. The length of the sample is determined by n. The numerical arguments other than n are recycled so that the number of samples is equal to n.
n <- 1000
m <- 2 ; s <- 1.7; q <- 1
ptm <- proc.time()
r1 <- fast_rgengamma(n, mu = m, sigma = s, Q = q)
proc.time() - ptm
#>    user  system elapsed 
#>   0.001   0.000   0.001 
ptm <- proc.time()
library("flexsurv")
r2 <- flexsurv::rgengamma(n, mu = m, sigma = s, Q = q)
proc.time() - ptm
#>    user  system elapsed 
#>   0.001   0.000   0.002 
summary(r1)
#>      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
#> 2.000e-06 9.782e-01 4.231e+00 1.181e+01 1.365e+01 1.960e+02 
summary(r2)
#>      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
#> 1.000e-06 8.095e-01 3.758e+00 1.203e+01 1.339e+01 2.820e+02