Below are the solutions to these exercises on probability mass function.

#################### # # # Exercise 1 # # # #################### dbinom(5, size=200, prob=1/20)

## [1] 0.0358957

#################### # # # Exercise 2 # # # #################### print(dbinom(0,10,1/2)+dbinom(1,10,1/2)+dbinom(2,10,1/2)+dbinom(3,10,1/2)+dbinom(4,10,1/2)+dbinom(5,10,1/2)+dbinom(6,10,1/2))

## [1] 0.828125

print(pbinom(6,10,1/2))

## [1] 0.828125

#################### # # # Exercise 3 # # # #################### print(pbinom(10,10,1/2)-pbinom(5,10,1/2))

## [1] 0.3769531

#################### # # # Exercise 4 # # # #################### barplot(dbinom(0:10, 10, 1/20),names.arg=0:10,main=sprintf(paste('Binomial dististribution ',10,1/20,sep=';')))

barplot(dbinom(0:10, 10, 1/10),names.arg=0:10,main=sprintf(paste('Binomial dististribution ',10,1/10,sep=';')))

barplot(dbinom(0:10, 10, 1/3),names.arg=0:10,main=sprintf(paste('Binomial dististribution ',10,0.333,sep=';')))

#The more the probability of success get high, the more the bar in the plot shift to the right, meaning that the probability of a high number of success get bigger. #################### # # # Exercise 5 # # # #################### dpois(85,lambda=80)

## [1] 0.03709261

dpois(2000,lambda=80*24) #Watch out for the unit!

## [1] 0.001723462

#################### # # # Exercise 6 # # # #################### dpois(5,lambda=(1/2)*20/5)

## [1] 0.03608941

#################### # # # Exercise 7 # # # #################### ppois(5,lambda=10)

## [1] 0.06708596

ppois(5,lambda=10,lower=FALSE)

## [1] 0.932914

#################### # # # Exercise 8 # # # #################### barplot(dpois(0:20, lambda=1),names.arg=0:20,main=sprintf(paste('Poisson dististribution with rate ',1,sep=':')))

barplot(dpois(0:20, lambda=3),names.arg=0:20,main=sprintf(paste('Poisson dististribution with rate ',3,sep=':')))

barplot(dpois(0:20, lambda=5),names.arg=0:20,main=sprintf(paste('Poisson dististribution with rate ',4,sep=':')))

barplot(dpois(0:20, lambda=10),names.arg=0:20,main=sprintf(paste('Poisson dististribution with rate ',10,sep=':')))

#################### # # # Exercise 9 # # # #################### dnbinom(3,5,1/3)

## [1] 0.04267642

#################### # # # Exercise 10 # # # #################### pnbinom(3,5,1/3)

## [1] 0.08794391

**What's next:**

- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

## Leave a Reply