My question is about estimating a normal distribution for a row of points of an interval that are extracted from the data, just knowing the maximum (xmax = 200) and minimum (xmin = 100), to distribute them randomly by an average and an associated standard deviation that we will estimate.
Is there a method in Matlab, or the literature to do it, such that when you draw the associated law, we must not exceed the xmin and xmax values?
I used this trick:
x = xmin + rand (1, n) * (xmax-xmin);but I do not know how to extract the parameters of the normal distribution (the mean, the standard deviation).
1 Answer
First, you'll want to use randn for a normal distribution - rand will draw from a uniform distribution.
Calling randn(1,n) will return n normally distributed samples from the standard distribution with mean of zero and a variance (standard deviation squared) of one. To change the mean of this distribution to an arbitrary x and the standard deviation to y, simply do x + y*randn(1,n).
If you expect the mean to be, say, 150 and the standard deviation to be 25, you would accomplish this as follows:
>> stddev = 25;
>> xmin = 100;
>> xmax = 200;
>> xmean = 150;
>> n = 10000;
>> out = xmin + ( (xmean-xmin) + stddev * randn(1,n) );And you can verify that mean(out) and std(out) are approximately 150 and 25, respectively. However - for a large n and a sufficiently large stddev, you are pretty much guaranteed to get some samples less than xmin and some greater than xmax. You can set these back to your limits in just a couple lines:
>> out( out<xmin ) = xmin;
>> out( out>xmax ) = xmax;or just remove those entries entirely (so the length of out will be less than n):
>> out( out<xmin | out>xmax ) = []; 0