Assignment 3-distribution

Author

Allison Shrivastava

  1. A researcher wishes to conduct a study of the color preferences of new car buyers. Suppose that 50% of this population prefers the color red. If 20 buyers are randomly selected, what is the probability that between 9 and 12 (both inclusive) buyers would prefer red?
## this is binomial distribution

## start with a plot of the distribution
plot(9:12 ,dbinom(9:12,20,.50),
     type='h',
   ylab="",
     xlab="",
     lwd=5)

#now calculate the probability     
sum(dbinom(9:12, size=20, prob=0.5))
[1] 0.6167
  1. A quality control inspector has drawn a sample of 13 light bulbs from a recent production lot. Suppose 20% of the bulbs in the lot are defective. What is the probability that less than 6 but more than 3 bulbs from the sample are defective?
## this is binomial distribution

## start with a plot
plot(3:6 ,dbinom(3:6,13,.20),
     type='h',
   ylab="",
     xlab="",
     lwd=5)

## now calculate the probability
sum(dbinom(3:6, size=13, prob=0.20))
[1] 0.4913
  1. The auto parts department of an automotive dealership sends out a mean of 4.2 special orders daily. What is the probability that, for any day, the number of special orders sent out will be no more than 3?
# this is a poisson distribution

## start with a plot
plot(0:3, dpois(0:3, lambda = 5),
     type='h',
      ylab="",
     xlab="",
     lwd=5)

# then calculate the probability
sum(dpois(0:3, lambda = 4.2))
[1] 0.3954
  1. A pharmacist receives a shipment of 17 bottles of a drug and has 3 of the bottles tested. If 6 of the 17 bottles are contaminated, what is the probability that less than 2 of the tested bottles are contaminated?
## notes to keep track of work
# 17 bottles
# 3 bottles tested
# if 6 of 17 are contaminated,whats the prob less than 2 of the 3 tested are as well

# this is a hypergeometric distribution as the bottles aren't being replaced (fixed sample from which 3 bottles are being pulled)

#probability
dhyper(0,6,17-6,3)+dhyper(1,6,17-6,3)
[1] 0.7279
# set graph values
x4<-0:3
prob<-dhyper(x4,6,17-6,3)

#plot
barplot(prob, names.arg=x4,
        col=cols,
      ylab="",
     xlab="")
Warning in rect(y1, x1, y2, x2, ...): supplied color is neither numeric nor
character

  1. A town recently dismissed 6 employees in order to meet their new budget reductions. The town had 6 employees over 50 years of age and 19 under 50. If the dismissed employees were selected at random, what is the probability that more than 1 employee was over 50?

    # 6 employees gone
    # 6 employees over 50 
    # 19 employees under 50
    # 56 employees total
    # whats the probability that 1 or more employee is over 50
    # this is a hypergeometric probability since the employees are not being replaced
    
    # start with the probability as vectors need to be defined to plot
    x5<-2:6
    probability2<-sum(dhyper(x5, 6,25-6,6))
    probability2
    [1] 0.4529
    #plot
    barplot(x5, probability2, 
          ylab="",
         xlab="",
         lwd=1)

  1. The weights of steers in a herd are distributed normally. The variance is 90,000 and the mean steer weight is 800 lbs. Find the probability that the weight of a randomly selected steer is between 1040 and 1460 lbs.

    #this is a normal distribution
    ## the standard deviation is the square root of the variance, which we are given
    
    # set values
    x<-seq(0,2000)
    y<-dnorm(x, 800, sqrt(90000))
    
    # plot 
    plot(x,y,  type="l", lwd=1,
         xlab="",
         ylab="")

    # calculate probability
    pnorm(1460, 800, sqrt(90000))-pnorm(1040, 800, sqrt(90000))
    [1] 0.198
  1. The diameters of ball bearings are distributed normally. The mean diameter is 106 millimeters and the standard deviation is 4 millimeters. Find the probability that the diameter of a selected bearing is between 103 and 111 millimeters.
#this is a normal distribution

# set values
x2<-seq(0,200, by=1)
y2<-dnorm(x2, 106, 4)

# plot
plot(x2,y2,type="l", lwd=4,
     xlab="",
     ylab="")

# calculate probability
pnorm(111, 106, 4)-pnorm(103, 106, 4)
[1] 0.6677
  1. The lengths of nails produced in a factory are normally distributed with a mean of 3.34 centimeters and a standard deviation of 0.07 centimeters. Find the two lengths that separate the top 3% and the bottom 3%. These lengths could serve as limits used to identify which nails should be rejected.
## calculate a range for the plot
x3<-seq(3.34-5*0.07, 3.34+5*0.07, length.out=1000)
y3<-dnorm(x3, 3.34,0.07)

# plot
plot(x=x3,y=y3, type="l", lwd=2,
 xlab="",
     ylab="")

## find the lengths
qnorm(0.03,3.34,.07)
[1] 3.208
qnorm(0.97,3.34,.07)
[1] 3.472
  1. A psychology professor assigns letter grades on a test according to the following scheme. A: Top 9% of scores B: Scores below the top 9% and above the bottom 63% C: Scores below the top 37% and above the bottom 17% D: Scores below the top 83% and above the bottom 8% F: Bottom 8% of scores Scores on the test are normally distributed with a mean of 75.8 and a standard deviation of 8.1. Find the minimum score required for an A grade. Round your answer to the nearest whole number, if necessary
# notes to keep track
# mean is 75.8
# standard deviation is 8.1
# looking for minimum score for top 9% ie, the 91st percentile

# find minimum score
round(qnorm(0.91, mean=75.8, sd=8.1))
[1] 87
# set values
x5<-seq(30, 150, length=200)
y5<-dnorm(x5, mean=75.8, sd=8.1)

# plot
plot(x5, y5, type="l",
      xlab="",
     ylab="")

# add a line to show where the 91st percentile is
abline(v=round(qnorm(0.91, mean=75.8, sd=8.1)))

  1. Consider the probability that exactly 96 out of 155 computers will not crash in a day. Assume the probability that a given computer will not crash in a day is 61%. Approximate the (binomial) probability using the normal distribution.
# notes to keep track
# p=0.61 will not crash 
# n=155
# lower bounds are 95.6, upper is 96.5
# sd=sqrt(n*p*(1-p))
# approximation formula = pnorm(upper, mean, standard dev)-pnorm(lower,  mean, standard dev)


meandef<-155*0.61
sddef<-sqrt(155*0.61*(1-0.61))

## set values for the graph, ensure large enough to capture all values
x6<-seq(meandef-4*sddef, meandef+4*sddef, length=200)
y6<-dnorm(x6, mean=meandef, sd=sddef)

plot(x6,y6, type="l", lwd=3,
        xlab="",
     ylab="")

pnorm(96.5,mean=meandef, sd=sddef)- pnorm(95.5,mean=meandef,sd=sddef)
[1] 0.06378