Lab 4 Objectives:

In this lab, we will use S-Plus to calculate probabilities of events for random variables distributed as binomial, Poisson, and normal. We follow Section 7.5 so that we can verify our calculations


Binomial Probabilities

Start S-Plus and prepare your workspace as you see fit (see lab 1). If the Commands window is not already open, open it using the tool bar button that looks like

>
> x|

or use the menus: Window>Commands Window; make sure there is a check mark next to Commands Window. We will use the function dbinom() ("d" for probability "d"ensity (really should be "m" for "mass" in this case, since binomial is discrete)). This gives P(X=x) for X ~ Bin(n,p). The example on page 186 asks for probabilities from Bin(5, .3). In S-Plus Commands window, to find P(X=0), type

> dbinom(0, 5, .3)

All of the calculations on page 186:

> dbinom(c(0,1,2,3,4,5), 5, .3)

We can use pbinom() ("p" for cumulative "p"robability) to calculate probability statements like on page 187. For example, P(X >= 3) = 1 - P(X <= 2) is

> 1 - dbinom(2,5,.3)

We could have done it as:

> sum(dbinom(c(3,4,5),5,.3))

Let's make a plot of the Bin(5,.3) distribution (corresponding to Table 7.2, page 187, POB). Open a new data sheet by selecting Data > Select Data... and selecting Source New Data and typing, for example, binom7.2 for New Data Name. Press OK and a new graph sheet will appear. Name the first column x (or k as in the book) and second column, say, px. Type 0,1,2,3,4,5 as the values of x. You may want to change the data type of x to integer. We want to enter P(X=x) into the second column. Choose Data>Transform... from the menu and choose px as the Target Column and, for Expression, type pbinom(x,5,.3). Press OK. Now Graph>2D Plot... and in the Insert Graph dialog box choose High Density Line Plot(x,y1,y2,...) as the Plot Type. Leave other entries as they are and press OK. Now, for x Columns, type x and, for y Columns, type px. You may want to make the plot line thicker by modifying options from the Line tab. Press OK. The result is the graphical version of Table 7.2.

Poisson Probabilities

Now we'll calculate some Poisson probabilities for X ~ Pois(2.5) as on pages 187-188. Use the function dpois() to calculate P(X=x) for various values of x. For example,

> dpois(c(0,1,2,3,4,5),2.5)

Also, use ppois() for calculating the 2 cumulative Poisson probabilities at the bottom of page 188, POB:

> 1 - ppois(c(3,5), 2.5)

Get it? If you want, graph the Pois(2.5) distribution for x= 0,1,2,3,4,5,6,7 using the same procedure as we used for the binomial. Otherwise, let's move on to calculating normal probabilities.

Normal Probabilities

We'll use the function pnorm() for calculating normal probabilities as on pages 189-191. Note that the function dnorm() gives normal "d"ensity values, not probabilities. First, a standard normal probability calculation:

> diff(pnorm(c(-3,3)))

Does this remind you of the empirical rule? Note that we do not have to standardize by hand when using pnorm(). For example, for the N(63.9,2.6^2) calculation on page 191 we have

> diff(pnorm(c(60,68), 63.9, 2.6))

Now, let's find the 95th percentile (quantile) of the normal distribution N(63.9,2.6^2) using the quantile function:

> qnorm(.95, 63.9, 2.6)

Experiment with the above functions for the binomial, Poisson, and normal distributions. Be sure that you can do all of the above calculations (binomial, Poisson, normal) using the tables in the appendix of POB.