GEOG 172, Fall 2007

Lab Assignment 2

The goal in lab this week is to gain some familiarity with the R language for statistical computing. The initial lab session will introduce you to basic features of R (log window, interactive session, batch submission, math operators, and storage) as well as using R to query results from statistical distributions. After the brief introduction in the lab, you will be on your own to answer the questions below.

I.Probability questions and R for basic calculations

  1. Write a brief script to carry out the following mathematical operations:

X=5

Y=4+3X

Print X

Print Y

Z=5/52

Print Z

X=1, 2,…,20

Y=4+3X

Plot X (horizontal axis) against Y (vertical axis)

For B, C, and D write out the calculation first by hand and then check your work using R as a calculator.

  1. Suppose you have a standard deck of 52 playing cards and you draw three cards without replacement. What is the probability of drawing at a Jack of any suite on one of the three draws?
  2. What is the probability of drawing three Jacks in three draws, again drawing without replacement? What if you were drawing with replacement?
  3. What is the probability of drawing three Jacks such that the three suites do not include the Jack of diamonds if you are drawing without replacement?

II.Binomial distribution and statistical tables in R: The questions below are all variants that can be answered using the binomial distribution. For questions A and B write out the structure of the answer by hand and use the pbinom or dbinom functions in R to calculate the answers. In C and D just write down the necessary R code and the answer.

  1. Based on long-term observational studies we know that the current influenza vaccine is 70% effective in preventing the worst symptoms in non-high-risk populations. That is, if you get the vaccine there is 70% chance you will not get the flu and 30% you will still get it. Suppose that after the flu season we follow-up on 15 individuals that received their flu shot. What is the probability that exactly 8 will have had the flu?
  2. Suppose we have a new vaccine and we give it to 15 people and 80% do not get the flu. What is the probability that 80% or more would not have had the flu using the old vaccine?
  3. Suppose instead we administered the new vaccine to 100 people and the “prevention rate” was 72 percent. Does that provide strong evidence that the new vaccine is more effective? Exactly how strong (or weak) is the evidence for that assertion?
  4. How much stronger would the evidence be if we achieved the same prevention rate among 10,000 people?

III.Normal distribution: Use pnorm or dnorm to answer the following questions. Draw a rough sketch of the distribution in each case showing the area under the curve that is being assessed, write down the answer, and write down the R code used to generate the answer.

Probability that a normal random variable with mean 22 and variance 25:

  1. lies between 16.2 and 27.5
  2. is greater than 29
  3. is less than 17
  4. is less than 15 or greater than 25
  1. Plotting data and histograms:
  1. Enter the following commands to generate a plot of the standard normal density function.

x<-seq(-4.5,4.5,.1)

normden<-dnorm(x,mean=0,sd=1)

plot(x,normden,type=”l”) [note: that is a lower case “L” in the quotes]

  1. Enter the following commands to generate a plot of the binomial probability mass function.

x<-c(1:30)

plot(x,dbinom(x,size=3-,prob=.15),type=”h”)

  1. Suppose your star free throw shooter has a career average of 80 percent. He has gone to the free throw line 10 times (attempted 20 shots) during the game and has only sunk 8 of his baskets. What is the probability that he would hit 8 or fewer baskets in 20 attempts from the line? Plot the probability mass function histogram and interpret the results.