R script: seed.R


# 1 Introduction

The same sequence of random numbers can be used for successive runs of simulx by using the field seed of the list settings. The seed should be an integer.

s <- list(seed=123456)}
res <- simulx( ... , settings=list(seed=s, ...))

Then, the same results will be obtained at each run if the seed is not modified.

# 2 Example

we set first the seed to 12345 in this example:

myModel = inlineModel("
[LONGITUDINAL]
input =  {a, b, s}
EQUATION:
f = a + b*t
DEFINITION:
y = {distribution=normal, prediction=f, sd=s}
")

res <- simulx(model     = myModel,
parameter = c(a=10, b=10, s=0.5),
settings  = list(seed=12345),
output    = list(name='y',time=(1:5)))
print(res$y) ## time y ## 1 1 20.04104 ## 2 2 29.56789 ## 3 3 39.27692 ## 4 4 50.16861 ## 5 5 59.64229 We obtain again the same results if we run again simulx with the same seed res <- simulx(model = myModel, parameter = c(a=10, b=10, s=0.5), settings = list(seed=12345), output = list(name='y',time=(1:5))) print(res$y)
##   time        y
## 1    1 20.04104
## 2    2 29.56789
## 3    3 39.27692
## 4    4 50.16861
## 5    5 59.64229

Change the seed, or don’t use it in settings, to obtain different results.

res <- simulx(model     = myModel,
parameter = c(a=10, b=10, s=0.5),
settings  = list(seed=54321),
output    = list(name='y',time=(1:5)))
print(res$y) ## time y ## 1 1 19.99159 ## 2 2 29.64455 ## 3 3 40.18644 ## 4 4 49.51541 ## 5 5 59.94413 res <- simulx(model = myModel, parameter = c(a=10, b=10, s=0.5), output = list(name='y',time=(1:5))) print(res$y)
##   time        y
## 1    1 19.88786
## 2    2 29.97479
## 3    3 39.88018
## 4    4 49.76314
## 5    5 59.63709