[Rd] .Random.seed (PR#911)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Thu, 12 Apr 2001 11:08:20 +0200 (MET DST)


On Thu, 12 Apr 2001 e.zwane@fss.uu.nl wrote:

> I am not sure whether this is really a bug, but seems to be as my program
> works pretty well in S+, for small iterations.

It contains two serious bugs.  Please read the FAQ on reporting BUGS.

> I am creating a random sample from a chi^2 distribution with 23.5 df. Thus
> I have to sample from a chi^2 with 23 or 24 df with probability 0.5. The
> other alternative is to create a weighted version of the two distribution,
> which is where my problem lies.
>
> I use the following commands
>
> while(iter<100){
> old.seed<-.Random.seed
> #sample from chi^2 23
> set.seed(old.seed)

That's invalid in both S-PLUS and in R.  The argument to set.seed is
not in the format of the result of the return from .Random.seed.

> #sample from chi^2 24
>
> #chi^2, 23.5 <- 0.5*(chi^2 23+chi^2 24)

That's an average, not an equi-probability choice.

> iter+1
> }
>
> The unfortunate thing is that the ".Random.seed" is no longer random but
> remains constant, and I want to find ways around this problem.

Use the functions correctly!  You really should not be restoring random
seeds during a simulation, as you will get heavily dependent rvs.

If you really want a Chi-squared with 23.5 df, use rgamma.  It can do it
exactly.


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._