indu mann
indu mann

Reputation: 63

getting empirical distribution of a variable in matlab?

I am trying to get the empirical distribution of two different series, p and q.

I used the syntax [f1,x]=ecdf(p) and [f2,x]=ecdf(q). Although these are two completely different series, they produce the same values for f1 and f2. I guess it is because of the matlab generated node points, x which is chosen by default and is same for the two series. What is the correct way of generating ecdf?

With p and q defined as follow:

p=[3.827880237 3.843230114 3.832979798 3.814851094 3.798070125 3.793802374 3.790420184 3.758288905 3.703854270 3.699633917 3.722435113 3.685122405 3.671987586 3.677439264 3.673511977 3.706842154 3.69299597];

q=[3.832763324 3.848230872 3.835789699 3.819249605 3.802654468 3.801538272 3.800867956 3.763986927 3.711618941 3.703275334 3.744550651 3.688129173 3.673511977 3.681603045 3.679081612 3.716737782 3.702782359];

Upvotes: 0

Views: 401

Answers (1)

R.Falque
R.Falque

Reputation: 944

You overwrite your x that are different, if you use the following code you will have different curves.

[f1,x1]=ecdf(p);
[f2,x2]=ecdf(q);

figure; plot(f1, x1, 'b', f2, x2, 'r');

The cumulative distribution are different as expected:

enter image description here

Upvotes: 1

Related Questions