R script: seed.R

$$\newcommand{\esp}[1]{\mathbb{E}\left(#1\right)} \newcommand{\var}[1]{\mbox{Var}\left(#1\right)} \newcommand{\deriv}[1]{\dot{#1}(t)} \newcommand{\prob}[1]{ \mathbb{P}\!(#1)} \newcommand{\eqdef}{\mathop{=}\limits^{\mathrm{def}}} \newcommand{\by}{\boldsymbol{y}} \newcommand{\bc}{\boldsymbol{c}} \newcommand{\bpsi}{\boldsymbol{\psi}} \def\pmacro{\texttt{p}} \def\like{{\cal L}} \def\llike{{\cal LL}} \def\logit{{\rm logit}} \def\probit{{\rm probit}} \def\one{{\rm 1\!I}} \def\iid{\mathop{\sim}_{\rm i.i.d.}} \def\simh0{\mathop{\sim}_{H_0}} \def\df{\texttt{df}} \def\res{e} \def\xomega{x} \newcommand{\argmin}[1]{{\rm arg}\min_{#1}} \newcommand{\argmax}[1]{{\rm arg}\max_{#1}} \newcommand{\Rset}{\mbox{\mathbb{R}}} \def\param{\theta} \def\setparam{\Theta} \def\xnew{x_{\rm new}} \def\fnew{f_{\rm new}} \def\ynew{y_{\rm new}} \def\nnew{n_{\rm new}} \def\enew{e_{\rm new}} \def\Xnew{X_{\rm new}} \def\hfnew{\widehat{\fnew}} \def\degree{m} \def\nbeta{d} \newcommand{\limite}[1]{\mathop{\longrightarrow}\limits_{#1}} \def\ka{k{\scriptstyle a}} \def\ska{k{\scriptscriptstyle a}} \def\kel{k{\scriptstyle e}} \def\skel{k{\scriptscriptstyle e}} \def\cl{C{\small l}} \def\Tlag{T\hspace{-0.1em}{\scriptstyle lag}} \def\sTlag{T\hspace{-0.07em}{\scriptscriptstyle lag}} \def\Tk{T\hspace{-0.1em}{\scriptstyle k0}} \def\sTk{T\hspace{-0.07em}{\scriptscriptstyle k0}} \def\thalf{t{\scriptstyle 1/2}} \newcommand{\Dphi}[1]{\partial_\pphi #1} \def\asigma{a} \def\pphi{\psi} \newcommand{\stheta}{{\theta^\star}} \newcommand{\htheta}{{\widehat{\theta}}}$$

# 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