s-news
[Top] [All Lists]

Re: Generating random real numbers

To: msawada@aix1.uottawa.ca (Mike C. Sawada)
Subject: Re: Generating random real numbers
From: "Joseph Beyene" <joseph@utstat.toronto.edu>
Date: Tue, 3 Apr 2001 21:56:49 -0400 (EDT)
Cc: demp2979@mach1.wlu.ca (Alastair Dempster), s-news@wubios.wustl.edu (splus list)
In-reply-to: <Pine.A41.3.96.1010403133310.44036A-100000@aix1.uottawa.ca> from "Mike C. Sawada" at Apr 03, 2001 01:33:52 PM
If seems to me the objective of the original question 
is to generate random numbers from a distribution that 
is assumed to follow a normal distribution on the 
support (0.005, 0.035).

Hence, the question boils down to determining the mean (mu)
and standard deviation (sigma) of the distribution,
since these two parameters fully specify the underlying 
normal distribution.

Step-1: The Gaussian mean parameter should be located at the
        center of the support. Here the center is
       (0.005 + 0.035)/2 = 0.02 = mu;

Step-2: Determine sigma using the following simple algebra:

      P(0.005 < X < 0.035) = 1  

=>  P((0.005-0.02)/sigma < (X-0.02)/sigma < (0.035-0.02)/sigma) =1

=> P(-0.015/sigma < Z < 0.015/sigma) = 1, where Z is N(0,1).

But we also know that P(-4 < Z < 4) is ALMOST 1, so can set

4 = 0.015/sigma, which implies sigma = 0.00375. 


Step-3:  We can now generate random samples from a N(0.02, 0.00375) 
distribution in the usual way.

e.g. 

> rnorm(n=10,mean=0.02,sd=0.00375)
 [1] 0.01880891 0.01918489 0.02010347 0.01819819
 [5] 0.01437798 0.01553930 0.01847044 0.02031811
 [9] 0.02246164 0.02356001


Am I missing the point of the question? I would 
like to hear about alternative (easier) approaches and/or
whether the above approach suffers from a major 
technical problem.

Regards,


Joseph Beyene
(joseph@utstat.torornto.edu)

Previously, Mike C. Sawada wrote:
> 
> Try:
> 
>  runif(100,min=0.005,max=0.035)
> 
> will produce 100 real numbers (real as far as rational and irrational
> numbers may ocurr) between the ranges of 0.005 and 0.035.
> 
> -------------------------------------------------------------------------------
> Mike C. Sawada                                       |Tel: 613-562-5800 x1734
> Laboratory of Paleoclimatology and Climatology |Fax: 613-562-5145
> Department of Geography                              |msawada@aix1.uottawa.ca 
>         
> University of Ottawa
> 165 Waller Street
> Ottawa, ON K1N 6N5
>   -----------------                                    -----------------
>       ************************************************************
>       WWW: http://www.uottawa.ca/academic/arts/geographie/lpcweb/
>       ************************************************************
> -------------------------------------------------------------------------------
> 
> On Tue, 3 Apr 2001, Alastair Dempster wrote:
> 
> > I'm posting this for an Splus user who is not part of this
> > discussion group:
> > 
> > She writes:
> > "I am interested in generating a set of 100 random real numbers
> > between 0.005 and 0.035, where the probability of drawing a specific
> > value is
> > defined by the normal distribution.  rnorm() will not let me define
> > the limits of
> > my dataset, yet my model parameter values cannot physically exceed
> > 0.035 by
> > definition.  Is anyone aware of how to specify range limits when
> > generating random
> > numbers with a non-uniform distribution? I have explored sample(),
> > runif(), rnorm(), and rmvnorm(), all of
> > which nicely generate random numbers.  However, either they are not
> > real (as in the case of sample()), or I cannot figure out how to
> > define a range of values for the random sample."
> > 
> > She is using Splus 2000 under NT4.
> > 
> > I have had a look at the discussions about random number generation
> > in the archives but did not find anything suitable.
> > 
> > Can anyone tell us how to code this or provide a reference?  I will
> > post a summary on behalf of my colleague.
> > 
> > Thank you,
> > 
> > Alastair Dempster
> > Wilfrid Laurier University
> > Waterloo, Canada
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > This message was distributed by s-news@lists.biostat.wustl.edu.  To
> > unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> > the BODY of the message:  unsubscribe s-news
> > 
> 
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>