Lab
Lab

Reputation: 11

Fitting the cumulative distribution function using MATLAB

How is it possible to make the following data more fitted when i will plot using Cumulative_distribution_function?

here is my code, plotted using the cdfplot

clear all; 
close all;
y = [23 23 23 -7.59 23 22.82 22.40 13.54 -3.97 -4.00 8.72 23 23 10.56 12.19 23 9.47 5.01 23 23 23 23 22.85 23 13.61 -0.77 -14.15 23 12.91 23 20.88 -9.42 23 -1.37 1.83 14.35 -8.30 23 15.17 23 5.01 22.28 23 21.91 21.68 -4.76 -13.50 14.35 23]
cdfplot(y)

Upvotes: 0

Views: 3425

Answers (2)

rozsasarpi
rozsasarpi

Reputation: 1641

There is no definite answer to your question, it is too broad and mainly belongs to statistics. Before doing any computation you should answer some questions:

  • is there a specific distribution type which the data follow?
  • is there any theoretical justification to select a distribution type and discard others?
  • do I need parametric or non-parametric distribution?
  • if no specific distribution type can be selected than what set of distributions should I investigate?
  • how to compare the distributions, goodness-of-fit measures?
  • what fitting method should I use, e.g. max-likelihood, method of moments, Bayesian, etc.?
  • how to treat uncertainties?
  • how and for what want I use the results?
  • etc.

Without answering these question it is meaningless to talk about fitting distribution to data. I give you an example how to do the fit in Matlab using maximum-likelihood method, just for illustration, but I would strongly discourage you to use it without considering the above points.

Since I have no additional background information in respect of the nature of the data, normal and kernel distributions are fitted to illustrate 1 parametric and 1 non-parametric distribution.

cdfplot(y)
hold on
xx = -20:40;
%normal distribution
pd_norm = fitdist(y', 'normal');

F_norm = normcdf(xx, pd_norm.mu, pd_norm.sigma);
plot(xx, F_norm, 'r')

%kernel distribution
pd_kernel1 = fitdist(y', 'kernel', 'Kernel', 'normal', 'Width', 6);

F_kernel1 = cdf(pd_kernel1, xx);
plot(xx, F_kernel1, 'g')

%kernel distribution
pd_kernel2 = fitdist(y', 'kernel', 'Kernel', 'normal', 'Width', 2);

F_kernel2 = cdf(pd_kernel2, xx);
plot(xx, F_kernel2, 'black')

legend('ecdf', 'normal', 'kernel1', 'kernel2', 'Location', 'NorthWest')

enter image description here

Upvotes: 2

Kostya
Kostya

Reputation: 1572

You can try

h = cdfplot(y)
cftool( get(h,'XData'), get(h,'YData') )

Upvotes: 1

Related Questions