[R] Random Sample with constraints

(Ted Harding) Ted.Harding at wlandres.net
Sun Mar 3 18:12:53 CET 2013


On 03-Mar-2013 16:29:05 Angelo Scozzarella Tiscali wrote:
> For example,  I want to simulate different populations with same mean and
> standard deviation but different distribution.
> 
> Il giorno 03/mar/2013, alle ore 17:14, Angelo Scozzarella Tiscali ha scritto:
>> Dear R friends,
>> 
>> I'd like to generate random sample (variable size and range) without a
>> specified distribution but with given mean and standard deviation.
>> 
>> Could you help me?
>> 
>> thanks in advance
>> Angelo

As Ben Bolker said, any random sample must come from some distribution,
so you cannot generate one without specifying some distribution.

Insofar as your question can be interpreted, it will be satisfied
if, given the desired mean, M, and SD, S, you take any two available
distributions with, respectively, known means M1 and M2 and known
SDs S1 and S2. Let X1 denote a sample from t5he first, and X2 a
sample from the second.

Then (X1 - M1)/(S1/S) is a sample from the first distribution
re-scaled to have mean M and SD S, as required.

Similarly, (X2 - M2)/(S2/S) is a sample from the second distribution
re-scaled to have mean M and SD S, as required.

As for what the first distribution that you sample from, and the second,
that can be at your own choice -- for eample, the first could be
the Standard Normal (M1 = 0, S1 = 1); use rnomr().
The second could be the uniform on (0,1) (M2 = 0.5, S2 = 1/sqrt(12));
use runif().

Similar for other arbitrary choices of first and second distribution
(so long as each has at least a second moment, hence excluding, for
example, the Cauchy distribution).

That's about as far as one can go with your question!

Hoping it helps, howevr.
Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 03-Mar-2013  Time: 17:12:50
This message was sent by XFMail



More information about the R-help mailing list