[Return to Sta113 Home]

STA113: Lab 2 (Friday, September 10, 2004)

In this lab, we will use Matlab to calculate and plot probabilities of various discrete probability distributions we discussed in class.

At the beginning of the lab period, Floyd will go over two very short topics not covered in lecture: (1) determining a pdf from a cdf for a generic discrete random variable, and (2) reading binomial cdf tables such as those on pp. 736-8 of your text. This will take about five minutes. If you have questions on either of these topics after that short presentation, ask one of the TAs in the lab for help.


Binomial Probabilities


Geometric Distribution

Let's draw Geometric probability distributions for p=0.3 and p=0.7.

y1 = geopdf(0:9, 0.3);
y2 = geopdf(0:9, 0.7);
h1 = stem(1:10, y1, 'o');
    % h = stem(...) returns handles to three line graphics objects:
    % h(1) - the marker symbol at the top of each stem
    % h(2) - the stem line
    % h(3) - the base line

hold on; % add new plot to the existing axes
h2 = stem(1:10, y2, 'x');
set(gca, 'XLim', [0.5 10.5]);
legend([h1(1),h2(1)], {'p=0.3','p=0.7'}) 
title('Geometric Probability Distributions');
hold off; % release the current Figure window for new plots

Summary of Commands for Discrete Distributions

Today 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 each distribution are listed below:

(The following three distributions will be covered in future classes and labs.)

Go to help page for more details about these commands.

Check Your Mastery of These Distributions

Work out solutions to the following problems using MatLab, referring back to the earlier sections in this web page as little as possible. They are designed to check your understanding of the two distributions covered in this lab,to check your skills in using MatLab to work with the distributions, and also to foreshadow future topics in STA113. You do not need to turn your answers in. These problems are for you to check your own mastery and understanding. If you have difficulty answering the questions, ask one of the TAs for help.

  1. A class of students is interested in whether anyone in the class can tell the difference between Coke and Pepsi by taste. They conduct a study in which each student is presented with three identical-looking cups labeled A, B, and C. One of the cups contains one drink and the other two contain the other drink. The drink that occurs only once is selected at random, as is the cup it goes in. The students are to taste the three drinks and identify which cup contains a different drink from the other two. They do not need to name the drinks. There are 30 students in the class. Let X (a random variable) be the number of students who correctly identify the cup containing the different drink.

  2. A young, healthy couple who are trying to have a baby have a probability of about 1 in 6 of getting pregnant during any given month in which pregnancy has not already occurred. Let X (a random variable) be the number of months that have passed before the woman gets pregnant. (So X = 0 would mean she got pregnant during the first month.)