0

I am using the command wblrnd(12.34,1.56) to get 100 different values that lie within the Weibull distribution with those parameters.

But I want those 100 points/values to have the same distribution as the one given by the parameters. Which doesn't happen.

Basically I want, to get 100 values that give me the exact same distribution I had before.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
João Sousa
  • 13
  • 1
  • 2
  • Do you really want to draw Weibull distributed random numbers or do you just want to plot the Weibull pdf that corresponds to these given parameters? If the latter, you should use `wblpdf` instead. – H.Muster Jun 06 '13 at 15:12
  • I really need the numbers. wblpdf gives me back the probability of a certain value and not the value itself. To be more specific. This is a daily distribution for mean speeds of wind. And I want to know the mean speed of those 100 days. That is, 1 day had a mean speed of 12 knots 2 days had a mean speed of 8 knots and so on – João Sousa Jun 06 '13 at 15:42
  • @JoãoSousa, a pdf for a continuous r.v. does not give a probability, rather it is a measure of probability intensity (it is a derivative of a probability). Sorry to nitpick. – SecretAgentMan Oct 18 '18 at 03:53

5 Answers5

4

You cannot have the same distribution as the one you're sampling from, unless the number of draws you perform is infinite.

To give you a practical example you can compare how the empirical distribution of your draws, i.e. the histogram, matches the fitted pdf:

subplot(121)
sample = wblrnd(12.34,1.56,100,1);    
histfit(sample,100,'wbl')
title('100 draws')

subplot(122)
sample = wblrnd(12.34,1.56,1e5,1);    
histfit(sample,100,'wbl')
title('100,000 draws')

enter image description here

Also, note that the mean and standard deviations are NOT the arguments of wblrnd(A,B). In other words, mean(sample) is not supposed to converge to 12.34.

You can check on wikipedia: weibull distribution how to retrieve the mean from the shape and scale parameters, i.e. what theoretical mean is given by 12.34 and 1.56.

Oleg
  • 10,406
  • 3
  • 29
  • 57
  • 1
    Re: mean and variance of the Weibull distribution - you can use: `[M,V] = wblstat(A,B)`. – horchler Jun 06 '13 at 23:56
  • What if I create an array with, let's say 100.000 values form the sample = wblrnd(12.34,1.56,1e5,1). Then I run monte carlo simulation where for each iteration 100 points are chosen and a histfit(sample,100,'wbl') is done.Then the goodness of each fit is calculated. And the best goodness is chosen. By the way how can I do the goodness of fit of a histfit?Does anybody know? – João Sousa Jun 07 '13 at 10:21
  • Following your lead @Olag I did a mini-monte carlo I got to a sample with the same approximate mean, var and weibull parameters as the initial ones [M,V] = wblstat(12.5,1.8); M=roundsd(M,4); V=roundsd(V,4); sample=wblrnd(12.5,1.8,1e5,1); for i=1:5e6 index=randperm(1e5,88); for j=1:size(index,2) s(j)=sample(index(j)); end if M==roundsd(mean(s),4) if V==roundsd(var(s),4) break end end end – João Sousa Jun 07 '13 at 15:36
1

It may be useful for future seekers to use the new Probability Distribution Objects in MATLAB. This highlights utility of makedist(), random(), and pdf() functions (though others work too). See documentation.

You can define the probability distribution object first (shown below with output).

>> pd = makedist('Weibull',12.34,1.56)
pd = 
  WeibullDistribution

  Weibull distribution
    A = 12.34
    B =  1.56

Then obtaining the theoretical mean(), median(), std(), or var() is easy.

>> mean(pd)
ans =
   11.0911
>> var(pd)
ans =
   52.7623
>> median(pd)
ans =
    9.7562

Then generating random variates is simple with the random() command.

n = 2500;    
X = random(pd,n,1);

Weibull Distribution

Note: Probability Distribution Objects introduced in R2013a.

figure, hold on, box on
histogram(X,'Normalization','pdf','DisplayName','Empirical (n = 2500)')
plot([0:.01:50],pdf(pd,[0:.01:50]),'b-','LineWidth',2.5,'DisplayName','Theoretical')  

Reference: Weibull distribution

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
0

Would using rand('seed',0); before your command correct your problem?

m_power
  • 3,156
  • 5
  • 33
  • 54
0

According to wblrnd documentation to obtain 100 values that follow a Weibull distribution with parameters 12.34 and 1.56 you should do:

wind_velocity = wblrnd(12.34 , 1.56 , 1 , 100);

This returns a vector of 1x100 values, from day 1 to 100.
To obtain the average velocity of those 100 days do:

mean(wind_velocity)

Hope this is what you need.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
R. Schifini
  • 9,085
  • 2
  • 26
  • 32
0

If instead of obtaining random points you actually want to specify a probability (between zero and one) and get a value from a Weibull distribution with parameters A and B, what you want is the inverse CDF:

X = wblinv(P,A,B)

This is actually what wblrnd is based on (it's a technique called inverse sampling and is commonly used for generating random variates from many distributions). In wblrnd, P = rand(...) effectively. However, if you want to choose probabilities by some other method, wblinv permits you to obtain the values of X that correspond to any P (where P(X) is the probability distribution function, or PDF).

horchler
  • 18,384
  • 4
  • 37
  • 73