R has several functions built-in that can be used to calculate probabilities associated with known probability distributions. When in doubt, don’t forget that you can always type help(“function”) into the console for documentation! For example, help(dbinom) might help for problem 1.

Question 1

You flip an unbalanced coin 100 times. The probability that the coin lands on heads is 0.3. Using the dbinom() function in R, calculate the probability that the coin lands on the heads side exactly 30 times out of the possible 100.

# CODE FOR QUESTION GOES HERE
dbinom(30, size=100, prob=0.3)
## [1] 0.08678386

ANSWER 0.08678386

Question 2

You are teaching a class of eighty students. From experience, you know the probability that any one student passes the course is 0.95. Further, you assume that one student passing is independent from any other student passing. Using the pbinom() function in R, calculate the probability that the number of students (out of eighty) that fail the course is greater than or equal to five students.

# 1 - pbinom(4, 80, .05)

0.3711202

Question 3

Use the rbinom() function to create a vector of 10 random observations from the binomial distribution with n=100 and probability of success is equal to 0.4. In this situation, we’d like there to be 10 random draws from a distribution that has 100 trials, meaning you flip a coin 100 times, 10 different times. - Calculate the mean and standard deviation statistics for this vector of random draws using the mean() and sd() commands. - How do these numbers compare the mean and standard deviation of the binomial distribution when \(n = 100\) and \(p = 0.4\)? If they are different, why? Hint: if \(X \sim B(n,p)\), then \(\mu = np\) and \(\sigma = \sqrt{np(1-p)}\). - Make a histogram of this vector using the hist() command.

# Code for question 3 Goes Here
#r= rbinom(100, 10, .4)
#mean(r) mean
#39.87 
#sqrt(var(r)) sd
#4.858467

#B.
#n * p ;mean
#4
#sqrt(n* p* (1- p)) ;sd
#1.549193

#C.
#hist(r)

ANSWERS a. rbinom(100, 10, .4) = [1] 7 4 4 4 4 4 5 6 7 6 3 2 5 6 2 1 7 2 4 4 6 2 3 3 6 3 [27] 4 3 5 8 4 5 3 5 4 4 5 8 2 2 2 3 4 3 4 5 6 3 3 3 6 5 [53] 4 1 5 5 4 4 4 6 5 7 5 5 2 4 6 4 4 4 4 3 6 2 3 4 3 4 [79] 2 3 4 6 4 4 5 3 5 4 4 2 1 3 4 4 3 5 4 3 6 2

mean ; 39.87

sd; 4.858467

  1. mean; 4 sd; 1.549193 The mean and standard deviation I got from the random number and bionomical distribution are not the same

  2. hist(r)

Question 4

Repeat question 3 but with 1,000 random draws. Comment on how the new sample mean compares to the population mean and the old sample mean. How does the histogram differ?

# r= rbinom(1000, 100, .4)

#a.
#mean(r) 
#sqrt(var(r))

#b.
#n * p 
#sqrt(n* p* (1- p))

#c.
#hist(r)

ANSWERS a. mean ; 39.87 sd; 4.858467

  1. mean; 40 sd; 4.898979 The mean and standard deviation I got from the random number and bionomical distribution are the same

  2. hist(r)

Question 5

Use the pnorm() function in R to verify the empirical rule. Note that pnorm(x) calculates left tail probability of the standard normal distribution for \(x\). - 68% of observations are within 1 standard deviation of the mean - 95% of observations are within 2 standard deviations of the mean - 99.7% of observations are within 3 standard deviations of the mean

# pnorm(1, 0, 1)- pnorm(-1, 0, 1)
# pnorm(2, 0, 1)- pnorm(-2, 0, 1)
# pnorm(3, 0, 1)- pnorm(-3, 0, 1)

ANSWER For a standad normal distribution, mean = 0 and standard deviation = 1

  1. 68% data lies between -1 and +1 0.6826895 or about 68%

  2. 95% data lies between -2 and +2 0.9544997 or about 95%

  3. 99.7% data lies between -3 and +3 0.9974 or approximately 99.7%

Question 6

You and a friend take a statistics exam. The teacher tells you the exam grades were normally distributed with a mean of 72 and a standard deviation of 8. Your friend seems happy about their exam, but they won’t tell you their exact score. Instead they tell you that their grade is in the top 1% of all grades. Using the qnorm() function, calculate what their grade must be.

# qnorm(.01, 72, 8)

ANSWER 53.38922