Fitting a Cauchy or Laplace distribution
Show older comments
I've been using fitdist, to fit the best student-t and gaussian to my input data and would like to extend this to include the laplace and cauchy distribution, how could I do this?
student = fitdist(M,'tlocationscale');
I've tried something like
nbins = 150;
h = histogram(M,nbins,'Normalization','pdf');
q = h.BinLimits;
x = linspace(q(1),q(2),nbins);
y = h.Values;
gaussEqn2 = 'a*exp(-(abs(x-b)/c))';
startPoints = [-0.05 0 0.05];
f2 = fit(x',y',gaussEqn2, 'Start', startPoints);
But it fits me essentially straight lines over the data with huge errors, it works if I normalise the histogram to probability, but not to pdf, which is what I should do
Answers (1)
Martin Lindfors
on 14 Apr 2017
Edited: Martin Lindfors
on 14 Apr 2017
For Laplace:
The density of a Laplace variate is given by
p(x|m, b) = exp(-abs(x-m)/b)/b * const.
Equivalently, if you have N independent samples x_1, ..., x_N, your log-probability density of all the samples is
log p(x_1, ..., x_N | m, b) = -sum_k (abs(x_k - m)/b) - N log(b), where the sum is for k = 1, ..., N.
Then it can be seen that the maximum likelihood estimator for b, if you know m, is just b = sum_k (abs(x_k - m))/N. Furthermore, the maximum likelihood estimator for m is just the sample median.
Thus, the ML estimator for b is actually the mean absolute deviation from the median. https://en.wikipedia.org/wiki/Median_absolute_deviation
function [m, b] = fitLaplace(x)
m = median(x);
b = mean(abs(x-m));
end
Categories
Find more on t Location-Scale Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!