n1<-20
p1<-0.5
x1<-9:12
red<-0:n1
probabilities1<-dbinom(red,size=n1,prob=p1)
barplot(probabilities1,names.arg=red, main=paste("Binomial Distribution (n=",n1,", p=",p1,")"),xlab="Number of Buyers Who Prefer Red", ylab="Probability")
q1<-sum(dbinom(x1,size = n1,prob=p1))
round(q1,4)
## [1] 0.6167
The probability that between 9-12 buyers would prefer red is 61.67%.
n2<-13
p2<-0.2
x2<-4:5
defective<-0:n2
probabilities2<-dbinom(defective,size = n2,prob = p2)
barplot(probabilities2,names.arg = defective,main=paste("Binomial Distribution (n=",n2,", p=",p2,")"),xlab="Number of Defective Light Bulbs", ylab="Probability",ylim=c(0,max(probabilities2)*1.1))
q2<-sum(dbinom(x2,size = n2,prob=p2))
round(q2,4)
## [1] 0.2226
The probability that between 3 and 6 bulbs in the sample are defective is 22.26%.
q3<-3
lambda3<-4.2
###Boundary so we can clearly see on the graph
max_x<-10
x_values<-0:max_x
probabilities3<-dpois(x_values,lambda = lambda3)
barplot(probabilities3,names.arg=x_values,main=paste("Poisson Distribution (lambda=",lambda3,")"),xlab="Number of Special Orders", ylab="Probability",ylim=c(0,max(probabilities3)+0.05))
round(ppois(q3,lambda = lambda3),4)
## [1] 0.3954
The probability that the number of special orders sent out is not more than 3 is 39.54%.
#### m = number of successes in population, n = number of failures in population, k = number of drawings in sample, x= number of successes in sample
###contamination = success
m4<-6
n4<-17-6
k4<-3
###probability that 0 or 1 bottles in sample would be contaminated
q4<-1
round(phyper(q4,m4,n4,k4,lower.tail = TRUE),4)
## [1] 0.7279
The probability that less than 2 of the tested bottles are contaminated is 72.79%.
###successes = employees over 50
m5<-6
n5<-19
k5<-6
x5<-1
round(phyper(x5,m5,n5,k5,lower.tail = FALSE),4)
## [1] 0.4529
The probability that more than 1 employee was over 50 is 45.29%.
mean6<-800
###standard deviation is the square root of the variance
sd6<-sqrt(90000)
curve(dnorm(x,mean = mean6,sd = sd6),from= 0, to = 2000, main="Distribution of Steer Weights",xlab = "Weight (lbs)", ylab = "Probability Density")
probability6<-pnorm(1460,mean = mean6, sd = sd6,lower.tail = TRUE)-pnorm(1040,mean = mean6, sd = sd6, lower.tail = TRUE)
round(probability6,4)
## [1] 0.198
The probability that a randomly selectedsteer is between 1040 and 1460 pounds is 19.80%.
mean7<-106
sd7<-4
curve(dnorm(x,mean = mean7,sd=sd7),from = 0, to = 200, main="Distribution of Ball Bearing Diameters",xlab="Diameters (in mm)",ylab="Probability Density")
probability7<-pnorm(111,mean = mean7,sd=sd7,lower.tail = TRUE)-pnorm(103,mean = mean7, sd=sd7, lower.tail = TRUE)
round(probability7, 4)
## [1] 0.6677
The probability that the diameter of the selected bearing is between 103 and 111 mm is 66.77%.
mean8<-3.34
sd8<-0.07
curve(dnorm(x,mean = mean8,sd=sd8),from =2, to = 5,main="Length of Nails",xlab = "Length (in cm)",ylab = "Probability Density")
top<-0.97
bottom<-1-top
probability_top<-qnorm(top,mean = mean8,sd=sd8)
probability_bottom<-qnorm(bottom,mean=mean8,sd=sd8)
round(probability_top,2)
## [1] 3.47
round(probability_bottom,2)
## [1] 3.21
The minimum length for the top 3% is 3.47cm. The maximum length for the bottom 3% is 3.21cm.
mean9<-75.8
sd9<-8.1
curve(dnorm(x,mean=mean9,sd=sd9),from = 45, to = 100,main="Psychology Grades", xlab = "Grades (%)",ylab="Probability Density")
A_Grade<-1-.09
round(qnorm(A_Grade,mean = mean9,sd=sd9),0)
## [1] 87
The minimum score required for an A grade is 87%.
n10<-155
p10<-0.61
mean10<-n10*p10
###sd formula: n*p*(1-p)
sd10<-sqrt(n10*p10*(1-p10))
x10<-96
round(dnorm(x10,mean = mean10,sd=sd10),4)
## [1] 0.0639
round(dbinom(x10,size = n10,prob = p10),4)
## [1] 0.064
probabilities10<-dbinom(0:n10,size = n10,prob = p10)
barplot(probabilities10,names.arg=0:n10, main = "Computer Crash Probability (Binomial Distribution)",xlab = "Number of Computers", ylab = "Probability")
curve(dnorm(x,mean=mean10,sd=sd10),from = 10, to = 155,main="Computer Crash Probability", xlab = "Number of Computers (Normal Distribution)",ylab = "Probability Density")
The probability that exactly 96 computers would not crash is 6.39% using a normal distribution and 6.40% using a binomial distribution.