matlab mle function error for gev parameter fitness
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to study using mle function to fit the parameter. The normal distribution example passes but a more complex gev fitness is wrong. The codes are as follows
clear;
clc;
f=@normtest;
x=normrnd(0,1,[1000,1]);
pha=mle(x,'pdf',f,'Start',[0,1])
normfit(x)
f=@gev_test;
mle(x,'pdf',f,'start',[1 0 0])
function f=normtest(x,mu,sigma)
f=1/sigma/sqrt(2*pi)*exp(-(x-mu).^2/2/sigma^2);
end
function f=gev_test(x,k,mu,sigma)
t=(1+k*(x-mu)/sigma)^(-1/k);
f=1/sigma*t^(1+k)*exp(-t);
end
I am sure that the pdf of gev is right but there is some wrong with my code
0 comentarios
Respuestas (1)
Gandham Heamanth
el 11 de Jul. de 2023
Hi Jianyu, The code you provided seems to have a few issues. Here are the modifications you need to make:
1. In the code, the `mle` function is being used to fit the parameters for both the normal and GEV distributions. However, for the GEV distribution, you should use the `gevfit` function instead of `mle`. The `gevfit` function is specifically designed for fitting GEV parameters.
2. The `gevfit` function does not require a PDF function as an input. Instead, it directly fits the parameters to the data using the maximum likelihood estimation (MLE) method.
clear;
clc;
% Fit parameters for the normal distribution
x = normrnd(0, 1, [1000, 1]);
norm_params = normfit(x);
norm_params
% Fit parameters for the GEV distribution
x = normrnd(0, 1, [1000, 1]);
gev_params = gevfit(x);
gev_params
In the modified code, `normfit` is used to fit the parameters for the normal distribution, and `gevfit` is used to fit the parameters for the GEV distribution. The parameters are then stored in the variables `norm_params` and `gev_params`, respectively.
Note that the GEV distribution has three parameters: location (mu), scale (sigma), and shape (k). The `gevfit` function returns estimates for these parameters.
I removed the function definitions `normtest` and `gev_test` because they are not needed for fitting the parameters using the built-in functions.
I hope this helps! Let me know if you have any further questions.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!