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

5 vues (au cours des 30 derniers jours)
amit k le 10 Fév 2024
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
% 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-
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Jeff Miller le 11 Fév 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Generalized Extreme Value Distribution dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by