##### script for slidedeck c7 ##### ##### Slide deck for Uniform distribution ##### ### Preamble # two colors ito1 = "#E1EBEE" ## background ito2 = "#00AAE4" ## selected ##### ### Uniform pdf a=0.1; b=3.75 xx = seq(0,5, length=1e4) yy = dunif(xx, min=a,max=b) par(yaxs="i") par(family="serif",las=1) par(mar=c(3,0,2,3)+0.75) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(0,b+a), ylim=c(0,1/(b-a))) axis(1, at=c(a,b), label=c("a","b")); abline(h=0) title(xlab="Random Variable", line=1.50) title(ylab="Density", line=-1) abline(h=1/(b-a),lty=3, col="grey") mtext(side=2, at=1/(b-a), text=expression(frac(1,b-a)), line=-1 ) rect(a,0,b,1/(b-a), col=ito1, border="grey") abline(h=0) segments(-10,0, a,0, lwd=3) segments(b,0, 10,0, lwd=3) segments(a,1/(b-a), b,1/(b-a), lwd=3) ##### ### Ex: Main and Academy a=0; b=180; x=60 xx = seq(0,200, length=1e4) yy = dunif(xx, min=a,max=b) # Graphic par(yaxs="i") par(family="serif",las=1) par(mar=c(3,3,2,3)+0.75) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(0,b+a), ylim=c(0,1/(b-a))) axis(1, at=c(a,b,x), label=c(a,b,x)); abline(h=0) title(xlab="Wait Time [s]", line=1.5) title(ylab="Density", line=1) abline(h=1/(b-a),lty=3, col="grey") mtext(side=2, at=1/180, text=expression(frac(1,180)),line=1 ) rect(a,0,b,1/(b-a), col=ito1, border="grey") rect(a,0,x,1/(b-a), col=ito2, border="grey") abline(h=0) segments(-100,0, a,0, lwd=3) segments(b,0, 1000,0, lwd=3) segments(a,1/(b-a), b,1/(b-a), lwd=3) ### Graphic of the CDF # Define the CDF values a=0; b=1; x=0.33 xx = seq(0,200, length=1e4) yy = punif(xx, min=a,max=b) # Graphic par(yaxs="i", xpd=NA) par(family="serif",las=1) par(mar=c(3,3,2,3)+0.75) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.15,1.15), ylim=c(0,1) ) axis(1, at=c(a,b), label=c("a","b")); abline(h=0) title(ylab="Cumulative Probability", line=1) title(xlab="Random Variable", line=2.5) abline(h=1,lty=3, col="grey") mtext(side=2, at=0, text=0, line=1 ) mtext(side=2, at=1, text=1, line=1 ) lines(xx,yy, lwd=2) mtext(side=1, at=x, text="x", line=0) segments(x,0, x,punif(x, min=a,max=b), lwd=3, col=ito2) points(x,punif(x, min=a,max=b), pch=21, bg=ito2) ### End of File