setPackageSeedTP {TPmsm} | R Documentation |
The random number generator (RNG) with multiple independent streams developed by L'Ecuyer et al. (2002) is used for parallel computation of uniform pseudorandom numbers. Package TPmsm makes extensive use of uniform pseudorandom numbers, particularly for the bootstrapping statistical techniques and for the generation of univariate and multivariate pseudorandom data. This function defines the seed for the creation of RNG streams.
setPackageSeedTP(seed=12345)
seed |
A vector of one to six integers.
Defaults to |
If the user defines a vector with length lower than six
as seed, then the seed is internally defined as a vector
of length six with the first elements equal to the user
defined values, and the leaving elements equal to 12345
.
If a vector with more than six elements is provided as seed,
then only the first six elements are used.
Invisibly returns NULL.
When package TPmsm loads, an initial set of RNG streams
is created, one stream for each thread available for parallel
computation. The initial set of RNG streams is created from the
package seed c(12345, 12345, 12345, 12345, 12345, 12345)
.
Every time this function is called, the old set of RNG streams
is deleted, and a new set of RNG streams is created from the
user defined package seed. After the creation of each new RNG stream,
the internally stored package seed changes. So each RNG stream is
created from a different package seed, and yields different sets of
pseudorandom numbers.
Artur Araújo, Javier Roca-Pardiñas and Luís Meira-Machado
Karl A. T., Eubank R., Milovanovic J., Reiser M., Young D. (2014) Using RngStreams for parallel random number generation in C++ and R. Computational Statistics 29(5), 1301–1320.
L'Ecuyer, P. (1999) Good parameters and implementations for combined multiple recursive random number generators. Operations Research 47(1), 159–-164.
L’Ecuyer P., Simard R., Chen E. J., Kelton W. D. (2002) An object-oriented random-number package with many long streams and substreams. Operations Research 50(6), 1073–-1075.
# Set the number of threads nth <- setThreadsTP(2) # Define package seed seed <- rep(x=1, times=6) # Set package seed setPackageSeedTP(seed) # Create survTP object data(heartTP) heartTP_obj <- with(heartTP, survTP(time1, event1, Stime, event)) # Compute transition probabilities with confidence band TPmsm0 <- transAJ(object=heartTP_obj, s=33, t=412, conf=TRUE, conf.level=0.9, method.boot="percentile") # Compute transition probabilities with confidence band TPmsm1 <- transAJ(object=heartTP_obj, s=33, t=412, conf=TRUE, conf.level=0.9, method.boot="percentile") # The objects should be different all.equal(TPmsm0, TPmsm1) # Set package seed setPackageSeedTP(seed) # Compute transition probabilities with confidence band TPmsm2 <- transAJ(object=heartTP_obj, s=33, t=412, conf=TRUE, conf.level=0.9, method.boot="percentile") # Both objects were computed from the same seed and should be equal all.equal(TPmsm0, TPmsm2) # Restore the number of threads setThreadsTP(nth)