Care should be taken with this method not to encounter the
birthday problem, described
https://www.johndcook.com/blog/2016/01/29/random-number-generator-seed-mistakes/.
Since the sitmo
threefry
, this currently generates
one random deviate from the uniform distribution to seed the
engine threefry
and then run the code.
rxweibull(shape, scale = 1, n = 1L, ncores = 1L)
shape | shape and scale parameters, the latter defaulting to 1. |
---|---|
scale | shape and scale parameters, the latter defaulting to 1. |
n | number of observations. If |
ncores | Number of cores for the simulation
|
Weibull random deviates
Therefore, a simple call to the random number generated followed by a second call to random number generated may have identical seeds. As the number of random number generator calls are increased the probability that the birthday problem will increase.
The key to avoid this problem is to either run all simulations in the
RxODE
environment once (therefore one seed or series of seeds
for the whole simulation), pre-generate all random variables
used for the simulation, or seed the RxODE engine with rxSetSeed()
Also care should be made that the computer you will be running on can run the same number of cores as you are running so they can reproduce your results.
# \donttest{
## Use threefry engine
# with rxweibull you have to explicitly state n
rxweibull(shape = 1, scale = 4, n = 10)
#> [1] 3.263039 14.203785 4.383256 3.435666 1.218369 1.137865 4.117574
#> [8] 1.781901 8.414812 13.043168
# You can parallelize the simulation using openMP
rxweibull(shape = 1, scale = 4, n = 10, ncores = 2)
#> [1] 2.4164762 5.9515926 2.2433800 2.3252854 9.6580657 3.7239096 3.2281503
#> [8] 3.5391126 0.7262167 5.1057364
rxweibull(3)
#> [1] 0.4198434
## This example uses `rxweibull` directly in the model
rx <- RxODE({
a <- rxweibull(1, 3)
})
#>
et <- et(1, id = 1:2)
s <- rxSolve(rx, et)
# }