##### Slidedeck c1 ##### ##### Create graphics for Discrete Distributions ##### ##### ### Distribution of Number of Heads xx = 0:3 yy = dbinom(xx, size=3, prob=0.5) par(xaxs="i",yaxs="i") par(family="serif",las=1) par(mar=c(4,4.5,1,1)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.25,3.25), ylim=c(0,0.50)) yyVals = 0:5*0.1 axis(1, at=-1:4) axis(2, at=yyVals) segments(-0.25,yyVals,3.25,yyVals, lty=3, col="grey") title(xlab="Number of Heads", line=2.5) title(ylab="Probability", line=3.15) for(i in xx) { segments(i,0,i,yy[i+1]) points(i,yy[i+1], pch=21, bg="dodgerblue") } # Calculations x = 0:3 p = c (0.125 ,0.375 ,0.375 ,0.125) sum (x*p) sum ( (x -1.5) ^2* p ) sqrt ( sum ( (x -1.5) ^2* p )) cumsum (p) # Plot of CDF plot(x, cumsum(p), type="s" ) ##### ### Distribution of Hockey Points xx = 0:5 yy = c(0.1,0.1,0.2,0.4,0.1,0.1) par(xaxs="i",yaxs="i") par(family="serif",las=1) par(mar=c(4,4.5,1,1)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.25,5.25), ylim=c(0,0.50)) yyVals = 0:5*0.1 axis(1, at=-1:6) axis(2, at=yyVals) segments(-0.25,yyVals,5.25,yyVals, lty=3, col="grey") title(xlab="Number of Goals Scored", line=2.5) title(ylab="Probability", line=3.15) for(i in xx) { segments(i,0,i,yy[i+1]) points(i,yy[i+1], pch=21, bg="dodgerblue") } # Calculations x = 0:5 p = c (0.1 ,0.1 ,0.2 ,0.4 ,0.1 ,0.1) sum (x*p) sum ( (x -2.6) ^2* p ) sqrt ( sum ( (x -2.6) ^2* p )) cumsum (p) plot(x,cumsum(p), type="s") ### End of File