#####Distributions#####
################################
###4 successes###
dbinom(4, size=12, prob=0.2)
####<=4 successes####
# Suppose there are twelve multiple choice questions in an
# English class quiz. Each question has five possible answers,
# and only one of them is correct. Find the probability of having
# four or less correct answers if a student attempts to answer every question at
# random.
dbinom(0, size=12, prob=0.2) +
dbinom(1, size=12, prob=0.2) +
dbinom(2, size=12, prob=0.2) +
dbinom(3, size=12, prob=0.2) +
dbinom(4, size=12, prob=0.2)
pbinom(4, size=12, prob=0.2)
rbinom(10,100,0.2)
################################
# If there are twelve cars crossing a bridge per minute on average,
# find the probability of having seventeen or more cars
# crossing the bridge in a particular minute.
ppois(16, lambda=12) #sixteen or less cars
ppois(16, lambda=12, lower=FALSE) #17 or more cars
qpois(0.899, lambda = 12)
rpois(12,lambda = 12)
ppois(3,12)
pbinom(3,1000,0.012)
################################
runif(10, min=1, max=3)
################################
# Assume that the test scores of a college entrance exam fits a normal distribution.
# Furthermore, the mean test score is 72, and the standard deviation is 15.2.
# What is the percentage of students scoring 84 or more in the exam?
pnorm(84, mean=72, sd=15.2, [Link]=FALSE)
1-pnorm(84,72,15.2)
################################
# figures
# probability-dist-unif
png(file="[Link]", width=450, height=450)
curve(pbinom(x, 10, 0.3), 0, 10, xlab='x', ylab='binom(x)')
[Link]()
# probability-dist-unif
png(file="[Link]", width=450, height=450)
curve(punif(x, 1, 3), 0, 5, xlab='x', ylab='unif(x)')
[Link]()
# probability-dist-beta
png(file="[Link]", width=450, height=450)
curve(dbeta(x,5,12), 0, 1, xlab='x', ylab='beta(x;a=5, b=12)')
length(x)
[Link]()
# probability-dist-gamma
png(file="[Link]", width=450, height=450)
curve(dgamma(x,2,1), 0, 10, xlab='x', ylab='gamma(x;a=2, b=1)')
[Link]()