# how to generate a normal distribution with mean=1, min=0.2, max=0.8

12 messages
Open this post in threaded view
|
Report Content as Inappropriate

## how to generate a normal distribution with mean=1, min=0.2, max=0.8

 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? I know how the generate a normal distribution of mean = 1 and sd = 1 and with 500 data point. rnorm(n=500, m=1, sd=1) But, I am confusing with how to generate a normal distribution with expected min and max. I expect to hear your directions. Thanks in advance. Best, Jian-Feng,         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 Surely you must be joking, Mr. Jianfeng. ------------------------------------------------------- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: [hidden email] -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Mao Jianfeng Sent: Thursday, April 28, 2011 12:02 PM To: [hidden email] Subject: [R] how to generate a normal distribution with mean=1, min=0.2, max=0.8 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? I know how the generate a normal distribution of mean = 1 and sd = 1 and with 500 data point. rnorm(n=500, m=1, sd=1) But, I am confusing with how to generate a normal distribution with expected min and max. I expect to hear your directions. Thanks in advance. Best, Jian-Feng,         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 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. > ------------------------------------------------------- > Ravi Varadhan, Ph.D. > Assistant Professor, > Division of Geriatric Medicine and Gerontology School of Medicine   > Johns Hopkins University > > Ph. (410) 502-2619 > email: [hidden email] > > > -----Original Message----- > From: [hidden email] [mailto:[hidden email] > ] On Behalf Of Mao Jianfeng > Sent: Thursday, April 28, 2011 12:02 PM > To: [hidden email] > Subject: [R] how to generate a normal distribution with mean=1,   > min=0.2, max=0.8 > > 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? > > I know how the generate a normal distribution of mean = 1 and sd = 1   > and > with 500 data point. > > rnorm(n=500, m=1, sd=1) > > But, I am confusing with how to generate a normal distribution with   > expected > min and max. I expect to hear your directions. > > Thanks in advance. > > Best, > Jian-Feng, > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. > > ______________________________________________ > [hidden email] 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. David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

Open this post in threaded view
|
Report Content as Inappropriate

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

 In reply to this post by Mao Jianfeng 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 -------__________________ From: David Winsemius 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?  > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 Good point.  It would be absurdly inefficient if the upper and lower limits on the interval of interest were, say, 0.2 and 0.201 instead of 0.2 and 0.8.  Here's what I think is probably the best general approach: Compute the CDF for the upper and lower limits of the interval and generate uniform random numbers within that range of CDF values, then compute the inverse CDF of those values.  To be explicit: n <- 1000 L <- .2 U <- .8 p_L <- pnorm(L) p_U <- pnorm(U) x <- qnorm(runif(n, p_L, p_U)) It is very fast and it always produces exactly the desired number ("n") of random normal values. Mike -- Michael B. Miller, Ph.D. Bioinformatics Specialist Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota On Thu, 28 Apr 2011, Carl Witthoft wrote: > 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 > > -------__________________ > From: David Winsemius > 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? > >> > > ______________________________________________ > [hidden email] 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. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 I just realized that I had misread what was wanted -- the code I wrote was for mean=0, sd=1, not for mean=1.  So for mean=m, and sd=s, lower limit L and upper limit U, this approach will work: n <- 1000 m <- 1 s <- 1 L <- .2 U <- .8 p_L <- pnorm(L, mean=m, sd=s) p_U <- pnorm(U, mean=m, sd=s) x <- qnorm(runif(n, p_L, p_U), mean=m, sd=s) Or it could be written on one line: x <- qnorm(runif(n, pnorm(L, mean=m, sd=s), pnorm(U, mean=m, sd=s)), mean=m, sd=s) Mike On Thu, 28 Apr 2011, Mike Miller wrote: > Good point.  It would be absurdly inefficient if the upper and lower > limits on the interval of interest were, say, 0.2 and 0.201 instead of > 0.2 and 0.8. Here's what I think is probably the best general approach: > > Compute the CDF for the upper and lower limits of the interval and > generate uniform random numbers within that range of CDF values, then > compute the inverse CDF of those values.  To be explicit: > > n <- 1000 > L <- .2 > U <- .8 > > p_L <- pnorm(L) > p_U <- pnorm(U) > > x <- qnorm(runif(n, p_L, p_U)) > > It is very fast and it always produces exactly the desired number ("n") > of random normal values. > > Mike > > -- > Michael B. Miller, Ph.D. > Bioinformatics Specialist > Minnesota Center for Twin and Family Research > Department of Psychology > University of Minnesota > > > > On Thu, 28 Apr 2011, Carl Witthoft wrote: > >> 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 >> >> -------__________________ >> From: David Winsemius >> 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? >> >>> >> >> ______________________________________________ >> [hidden email] 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. >> > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

Open this post in threaded view
|
Report Content as Inappropriate

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

 On Fri, 29 Apr 2011, Giovanni Petris wrote: > Well, but the original poster also refers to 0.2 and 0.8 as "expected > min and max", in which case we are back to a joke... Well, he is a lot better with English than I am with Mandarin.  He seemed to like the truncated normal answers, so we'll let those be his answers. It is possible to choose parameters for a normal distribution with 500 observations such that the expected value of the maximum is .8 and the expected value of the minimum is .2.  Obviously, the mean would be .5, not 1, but what would the variance then have to be to provide the correct expected max and min?  That's another legitimate question. Mike >>> -----Original Message----- >>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Mao Jianfeng >>> Sent: Thursday, April 28, 2011 12:02 PM >>> To: [hidden email] >>> Subject: [R] how to generate a normal distribution with mean=1, min=0.2, max=0.8 >>> >>> 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? >>> >>> I know how the generate a normal distribution of mean = 1 and sd = 1 >>> and with 500 data point. >>> >>> rnorm(n=500, m=1, sd=1) >>> >>> But, I am confusing with how to generate a normal distribution with >>> expected min and max. I expect to hear your directions. >>> >>> Thanks in advance. >>> >>> Best, >>> Jian-Feng, ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 On Apr 29, 2011, at 1:29 PM, Mike Miller wrote: > On Fri, 29 Apr 2011, Giovanni Petris wrote: > >> Well, but the original poster also refers to 0.2 and 0.8 as   >> "expected min and max", in which case we are back to a joke... > > Well, he is a lot better with English than I am with Mandarin.  He   > seemed to like the truncated normal answers, so we'll let those be   > his answers. > > It is possible to choose parameters for a normal distribution with   > 500 observations such that the expected value of the maximum is .8   > and the expected value of the minimum is .2.  Obviously, the mean   > would be .5, not 1, but what would the variance then have to be to   > provide the correct expected max and min?  That's another legitimate   > question. You would need to specify an N since the expected first and last order   statistic would decrease/increase with increasing N. -- David. > > Mike > > >>>> -----Original Message----- >>>> From: [hidden email] [mailto:[hidden email] >>>> ] On Behalf Of Mao Jianfeng >>>> Sent: Thursday, April 28, 2011 12:02 PM >>>> To: [hidden email] >>>> Subject: [R] how to generate a normal distribution with mean=1,   >>>> min=0.2, max=0.8 >>>> >>>> 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? >>>> >>>> I know how the generate a normal distribution of mean = 1 and sd   >>>> = 1 and with 500 data point. >>>> >>>> rnorm(n=500, m=1, sd=1) >>>> >>>> But, I am confusing with how to generate a normal distribution   >>>> with expected min and max. I expect to hear your directions. >>>> >>>> Thanks in advance. >>>> >>>> Best, >>>> Jian-Feng, David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

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

 On Fri, 29 Apr 2011, David Winsemius wrote: > On Apr 29, 2011, at 1:29 PM, Mike Miller wrote: > >> On Fri, 29 Apr 2011, Giovanni Petris wrote: >> >>> Well, but the original poster also refers to 0.2 and 0.8 as "expected min >>> and max", in which case we are back to a joke... >> >> Well, he is a lot better with English than I am with Mandarin.  He seemed >> to like the truncated normal answers, so we'll let those be his answers. >> >> It is possible to choose parameters for a normal distribution with 500 >> observations such that the expected value of the maximum is .8 and the >> expected value of the minimum is .2.  Obviously, the mean would be .5, >> not 1, but what would the variance then have to be to provide the >> correct expected max and min?  That's another legitimate question. > > You would need to specify an N since the expected first and last order > statistic would decrease/increase with increasing N. Right -- I chose N=500, as did the OP.  I think the order statistics for the normal are pretty complex, but it wouldn't be hard to use the density for order statistics for the uniform to compute the appropriate values for a standard normal, then rescale. http://en.wikipedia.org/wiki/Order_statistic#The_order_statistics_of_the_uniform_distributionYou'd have to multiply the beta density times the inverse normal cdf and get the weighted average for a set of points.  It doesn't sound terribly difficult but I don't want to do it!  ;-) Mike ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.