Question
((using R progrem do the following )) 1. Binomial distribution. Let X be binomially distributed with n = 60 and p = 0.4. Compute the
((using R progrem do the following ))
1. Binomial distribution. Let X be binomially distributed with n = 60 and p = 0.4. Compute the following. (a) P(X = 24), P(X 24), and P(X 30). (b) P(20 X 30), P(20 X). 90 CHAPTER 3. IMPORTANT PROBABILITY DISTRIBUTIONS (c) P(20 X or X 40), and P(20 X and X 10). (d) The mean and standard deviation of X. (e) The quantiles x0.025, x0.5, and x0.975.
((script)) # 3.1 Discrete distributions # 3.1.1 Bernoulli distribution # 3.1.2 Binomial distribution
# Example 1. Load the TeachingDemos package... # install.packages("TeachingDemos") # Note that TeachingDemos requires XQuartz from www.xquartz.org on the Mac. library(TeachingDemos) vis.binom()
# Example 2. If we cross two heterozygous carriers... choose(3,1)* 0.25^1* 0.75^2
for (k in 0:3) { print(dbinom(k,3,0.25)) }
pbinom(2,3,0.25)
# Example 3. After four coin tosses, we can.... pbinom(2,4,0.50) # binomial cumulative distribution function (CDF)
# Example 4. microRNA consists of a sequence composed of nucleotides A, G, U, and C,... dbinom(14, 22, 0.7) pbinom(13, 22, 0.7)
sum(dbinom(11:22, 22, 0.7)) 1 - pbinom(10, 22, 0.7)
x <- 0:22 plot(x, # X-values dbinom(x,size=22,prob=.7), # binomial mass function type="h", # histogram col="blue", lwd=4, # make lines thicker xlab="x", ylab="Binomial probability mass function f(x)", cex.lab=1.5) # make axis labels big
binomialCDF = stepfun(x, c(0,pbinom(x,size=22,prob=.7))) # create a step function from binomial CDF plot(binomialCDF, # binomial cumulative function col="red", vertical=FALSE, lwd=4, # make lines thicker xlab="x", ylab="Binomial cumulative distribution function F(x)", main=NULL, cex.lab=1.5) # make axis labels big)
rbinom(1000, 22, 0.7) # 3.1.3 Poisson distribution
# Poisson approximating the binomial lambda=4 plot(x, # X-values dpois(x,lambda),# Poisson density function type="h", # histogram col=1, lwd=8, # make lines thicker ylim=c(0,0.25), # range of the y-axis xlab="x", ylab="Density function f(x)", cex.lab=1.5) # make axis labels big for (counter in 1:10) { lines(x, dbinom(x, size=counter*10, prob=lambda/(counter*10)), col=counter+1, lwd=2) } legend("topright", lty=rep(1,11), lwd=rep(2,11), col=1:11, legend=c(expression(Poisson(lambda == 4)), as.expression(sapply(seq(10,100, 10), function(x) bquote(B(n ==.(x), p == 4/.(x)))))))
# Example 1. Teaching demo vis.binom()
# Example 2. Daily Lottery exp(-2)*2^0/factorial(0) dpois(0,2)
exp(-2)*2^1/factorial(1) dpois(1,2)
x <- 0:20 plot(x, # X-values dpois(x,5), # Poisson mass function type="h", # histogram col="blue", lwd=4, # make lines thicker xlab="x", ylab="Poisson probability mass function f(x)", cex.lab=1.5) # make axis labels big
poissonCDF = stepfun(x, c(0,ppois(x,5))) # create a step function from poisson CDF plot(poissonCDF, # poisson cumulative function col="red", vertical=FALSE, lwd=4, # make lines thicker xlab="x", ylab="Poisson cumulative distribution function F(x)", main=NULL, cex.lab=1.5) # make axis labels big)
# Example 3. Finding k-mers exp(-3.9)*2^0/factorial(0) dpois(0,3.9)
1 - dpois(0,3.9)
# Example 4. Gaps in an open reading frame exp(-5)*5^2/factorial(2) dpois(2,5)
ppois(3,5)
y <- rpois(10000,5) # 1000 random samples with lambda=5 mean(y) var(y)
qpois(c(0.025,0.975), lambda=5, lower.tail = TRUE)
sum(dpois(1:10,5)) # 3.2 Continuous distributions # 3.2.1 Exponential distribution
# Example 1. Suppose that lambda=5 pexp(.5,5)
f <-function(x) { dexp(x,5) } plot(f, # function to plot 0, # first x-value 2, # last x-value xlab="x", ylab="Expontential mass function f(x)", cex.lab=1.5) # make axis labels bigger x1 <- seq(0,0.5,.1) # set of magenta x-values x2 <- seq(0.5,2,.1) # set of blue x-values polygon(c(0,x1,.5), c(0,f(x1),0), col="magenta") polygon(c(.5,x2,2), c(0,f(x2),0), col="lightblue") arrows(0.75,2.5,0.25,1.6, lwd=3, col="green") text(0.86, 2.7 - c(0,0.7), cex = 1.2, adj=c(0,0), col="blue", c(expression(P(X <= 0.5)), expression(paste(" = ", integral(f(x) * dx, 0, 0.5)))))
F <- function(x) { pexp(x,5) } plot(F, # function 0, # start x 2, # end x cex.lab=1.5, # make axis labels big col="red", lwd=6, # make line thicker xlab="x", ylab="Exponential cumulative distribution function F(x)") mtext("0.92",side=2,at=0.92, col="red") arrows(0.8,0.6,0.5,0.9, lwd=3, col="green") text(0.65, 0.5 - c(0,.11,.22,.33,.44), cex=1.2, adj=c(0,0), col="blue", c(expression(P(X <= 0.5)), expression(paste(" = ", integral(f(x) * dx, 0, 0.5))), expression(paste(" = ", bgroup("[", F(x) ,"]")[0]^0.5)), expression(paste(" = ", CDF(0.5))), expression(paste(" = ", 0.92))))
1-pexp(2,5)
pexp(2,5)-pexp(.25,5)
qexp(c(0.025,0.975), rate = 5, lower.tail = TRUE, log.p = FALSE) pexp(0.737775891,5)-pexp(0.005063562,5)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started