<< Tutorial Tutorial Beta >>

distfun >> distfun > Tutorial > Distribution Function Plots

Distribution Function Plots

A collection of distribution function plots.

Purpose

The goal of this document is to show pdf and cdf plots for different distribution functions of the distfun toolbox.

Normal distribution

Reference: Normal distribution. In Wikipedia, The Free Encyclopedia. (Retrieved 2014, February). from http://en.wikipedia.org/wiki/Normal_distribution

To make pdf plot, we can use the distfun_normpdf function.

mu = [0 0 0 -2];
sigma2 = [0.2 1.0 5.0 0.5];
cols = [1 2 3 4];
nf = size(cols,"*");
lgd = [];
scf();
for k = 1 : nf
x = linspace(-5,5,1000);
y = distfun_normpdf ( x , mu(k) , sqrt(sigma2(k)) );
plot(x,y)
str = msprintf("mu=%s, sigma^2=%s",..
string(mu(k)),string(sigma2(k)));
lgd($+1) = str;
end
h = gcf();
for k = 1 : nf
hk = h.children.children.children(nf - k + 1);
hk.foreground = cols(k);
end
legend(lgd);
xtitle("Normal PDF","x","y")

To make cdf plot, we can use the distfun_normcdf function.

mu = [0 0 0 -2];
sigma2 = [0.2 1.0 5.0 0.5];
cols = [1 2 3 4];
nf = size(cols,"*");
lgd = [];
scf();
for k = 1 : nf
x = linspace(-5,5,1000);
y = distfun_normcdf ( x , mu(k) , sqrt(sigma2(k)) );
plot(x,y)
str = msprintf("mu=%s, sigma^2=%s",..
string(mu(k)),string(sigma2(k)));
lgd($+1) = str;
end
h = gcf();
for k = 1 : nf
hk = h.children.children.children(nf - k + 1);
hk.foreground = cols(k);
end
xtitle("Normal CDF","x","$P(X\leq x)$");
legend(lgd);

Geometric distribution

Reference: Geometric distribution. In Wikipedia, The Free Encyclopedia. (Retrieved August 2012) from http://en.wikipedia.org/wiki/Geometric_distribution

To make pdf plot, we can use the distfun_geopdf function.

scf();
x = 0:10;
y = distfun_geopdf(x,0.2);
plot(x,y,"ro-");
y1 = distfun_geopdf(x,0.5);
plot(x,y1,"go-");
y2 = distfun_geopdf(x,0.8);
plot(x,y2,"bo-");
xtitle("Geometric PDF","x","P(x=x)");
legend(["pr=0.2","pr=0.5","pr=0.8"]);

The previous script produces the following output.

To make cdf plot, we can use the distfun_geocdf function.

x=(0:11)';
scf(); 
p1=distfun_geocdf(x,0.2);
p2=distfun_geocdf(x,0.5);
p3=distfun_geocdf(x,0.8);
distfun_plotintcdf(x,[p1,p2,p3],["r" "b" "g"],..
    ["pr=0.2" "pr=0.5" "pr=0.8"]);
xtitle("Geometric CDF")

The previous script produces the following output.

Binomial distribution

Reference: Binomial distribution. In Wikipedia, The Free Encyclopedia. (Retrieved August 2012), from http://en.wikipedia.org/wiki/Binomial_distribution

To make pdf plot, we can use the distfun_binopdf function.

scf();
N1 = 20;
x = 0:N1;
y1 = distfun_binopdf(x,N1,0.5);
plot(x,y1,"bo-")
N2 = 20;
x = 0:N2;
y2 = distfun_binopdf(x,N2,0.7);
plot(x,y2,"go-")
N3 = 40;
x = 0:N3
y3 = distfun_binopdf(x,N3,0.5);
plot(x,y3,"ro-")
legend(["pr=0.5, N=20","pr=0.7, N=20","pr=0.5, N=40"]);
xtitle("Binomial PDF","x","P(x)")

To make cdf plot, we can use the distfun_binocdf function.

scf();
x = (0:20)';
p1=distfun_binocdf(x,20,0.5);
p2=distfun_binocdf(x,20,0.7);
p3=distfun_binocdf(x,40,0.5);
legendspec=["pr=0.5, N=20","pr=0.7, N=20","pr=0.5, N=40"];
distfun_plotintcdf(x,[p1,p2,p3],["b" "g" "r"],legendspec);
xtitle("Binomial CDF")

Chi-Square distribution

Reference: Chi-Square distribution. In Wikipedia, The Free Encyclopedia. (Retrieved August 2012), from http://en.wikipedia.org/wiki/Chisquare_distribution

To make pdf plot, we can use the distfun_chi2pdf function.

h=scf();
k = [2 3 4 6 9 12];
cols = [1 2 3 4 5 6];
lgd = [];
for i = 1:size(k,'c')
   x = linspace(0,10,1000);
   y = distfun_chi2pdf ( x , k(i) );
   plot(x,y)
   str = msprintf("k=%s",string(k(i)));
   lgd($+1) = str;
end
for i = 1:size(k,'c')
    hcc = h.children.children;
    hcc.children(size(k,'c') - i + 1).foreground = cols(i);
end
xtitle("Chi-square PDF","x","f(x)")
legend(lgd);

To make cdf plot, we can use the distfun_chi2cdf function.

h=scf();
k = [2 3 4 6 9 12];
cols = [1 2 3 4 5 6];
lgd = [];
for i = 1:size(k,'c')
  x = linspace(0,10,1000);
  y = distfun_chi2cdf ( x , k(i) );
  plot(x,y)
  str = msprintf("k=%s",string(k(i)));
  lgd($+1) = str;
end
for i = 1:size(k,'c')
    hcc = h.children.children;
    hcc.children(size(k,'c') - i + 1).foreground = cols(i);
end
xtitle("Chi-square CDF","x","f(x)")
legend(lgd);

Poisson distribution

Reference: Poisson distribution. In Wikipedia, The Free Encyclopedia. (Retrieved August 2012), from http://en.wikipedia.org/wiki/Poisson_distribution

To make pdf plot, we can use the distfun_poisspdf function.

scf();
x = 0:20;
y = distfun_poisspdf(x,1);
plot(x,y,"ro-");
y1 = distfun_poisspdf(x,4);
plot(x,y1,"go-");
y2 = distfun_poisspdf(x,10);
plot(x,y2,"bo-");
xtitle("Poisson PDF","x","P(X=x)");
legend(["lambda=1","lambda=4","lambda=10"]);

To make cdf plot, we can use the distfun_poisscdf function.

h=scf();
x=(0:20)';
p1=distfun_poisscdf(x,1);
p2=distfun_poisscdf(x,4);
p3=distfun_poisscdf(x,10);
legendspec=["lambda=1","lambda=4","lambda=10"];
distfun_plotintcdf(x,[p1,p2,p3],["r" "g" "b"],legendspec);
xtitle("Poisson CDF")
h.children.children(1).legend_location="in_lower_right";

Extreme Value (Gumbel) distribution

Reference: Gumbel distribution. In Wikipedia, The Free Encyclopedia. (Retrieved 2014, January 19) from http://en.wikipedia.org/wiki/Gumbel_distribution

Notice that Matlab and the distfun toolbox use the Minimum Gumbel distribution, while Wikipedia present the max-Gumbel distribution.

To make pdf plot, we can use the distfun_evpdf function.

N=1000;
x=linspace(-20,5,N);
y1= distfun_evpdf(x,-0.5,2.);
y2= distfun_evpdf(x,-1.0,2.);
y3= distfun_evpdf(x,-1.5,3.);
y4= distfun_evpdf(x,-3.0,4.);
scf();
xtitle("Gumbel","x","Density");
plot(x,y1,"r-")
plot(x,y2,"g-")
plot(x,y3,"b-")
plot(x,y4,"c-")
leg(1)="$\mu=-0.5,\beta=2.0$";
leg(2)="$\mu=-1.0,\beta=2.0$";
leg(3)="$\mu=-1.5,\beta=3.0$";
leg(4)="$\mu=-3.0,\beta=4.0$";
legend(leg,"in_upper_left");

To make cdf plot, we can use the distfun_evcdf function.

N=1000;
x=linspace(-20,5,N);
p1= distfun_evcdf(x,-0.5,2.,%t);
p2= distfun_evcdf(x,-1.0,2.,%t);
p3= distfun_evcdf(x,-1.5,3.,%t);
p4= distfun_evcdf(x,-3.0,4.,%t);
scf();
xtitle("Gumbel","x","P(X<x)");
plot(x,p1,"r-")
plot(x,p2,"g-")
plot(x,p3,"b-")
plot(x,p4,"c-")
leg(1)="$\mu=-0.5,\beta=2.0$";
leg(2)="$\mu=-1.0,\beta=2.0$";
leg(3)="$\mu=-1.5,\beta=3.0$";
leg(4)="$\mu=-3.0,\beta=4.0$";
legend(leg,"in_upper_left");


Report an issue
<< Tutorial Tutorial Beta >>