Clear Filters
Clear Filters

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

5 views (last 30 days)
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 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.
% Code to plot PDF and CDF of pebbles data.
close all
% load data
data= readmatrix('data');
% Aim is to fit log-‘raised cosine’ distribution (
% fitting parameters (can be guessed using mle)
(1 / (2 * s)) * (1 + cos(pi * (data - mu) / s))
custlogpdf = function_handle with value:
start = [mean(data),std(data)]
start = 1×2
6.3061 2.2614
[paramEsts,paramCIs] = mle(data,'pdf',custlogpdf,'Start',start, ...
'LowerBound',[-Inf 0]);
% parameters
%% This equation of pdf form is coded in lograisedcosinepdf function file.
% y = 1 ./ (2 * s) * (1 + cos(pi * (x - mu) ./ s));
y = lograisedcosinepdf(x,mu,s);
xgrid = linspace(min(x),max(x), size(x,1))';
hold on
ylabel('Probability Density')
legend('Sample Data','Fitted pdf','Location','northeast')
hold off
The expected plot-

Answers (1)

Jeff Miller
Jeff Miller on 11 Feb 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);

Community Treasure Hunt

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

Start Hunting!