# Maximum likelihood fitting for the r Largest Order Statistics

조회 수: 2 (최근 30일)
Yi Lun 2024년 3월 15일
답변: Sudarsanan A K 2024년 3월 15일
MATLAB Community,
I using the MLE to finding Gumble distribution parameters for the r Largest Order Statistics.
I already have the likelihood function,which is:
L=@(mu,sigma) prod( exp(-exp( - ( data2 (:,size ( data 2,2 ) ) -mu ./ sigma ))) .*prod( sigma^( -1).*exp( -( data2 - mu )./sigma),2))
where data2 is a 40*5 matrix, meaning I picking 1st to 5th largest data in one year for total 40 years.
(if data2 is a 40*1 matrix, L become the Gumble distribution likelihood function.)
The matlab code mle() can only input vector, is there any way to solve this problem?

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Sudarsanan A K 2024년 3월 15일
Hello Yi Lun,
To estimate the parameters of a Gumbel distribution using MATLAB's "mle" function for multidimensional data, such as your 40x5 matrix, you can follow this streamlined approach:
• Reshape Your Data: Convert your matrix into a vector since "mle" is designed for vector inputs. This treats each element in your matrix as an independent observation.
data2 = randn(40, 5); % Example data, replace with your actual data
dataVector = reshape(data2, [], 1); % Reshape your 40x5 matrix into a vector
• Define the Likelihood Function: Adjust the likelihood function for the Gumbel distribution to work with your reshaped vector data. The likelihood function for the Gumbel distribution, with parameters μ (location) and σ (scale), is given by:
• Define the Negative Log-Likelihood Function: For the Gumbel distribution, define a custom negative log-likelihood function. It's important to include "varargin" in your function definition to handle any additional arguments passed by "mle".
% Define the custom negative log-likelihood function for the Gumbel distribution
nloglf = @(params, data, varargin) -sum(log((1./params(2)) .* exp(-(data-params(1))./params(2) - exp(-(data-params(1))./params(2)))));
• Estimate Parameters Using "mle": With your data vector and the negative log-likelihood function ready, use "mle" to estimate the parameters. You'll need to provide initial guesses for the parameters.
% Specify initial parameter guesses
initialParams = [mean(dataVector), std(dataVector)]; % Example initial guesses
% Use mle to estimate parameters, specifying the custom nloglf and initial guesses
paramsEst = mle(dataVector, 'nloglf', nloglf, 'start', initialParams);
% Extract the estimated parameters
mu_est = paramsEst(1);
sigma_est = paramsEst(2);
fprintf('Estimated mu: %f\n', mu_est);
Estimated mu: -0.514545
fprintf('Estimated sigma: %f\n', sigma_est);
Estimated sigma: 1.041869
To validate the estimates, comparison between the empirical Cumulative Distribution Function (CDF) of your original data and the theoretical CDF of a Gumbel distribution using parameters estimated from that data can be done as follows:
% mu_est, sigma_est are your estimated parameters
% Generate Gumbel distributed values using estimated parameters
gumbelVals = mu_est - sigma_est * log(-log(rand(size(dataVector))));
% Plot empirical CDF
[f_empirical, x_empirical] = ecdf(dataVector);
plot(x_empirical, f_empirical, 'b-', 'LineWidth', 1.5); hold on;
% Plot theoretical CDF using estimated parameters
[f_theoretical, x_theoretical] = ecdf(gumbelVals);
plot(x_theoretical, f_theoretical, 'r--', 'LineWidth', 1.5);
legend('Empirical CDF', 'Theoretical CDF', 'Location', 'best');
xlabel('Value');
ylabel('Cumulative Probability');
title('Empirical vs Theoretical Gumbel Distribution');
grid on; hold off;
For further understanding of the critical functions used in this example, refer to the following documentations:
I hope this helps!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Probability Distributions에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by