rnorm. <- function(seed, ...){
+ set.seed(seed) + rnorm(...) + }
[1] -0.6264538######### rnorm.(1, 1)
rnorm.(1, 1)[1] -0.6264538
rnorm.(1, 1)[1] -0.6264538
rnorm.(1, 1)[1] -0.6264538
rnorm.(1, 1)[1] -0.6264538
rnorm.(1, 1)
[1] -0.6264538
Observe that the first argument is the seed, `...' is used to pass arguments to `rnorm()'!
x <- rnorm(100) y <- rnorm(100)
are independent, however,
x <- rnorm.(1, 100) y <- rnorm.(1, 100)
will be exactly the same.
Best, Dimitris
---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message ----- From: "Clark Allan" <[EMAIL PROTECTED]>
To: "Dimitris Rizopoulos" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Friday, March 04, 2005 1:21 PM
Subject: Re: [R] R: simulation
Hi
thanx for the reply.
i used your code and pasted it into R and ran it a few times. the output
is below. what i want is to get the same output every time the program
is run. is this possible?
another question?
x<-rnorm(100) y<-rnorm(100)
is x and y independent?
rnorm(1)[1] 0.4251004rnorm(1)[1] -0.2386471rnorm(1)[1] 1.058483rnorm(1)[1] 0.8864227rnorm(1)[1] -0.619243rnorm(1)[1] 2.206102rnorm(1)[1] -0.2550270rnorm(1)[1] -1.424495rnorm(1)[1] -0.1443996rnorm(1)[1] 0.2075383rnorm(1)[1] 2.307978rnorm(1)[1] 0.1058024
Dimitris Rizopoulos wrote:
look at ?set.seed, e.g.,
rnorm. <- function(seed, ...){ set.seed(seed) rnorm(...) } ######### rnorm.(100, 1, 2)
I hope it helps.
Best, Dimitris
---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message ----- From: "Clark Allan" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Friday, March 04, 2005 12:07 PM Subject: [R] R: simulation
> hi all
>
> a simple question
>
> i want to run simulations in r. i however want the experiments to > be
> repeated at a later time with exactly the same numbers by other
> users.
> can i set the random number seed for rnorm in some way?
>
> e.g. is there some arguement that goes with rnorm?
>
> please supply an example
>
> regards
> Allan
--------------------------------------------------------------------------------
> ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
