fit a log 'raised cosine' distribution on univariate data in matlab
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have one dimensional data like data (saved in .txt). My objective is to fit the probability density function (pdf) and cumulative distribution function (cdf) of a log 'raised cosine' distribution (as described in https://en.wikipedia.org/wiki/Raised_cosine_distribution) to this univariate data.
I estimated parameters using mle and wrote short function to implement equation given for raised cosine distribtuion. I obtained fitted output to my data but I am not able to show fitted curve as it should be. I think It should appear as lognormal type curve approximately.
Could you help me to find pdf, cdf and mistake in codes. I attached data, code, function for reference. I also attached result of the fit and expected fit as well.
Thanks
% Code to plot PDF and CDF of pebbles data.
clc
clear
close all
% load data
data= readmatrix('data');
% Aim is to fit log-‘raised cosine’ distribution (https://en.wikipedia.org/wiki/Raised_cosine_distribution)
% fitting parameters (can be guessed using mle)
custlogpdf=@(data,mu,s)...
(1 / (2 * s)) * (1 + cos(pi * (data - mu) / s))
start = [mean(data),std(data)]
[paramEsts,paramCIs] = mle(data,'pdf',custlogpdf,'Start',start, ...
'LowerBound',[-Inf 0]);
% parameters
mu=paramEsts(1);
s=paramEsts(2);
%% This equation of pdf form is coded in lograisedcosinepdf function file.
% y = 1 ./ (2 * s) * (1 + cos(pi * (x - mu) ./ s));
x=data;
y = lograisedcosinepdf(x,mu,s);
histogram(x,'Normalization','pdf')
xgrid = linspace(min(x),max(x), size(x,1))';
hold on
plot(xgrid,y,'-')
xlabel('data')
ylabel('Probability Density')
legend('Sample Data','Fitted pdf','Location','northeast')
hold off
The expected plot-![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1613336/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1613336/image.png)
0 comentarios
Respuestas (1)
Jeff Miller
el 11 de Feb. de 2024
I think the problem is here:
y = lograisedcosinepdf(x,mu,s);
Since you are plotting xgrid versus y, I think you want
y = lograisedcosinepdf(xgrid,mu,s);
0 comentarios
Ver también
Categorías
Más información sobre Generalized Extreme Value Distribution en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!