[Return to Sta113 Home]

Sta113: Lab4 (Friday, January 31, 2003)


Poisson Distribution

In Lab 3, we learned three kinds of Matlab commands related with discrete distributions: They are commands for Probability Density Functions (ending with pdf), for Cumulative Distribution Functions (ending with cdf) and for Mean and Variance (ending with stat). The corresponding commands for Poisson distribution are:

 poisspdf, poisscdf, poisstat 
In class we learned that Binomial(n,p) can be approximated by Poisson(lambda) with lambda = np , when n is very large. Let us check the approximation.
x = 0:12;
y1 = poisspdf(x, 4);  % calculate the Poisson probabilities with
                      % parameter 4 at values 0 to 12 
stem(x, y1, 'o', 'fill');
hold on;
n=25;
y2 = binopdf(x, n, 4/n);
plot(x+0.3, y2,'+r'); % shift the x-coordinate by 0.3, and then draw the
                      % Binomial probabilities in 'r'ed and marked by '+'
hold off;
Try different values of n, for example, try n=75 and 100. See how the approximation is getting better and better.

Commands for Continuous Distributions

For continuous distributions, Matlab provides commands for Probability Density Functions (ending with pdf), for Cumulative Distribution Functions (ending with cdf) and for Mean and Variance (ending with stat). Here is the website I often go to find commands for distributions:

http://www.mathworks.com/access/helpdesk/help/toolbox/stats/stats.shtml

The probability distributions are listed on the left.

Read the description for distributions and especially pay attention to description on the parameters. For example, the parameters for Weibull distribution used in Matlab are a and b, while the textbook uses beta and alpha. To draw the hazard function for Weibull distribution with alpha = 2 and beta = 2, type

t=0:0.1:3;
h = weibpdf(t, 1/2, 2)./(1-weibcdf(t, 1/2, 2)); % returns the hazard function
plot(t, h, '-');