Fall 2024 …………………………………… Score ____ / 20

Homework #2

[ARASI KRISHNAMURTHY]

___________________________________________

highlight and click “Run” the line below before knitting

install.packages(“rmarkdown”)

# set seed replace 12345678 with your student ID
seed = 51297025
# picks a random number between 0.2 and 0.8 
set.seed(seed + 24)
p<-round(runif(1,min=0.2, max=0.8), digits=2) 
# Use this proportion to answer the questions
p  
## [1] 0.73
# creates number of successes
k<-c(0,1,2,3,4,5,6,7,8,9,10)
n<-length(k)-1
# creates data frame
# creates a table with the k column
table<-as.data.frame(k)
# computes the probability of k successes
table$prob<-round(dbinom(table$k, size=10, prob=p),4) 
# prints table
table
##     k   prob
## 1   0 0.0000
## 2   1 0.0001
## 3   2 0.0007
## 4   3 0.0049
## 5   4 0.0231
## 6   5 0.0750
## 7   6 0.1689
## 8   7 0.2609
## 9   8 0.2646
## 10  9 0.1590
## 11 10 0.0430
# creates histogram
barplot(table$prob, main = c(paste("Binomial Distribution"), paste("Prob =", p), paste("n =",n)), xlab="k",ylab="prob",names.arg=c(k), space=c(0,0,0,0,0,0,0,0,0,0,0))