fit a log 'raised cosine' distribution on univariate data in matlab

5 ビュー (過去 30 日間)
amit k
amit k 2024 年 2 月 10 日
回答済み: Jeff Miller 2024 年 2 月 11 日
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))
custlogpdf = function_handle with value:
@(data,mu,s)(1/(2*s))*(1+cos(pi*(data-mu)/s))
start = [mean(data),std(data)]
start = 1×2
6.3061 2.2614
[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-

回答 (1 件)

Jeff Miller
Jeff Miller 2024 年 2 月 11 日
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);

Community Treasure Hunt

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

Start Hunting!

Translated by