Re: [R] simple random number generation

From: S Ellison <S.Ellison_at_lgc.co.uk>
Date: Fri, 25 Jul 2008 04:07:01 +0100


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 uniformly distributed probabilities in the range pnorm(c(-1.5,1.5)), and then run qnorm on those, you should get what you want:

Try this:

lims<-pnorm(c(-1.5,1.5)) #get the range of probs required x<-qnorm(runif(500,lims[1],lims[2]))
hist(x)

Steve E.

>>> dxc13 <dxc13_at_health.state.ny.us> 07/25/08 12:35 AM >>>

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-number-generation-tp18642611p18642611.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 25 Jul 2008 - 03:09:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jul 2008 - 04:32:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive