Re: [S] Summary: RE: Problems in generating Random Numbers

Charles Roosen (roosen@statsci.com)
Mon, 01 Jun 1998 08:51:56 -0700


Here's a little followup on the random number issues in jackknife()
and cov.mve().

There's a basic question which I still struggle with a bit regarding
whether users expect statistical estimates to be identical every time
they are calculated. I think that for random number generation,
bootstrap, and the like they expect the numbers to vary. For robust
regression and robust covariance estimation, I think they'd expect to
get the same result each time unless they are explicitely trying to
look at the variation.

So the model I'm moving towards is to let the user explicitely specify
a seed in pretty much anything that uses randomization, and then to
default this to either a fixed value or the current .Random.seed
depending on whether the answer should be different each time or the
same each time. The trick with this is that if you set the seed to
a particular value you need to stash away the .Random.seed before
doing so, and then restore it on exit. Basically

if (specified.seed != .Random.seed){
old.seed <- .Random.seed
on.exit(.Random.seed <<- old.seed)
.Random.seed <<- specified.seed
}

If this gets muddled then the random number stream gets repeated in
undesired ways.

In the jackknife() in 4.5 release 1, I neglected to stash away the
.Random.seed. This is fixed for the next release. The workaround
is to use something like

jackknife(my.data, my.stat, seed=.Random.seed)

when calling jackknife().

The cov.mve() modifications for 4.0 or 4.5 included fixing the seed,
without the logic to specify a different seed. We should probably
put the kind of logic that's in bootstrap() and jackknife() into
cov.mve() to allow the specification of different seeds. In the
interim, a workaround is to comment out the lines

temp <- .Random.seed
...
set.seed(4)
...
.Random.seed <<- temp

in cov.mve.default(). This will then give different answers each time
cov.mve() is used (I think).

Charlie Roosen

At 10:53 AM 6/1/98 -0300, Smith, Stephen wrote:
>On the 25th of May I had reported a problem with using sample() to
>conduct a simulation and having .Random.seed reset back to the same
>number. Earlier Patrik OHagen had reported a similar problem with
>cov.mve which was confirmed by Brian Ripley.
>
>Thanks to Stephen Weller from Mathsoft for his quick assistance.
>
>
>It appears that Patrik's and my problems had a similar basis:
>
>cov.mve resets .Random.seed internally and therefore any simulation with
>this function will run into problems. A fix to this problem requres
>change to the code with an option to change the seed. The specific code
>is:
>
> class(ans) <- "mve"
> attr(ans, "call") <- sys.call()
> return(ans)
> }
> set.seed(4)
> if(!missing(mutate.prob)) {
> if(length(mutate.prob) != 4)
> stop("mutate.prob must have length 4")
> if(any(mutate.prob < 0))
> stop("negative value in mutate.prob")
> if(sum(mutate.prob[2:4]) > 1)
> stop("sum of last 3 mutation probabilities
>greater than 1")
> }
>
>In may case, I use jackknife() later on my code which defaults to seed=0
>in its call statement:
>
>> args(jackknife)
>function(data, statistic, args.stat = NULL, seed = 0, group.size = 1,
>assign.frame1 = F)
>
>This feature can be by-passed by conducting the simulation with
>something like seed=sample(1000,1) in the call statement.
>
>
>Stephen Smith
>
>
>---------------------------------------
>Stephen J. Smith
>Head, Molluscan Fisheries Section
>Invertebrate Fisheries Division
>Department of Fisheries and Oceans
>P.O. Box 1006
>Dartmouth, Nova Scotia
>Canada B2Y 4A2
>
>Street address for Couriers:
>1 Challenger Drive
>
>Voice: 902-426-3317
>Fax: 902-426-1862
>Note new email address.
>Internet: Smithsj@mar.dfo-mpo.gc.ca
>
>-----------------------------------------------------------------------
>This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
>send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
>message: unsubscribe s-news
>

**********************************************************************
Charles Roosen, PhD 1700 Westlake Ave N, Suite 500
Senior Statistician Seattle, WA 98109
Data Analysis Products Division (206) 283-8802 x254
MathSoft email: roosen@statsci.com
**********************************************************************

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news