Yi
2010-Sep-02 06:17 UTC
[R] How to generate integers from uniform distribution with fixed mean
Hi, folks, runif (n,min,max) is the typical code for generate R.V from uniform dist. But what if we need to fix the mean as 20, and we want the values to be integers only? Thanks [[alternative HTML version deleted]]
Barry Rowlingson
2010-Sep-02 07:16 UTC
[R] How to generate integers from uniform distribution with fixed mean
On Thu, Sep 2, 2010 at 7:17 AM, Yi <liuyi.feier at gmail.com> wrote:> Hi, folks, > > runif (n,min,max) is the typical code for generate R.V from uniform dist. > > But what if we need to fix the mean as 20, and we want the values to be > integers only?It's not clear what you want. Uniformly random integers with expected mean 20 - but what range? Any range centred on 20 will work, for example you could use sample() with replacement. To see the distribution, use sample() table(sample(17:23,10000,TRUE)) which gives a uniform distribution of integers from 17 to 23, so the mean is 20.0057 for 10000 samples. Is that what you want? Barry
Reasonably Related Threads
- How to predict the mean and variance of the dependent variable after regression
- count data with a specific range
- Verify the linear regression model used in R ( fundamental theory)
- Help on calculating spearman rank correlation for a data frame with conditions
- Variance of the prediction in the linear regression model (Theory and programming)