Re: [R] simple random number generation

2008-07-24 Thread Rolf Turner
Duncan Murdoch recently (24 July 2008) posted code providing a much more elegant and efficient approach. (Subject line: truncated normal). Also there is apparently a function in the msm package which will do this for you. cheers, Rolf Turner On 25/07/2008, at 2:43

Re: [R] simple random number generation

2008-07-24 Thread S Ellison
Since the standard normal distribution goes to infinity in both directions, you can't have random normal constrained to +-1.5. You can have _truncated_ standard normal, though, if that's really what you want. +-1.5 is/are the normal quantiles at pnorm(c(-1.5,1.5)). So if we generate 500 uniform

Re: [R] simple random number generation

2008-07-24 Thread Moshe Olshansky
Or, as suggested by Duncan Murdoch, qnorm(runif(500,pnorm(-1.5),pnorm(1.5))) --- On Fri, 25/7/08, jim holtman <[EMAIL PROTECTED]> wrote: > From: jim holtman <[EMAIL PROTECTED]> > Subject: Re: [R] simple random number generation > To: "dxc13" <[EMAIL PROT

Re: [R] simple random number generation

2008-07-24 Thread jim holtman
Generate more than you need and then just keep 500 of them: > x <- rnorm(3000) # make sure we have enough > y <- x[(x > -1.5) & (x < 1.5)][1:500] # keep 500 0f them > hist(y) > On Thu, Jul 24, 2008 at 7:35 PM, dxc13 <[EMAIL PROTECTED]> wrote: > > useR's, > > I want to randomly generate 500 numb

[R] simple random number generation

2008-07-24 Thread dxc13
useR's, I want to randomly generate 500 numbers from the standard normal distribution, i.e. N(0,1), but I only want them to be generated in the range -1.5 to 1.5. Does anyone have a simple way to do this? Thanks, dxc13 -- View this message in context: http://www.nabble.com/simple-random-numb