Re: [R] how to generate a normal distribution with mean=1, min=0.2, max=0.8

From: Carl Witthoft <carl_at_witthoft.com>
Date: Thu, 28 Apr 2011 18:37:01 -0400


That method (creating lots of samples and throwing most of them away) is usually frowned upon :-).

Try this: (I haven't, so it may well have syntax errors)

% n28<- dnorm(seq(.2,.8,by=.001),mean=1,sd=1)

% x <- sample(seq(.2,.8,by=.001), size=500,replace=TRUE, prob=n28)

And I guess in retrospect this will get really ugly if you want, say, a sampling grid resolution of 1e-6 or so.

Anyone know what's applicable from the "sampling" package?

Carl

-------<quote>__________________

From: David Winsemius <dwinsemius_at_comcast.net> Date: Thu, 28 Apr 2011 13:06:21 -0400

On Apr 28, 2011, at 12:09 PM, Ravi Varadhan wrote:

> Surely you must be joking, Mr. Jianfeng.
>

Perhaps not joking and perhaps not with correct statistical specification.

A truncated Normal could be simulated with:

set.seed(567)
x <- rnorm(n=50000, m=1, sd=1)
xtrunc <- x[x>=0.2 & x <=0.8]
require(logspline)
plot(logspline(xtrunc, lbound=0.2, ubound=0.8, nknots=7))

-- 
David.





> -----Original Message-----

> From: r-help-bounces_at_r-project.org
[mailto:r-help-bounces_at_r-project.org
> ] On Behalf Of Mao Jianfeng

> Dear all,

>

> This is a simple probability problem. I want to know, How to

> generate a

> normal distribution with mean=1, min=0.2 and max=0.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 Thu 28 Apr 2011 - 22:40:02 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 29 Apr 2011 - 01:40:33 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