Skip to content
Prev 173485 / 398506 Next

Pseudo-random numbers between two numbers

On Wed, 11 Mar 2009 06:57:02 -0400
Duncan Murdoch <murdoch at stats.uwo.ca> wrote:

            
This is the approach taken in 
http://www.jstatsoft.org/v16/c02
http://www.jstatsoft.org/v16/c02/paper

which you may want to consult.  They give general routines to truncate
arbitrary distributions.
I agree with this assessment and guess that similar problem will arise
with other truncated distributions created with the code from the paper
above.

And, note, that if sd is small, you can easily be in the situation
where you evaluate pnorm() at extreme values.
Or use package truncnorm.  Though their c code seem to sample with
rejection from a normal proposal which would be quite inefficient for
"extreme" truncations, e.g., standard normal truncated to [8,10].  

Or use package msm, whose rtnorm() implements a more efficient
algorithm for simulating from a truncated normal distribution.

Cheers,

	Berwin