############################################### ## Author: Joshua M. Tebbs ## Date: 25 July 2018 ## Update: 10 November 2018 ## STAT 511 course notes: R Code ## Chapter 3 ############################################### # Figure 3.1 # Page 37 y = c(2,3,4,5,6,7,8,9,10,11,12) prob = c(1/36,2/36,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),yaxt='n',cex.lab=1.25) abline(h=0) axis(side=1,at=y) axis(side=2,at=c(0,1/36,2/36,3/36,4/36,5/36,6/36),labels=c("0","1/36","2/36","3/36","4/36","5/36","6/36")) # Figure 3.2 # Page 39 y = c(0,1,2,3,4,5) prob = c(0.042,0.198,0.348,0.286,0.110,0.016) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) axis(side=1,at=y) # Figure 3.3 # Page 40 y = c(1:40) prob = (1/6)*(5/6)^(y-1) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) axis(side=1,at=seq(0,40,5)) # Figure 3.4 # Page 41 y = c(0:20) prob = ((y+1)*(y+2))^(-1) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) axis(side=1,at=seq(0,20,5)) # Figure 3.5 # Page 43 y = c(1,2,3,4,5) prob = c(0.38,0.27,0.18,0.11,0.06) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) points(x=2.2,y=0,pch=19,cex=1.5) # Figure 3.6 # Page 45 y = c(0:6) prob = exp(-1)/factorial(y) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) # Figure 3.7 # Page 57 y = seq(0,30,1) prob = dbinom(y,30,0.35) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) # Figure 3.8 # Page 60 y = seq(1,30,1) prob = dgeom(y-1,0.20) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) # Figure 3.9 # Page 63 y = seq(1,100,1) prob = dnbinom(y-4,4,0.15) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0) # Figure 3.10 # Page 66 # Left y = seq(0,10,1) prob.hyper = dhyper(y,100,900,10) plot(y,prob.hyper,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob.hyper)),cex.lab=1.25) abline(h=0) # Right y = seq(0,10,1) prob.bin = dbinom(y,10,0.10) plot(y,prob.bin,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob.bin)),cex.lab=1.25) abline(h=0) # Figure 3.11 # Page 71 y = seq(0,10,1) prob = dpois(y,1.5) plot(y,prob,type="h",xlab="y",ylab="PMF",ylim=c(0,max(prob)),cex.lab=1.25) abline(h=0)