install.packages(“rmarkdown”)
# Set seed that determines the random number generator
set.seed(48183130) #use your student ID instead of 12345678
p<-round(runif(1,min=0.2, max=0.8), digits=2) #this picks a random number between 0.2 and 0.8
p #this shows you the random number. Use this number to solve Q1 to Q5
## [1] 0.58
# creates number of successes
k<-c(0,1,2,3,4,5,6,7,8,9,10)
k
## [1] 0 1 2 3 4 5 6 7 8 9 10
n<-length(k)-1
# creates data frame
table<-as.data.frame(k) #this creates a table with the k column
table$prob<-round(dbinom(table$k, size=10, prob=p),4) #this calculates the probability of k successes
table
## k prob
## 1 0 0.0002
## 2 1 0.0024
## 3 2 0.0147
## 4 3 0.0540
## 5 4 0.1304
## 6 5 0.2162
## 7 6 0.2488
## 8 7 0.1963
## 9 8 0.1017
## 10 9 0.0312
## 11 10 0.0043
# 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))