Mao Jianfeng
2011-Apr-28 16:01 UTC
[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]]
Ravi Varadhan
2011-Apr-28 16:09 UTC
[R] 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: rvaradhan at jhmi.edu -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Mao Jianfeng Sent: Thursday, April 28, 2011 12:02 PM To: r-help at r-project.org 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]] ______________________________________________ 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.
David Winsemius
2011-Apr-28 17:06 UTC
[R] 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: rvaradhan at jhmi.edu > > > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org > ] On Behalf Of Mao Jianfeng > Sent: Thursday, April 28, 2011 12:02 PM > To: r-help at r-project.org > 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]] > > ______________________________________________ > 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. > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Carl Witthoft
2011-Apr-28 22:37 UTC
[R] how to generate a normal distribution with mean=1, min=0.2, max=0.8
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? >
Giovanni Petris
2011-Apr-29 14:34 UTC
[R] how to generate a normal distribution with mean=1, min=0.2, max=0.8
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... Giovanni On Thu, 2011-04-28 at 13:06 -0400, David Winsemius wrote:> 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: rvaradhan at jhmi.edu > > > > > > -----Original Message----- > > From: > r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org > > ] On Behalf Of Mao Jianfeng > > Sent: Thursday, April 28, 2011 12:02 PM > > To: r-help at r-project.org > > 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]] > > > > ______________________________________________ > > 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. > > > > ______________________________________________ > > 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. > > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > 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. > >-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/
Maybe Matching Threads
- nonparametric densities for bounded distributions
- how to substitute missing values (NAs) by the group means
- split a character variable into several character variable by a character
- how to plot two histograms overlapped in the same plane coordinate
- failed when merging two dataframes, why