obelix
obelix

Reputation: 890

Sample mean and variance of a Weibull distribution sample

Let's suppose that I have a random sample x from a Weibull distribution with shape parameter k=1 and scale parameter λ=2.
How am I supposed to compute the mean value of the sample? Also what can I do to compute the variance of the sample?

I would also appreciate any helpful Matlab code able to perform the aforementioned tasks.

Upvotes: 0

Views: 1408

Answers (3)

SecretAgentMan
SecretAgentMan

Reputation: 2854

Referencing the wiki page for the Weibull Distribution, these can be directly computed for the distribution. See wiki for formulas.

k = 1;          % shape parameter
lambda = 2;     % scale parameter

Wmeanh =@(k,lambda) lambda*gamma(1 + (1/k));    % Mean
Wvarh =@(k,lambda) (lambda^2)*(gamma(1+(2/k)) - (gamma(1+(1/k)))^2); % Variance

Now to test these anonymous function handles out on our parameters...

>> Wmeanh(k,lambda)
ans =
     2
>> Wvarh(k,lambda)
ans =
     4

And we can verify our formulas are correct and show that our answers agree.

% Test against alternate method
pd = makedist('Weibull',lambda,k)
mean(pd)
var(pd)

Below we generate samples from this distribution with different sample sizes and collect the sample mean and sample variance. This demonstrates how to get this from a sample and that our previous calculations appear correct.

N = [10 30 90 270 810 2430 7290]';
SampleMEAN = zeros(size(N));
SampleVAR = zeros(size(N));
for i = 1:length(N)
    ni = N(i);
    Xi = random(pd,ni,1);
    SampleMEAN(i) = mean(Xi);
    SampleVAR(i) = var(Xi);
end
T = table(N,SampleMEAN,SampleVAR)

Upvotes: 0

Luis Mendo
Luis Mendo

Reputation: 112679

Just use

mean(sample(:))

and

var(sample(:))

where sample is an array of numbers.

The (:) part is used to turn the array sample into a vector. You can omit that if sample is already a vector.

Note that this computes the sample mean and sample variance of your data (not the true mean and variance of the distribution).

Upvotes: 2

user1197918
user1197918

Reputation:

Random numbers for Weibul distribution with scale parameter λ and shape parameter k:

Numbers = wblrnd(λ,k);

To compute the mean

mean(Numbers(:));

To compute the variance

var(Numbers(:));

Upvotes: 1

Related Questions