[R] R: simulation

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Fri Mar 4 13:32:37 CET 2005


are you sure you tried the function I gave you? There is a "." that 
you might have missed. When I try it I get this:

> rnorm. <- function(seed, ...){
+      set.seed(seed)
+     rnorm(...)
+ }
> #########
> 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
> 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" <Allan at STATS.uct.ac.za>
To: "Dimitris Rizopoulos" <dimitris.rizopoulos at med.kuleuven.ac.be>; 
<r-help at stat.math.ethz.ch>
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.4251004
>> rnorm(1)
> [1] -0.2386471
>> rnorm(1)
> [1] 1.058483
>> rnorm(1)
> [1] 0.8864227
>> rnorm(1)
> [1] -0.619243
>> rnorm(1)
> [1] 2.206102
>> rnorm(1)
> [1] -0.2550270
>> rnorm(1)
> [1] -1.424495
>> rnorm(1)
> [1] -0.1443996
>> rnorm(1)
> [1] 0.2075383
>> rnorm(1)
> [1] 2.307978
>> rnorm(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" <Allan at stats.uct.ac.za>
>> To: <r-help at stat.math.ethz.ch>
>> 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
>>
>> --------------------------------------------------------------------------------
>>
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide!
>> > http://www.R-project.org/posting-guide.html




More information about the R-help mailing list