plot(x = 0:20, y = dbinom(x = 0:20, size = 20, prob = .5 ), type = ‘h’, main = ‘Binomial Distribution (n=20, p=0.5)’, ylab = ‘Probability’, xlab = ‘# Successes’, lwd = 3 )
dbinom(x=0:20, size=20, prob=.5) sum(dbinom(x=0:20, size=20, prob=.5)) round(x= sum(dbinom(x=9:12, size=20, prob=.5)), digits=4) # probability between ( and 12) dbinom(x=9:12, size=20, prob=.5) sum(dbinom(x=9:12,size=20, prob=.5))
#CDF Approach pbinom
pbinom(q=12, size=20, prob=.5,lower.tail = TRUE)-pbinom(q=8, size=20, prob=.5,lower.tail = TRUE)
pbinom(q=12, size=20, prob=.5,lower.tail = FALSE)-pbinom(q=8, size=20, prob=.5,lower.tail = FALSE)
#Note; I am getting the same value if i just change the lower.tail=FALSE for upper value. But your solution uses the reverse order for q value
#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?
#Sample size =13 #defective bulb % =20 #Probability >3 and <6 #Binomial Distribution plot(x = 0:13, y = dbinom(x =0:13, size = 13, prob = .2 ), type = ‘h’, main = ‘Binomial Distribution size n=13)’, ylab = ‘Probability’, xlab = ‘# Defective Successes’, lwd = 3 ) x<-(c(4,5)) dbinom(x,size=13,prob=.20,log=FALSE) dbinom sum(dbinom(x,13,.20)) round(x= sum(dbinom(x=4, size=13, prob=.2)), digits=4) ——————————-
plot(x = 0:10, y = dbinom(x=0:10, size = 13, prob = .2 ), type = ‘h’, main = ‘Binomial Probability)’, ylab = ‘Probability’, xlab = ‘# Defective Successes’, lwd = 3 ) x<-(c(4,5)) dbinom(x, size=13, prob=.20,log=FALSE)
sum(dbinom(x, size=13,prob=.20, log=FALSE)) round(x= sum(dbinom(x, size=13, prob=.2)), digits=4) #round(x= sum(dbinom(x=4, size=13, prob=.2)), digits=4)
#Note: I made a silly mistake(line44) corrected after i looked at your code
#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?
??poisson ## #P(X<=3)=P(X=0)+P(X=1)+P(X=2),+P(X=3)
#/lambda=4.2 #P(X=less than or equal to 3)
range=0:15
plot(x=range, y=dpois(x=range,lambda = 4.2), main = ‘Poisson Distribution (lambda = 4.2)’, ylab = ‘Probability’, xlab = ‘# Successes’, type = ‘h’, lwd = 3 )
sum(dpois(x=0.3,lambda = 4.2))
#Note: I am getting error Warning message: #In dpois(x = 0.3, lambda = 4.2) : non-integer x = 0.300000
round(dpois( x=range,lambda=4.2),digits = 4)
ppois(q=3,lambda=4.2,lower.tail = F) 1-ppois(q=3,lambda=4.2,lower.tail = F)
#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.
#mean=800 #sd=sqrt(90000) #sd install.packages(“ggplot2”) install.packages(“qqplotr”) library(ggplot2) library(qqplotr) PW<-pnorm(1040, mean=800, sd=sqrt(90000), lower.tail = FALSE) - pnorm(1460, mean=800, sd=sqrt(90000), lower.tail = TRUE) #ggplot(mapping = aes(Weigh = PW)) + stat_qq_point(size = 2) PW qqnorm(PW, ylab=“Weigh”, xlab=“Herd”, main=“weights of steers in a herd”) qqline(PW)
#- Above code is mine
#I am now trying with your (AS) solution
#x<-c(1040,1460)
sum(dnorm(x=1040:1460,mean=800,sd=300))
pnorm(q=1460, mean=800, sd=sqrt(90000)) - pnorm(q=1040, mean=800, sd=sqrt(90000))
#continous distribution, not discrete.
pnorm(q=1040, mean=800, sd=sqrt(90000), lower.tail = FALSE) - pnorm(q=1460, mean=800, sd=sqrt(90000), lower.tail = FALSE)
round(x=(pnorm(q=1460, mean=800, sd=sqrt(90000)) - pnorm(q=1040, mean=800, sd=sqrt(90000))),digits=4)
?seq() x <- seq(from = -4, to = 4, length = 1000) * 300 + 800
#create a vector of values that shows the height of the probability distribution for each value in x y <- dnorm(x = x, # argument = vector x created by seq() function mean = 800, sd = 300 )
#plot normal distribution with customized x-axis labels plot(x = x, y = y, type = “l”, lwd = 2, axes = FALSE, xlab = ““, ylab =”” )
sd_axis_bounds <- 5 axis_bounds <- seq(from = -sd_axis_bounds 300 + 800, to = sd_axis_bounds 300 + 800, by = 300) axis(side = 1, at = axis_bounds, pos = 0)
#— #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.
#mean=106 #sd=4 #P(X) between 103 and 111 data<-103:111 data
dnorm(x=data,mean=106,sd=4) sum(dnorm(x=data,mean=106,sd=4))
PW<-pnorm(q=111, mean=106, sd=4) - pnorm(q=103, mean=106, sd=4) PW ??diff diff(x=pnorm(c(103,111),mean=106,sd=4))
pnorm(q=103, mean=106, sd=4,lower.tail = F) - pnorm(q=111, mean=106, sd=4,lower.tail = F)
#use plot #change to density dnorm
#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.
mean=3.34 sd=0.07
qnorm(p=.03,mean=3.34,sd=0.07)
qnorm(p=0.97,mean=3.34,sd=0.07)
round(x=c(qnorm(p=0.03,mean=3.34,sd=0.07),qnorm(p=0.97,mean=3.34,sd=0.07)),digits=2)
qnorm(p=c(.03,.5,0.97),mean=3.34,sd=.07)
x <- seq(from = -4, to = 4, length = 1000) * .07 +3.34
#create a vector of values that shows the height of the probability distribution #for each value in x y <- dnorm(x, mean=3.34, sd=.7)
#plot normal distribution with customized x-axis labels plot(x,y, type = “l”, lwd = 2, axes = FALSE, xlab = ““, ylab =”“) sd_axis_bounds = 5 axis_bounds <- seq(from = -sd_axis_bounds .07 + 3.34, to = sd_axis_bounds .07 + 3.34, by = .07) axis(side = 1, at = axis_bounds, pos = 0)
#—–
#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.
#normally distributed
mean=75.8 sd=8.1
Agrd<-qnorm(p=.91,mean=75.8,sd=8.1) Agrd
round(x=Agrd,digits=0)
Bgrd<-qnorm(p=c(.91,.5,.37),mean=75.8,sd=8.1) Bgrd
round(x=Bgrd,digits=0)
Cgrd<-qnorm(p=c(.63,.5,.83),mean=75.8,sd=8.1) Cgrd
round(x=Cgrd,digits=0)
Dgrd<-qnorm(p=c(.17,.5,.92),mean=75.8,sd=8.1) Dgrd
round(x=Dgrd,digits=0)
Bottomgrd<-qnorm(p=.7,mean=75.8,sd=8.1) Bottomgrd
round(x=Bottomgrd,digits=0)
#————-
#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 probability using the normal distribution.
n=155 p=.61 q=1-0.61=0.39 MEAN<-np SD<-sqrt(p(1-p)*n)
dnorm(x=96,mean=.61155,sd=sqrt(.61(1-.61)*155))
??binomial dbinom(x=96,size=155,prob=.61) nd<-round(dbinom(x=96,size=155,prob=.61),digits = 4) nd