# The t-distribution relation to the Cauchy and Normal Distribution #pdf('tdist.pdf', width=7.5, height=10) par(mfrow=c(2,1)) # first plot the a good view x <- seq(-5,5,length=400) norm <- dnorm(x, mean=0, sd=1) # generate values for standard normal cauchy <- dcauchy(x) # generate values for cauchy, location=0, shape=1, by default t1 <- dt(x, df=1) # generate values for t distribution with 1 degree of freedom t5 <- dt(x, df=5) # " " " 5 degrees of freedom t15 <- dt(x, df=15) # " " " 15 degrees of freedom t35 <- dt(x, df=35) # " " " 35 degrees of freedom # plot the standard normal plot(x, norm, type="l", col="grey50", lwd=2, lty=1, ylab="Density", main="The t Distribution", sub="Relation to Cauchy and Normal Distributions") # overlay the cauchy points(x, cauchy, type="l", col="grey50", lwd=2, lty=2) # overlay the t distributions points(x, t1, type="l", col="red", lwd=3, lty=3) points(x, t5, type="l", col="blue", lwd=3, lty=4) points(x, t15, type="l", col="green", lwd=3, lty=5) points(x, t35, type="l", col="pink2", lwd=3, lty=6) # add legend legend(-5,0.4, "Normal", bty="n", lty=1, col="grey50",lwd=3) legend(-5,0.36, "Cauchy", bty="n", lty=2, col="grey50",lwd=2) legend(2,0.42, "1 Degree\nof Freedom", bty="n", lty=3, col="red",lwd=3) legend(2,0.35, "5 Degrees\nof Freedom", bty="n", lty=4, col="blue",lwd=3) legend(2,0.28, "15 Degrees\nof Freedom", bty="n", lty=5, col="green",lwd=3) legend(2,0.21, "35 Degrees\nof Freedom", bty="n", lty=6, col="pink2",lwd=3) # now zoom in on the tails x <- seq(2,7, length=400) norm <- dnorm(x, mean=0, sd=1) # generate values for standard normal cauchy <- dcauchy(x) # generate values for cauchy, location=0, shape=1, by default t1 <- dt(x, df=1) # generate values for t distribution with 1 degree of freedom t5 <- dt(x, df=5) # " " " 5 degrees of freedom t15 <- dt(x, df=15) # " " " 15 degrees of freedom t35 <- dt(x, df=35) # " " " 35 degrees of freedom plot(x, norm, type="l", col="grey50", lwd=2, lty=1, ylab="Density", main="The t Distribution", sub="Relation to Cauchy and Normal Distributions") # overlay the cauchy points(x, cauchy, type="l", col="grey50", lwd=2, lty=2) points(x, t1, type="l", col="red", lwd=3, lty=3) points(x, t5, type="l", col="blue", lwd=3, lty=4) points(x, t15, type="l", col="green", lwd=3, lty=5) points(x, t35, type="l", col="pink2", lwd=3, lty=6) # add legend legend(3,0.05, "Normal", bty="n", lty=1, col="grey50",lwd=3) legend(3,0.044, "Cauchy", bty="n", lty=2, col="grey50",lwd=2) legend(4.1,0.052, "1 Degree\nof Freedom", bty="n", lty=3, col="red",lwd=3) legend(4.1,0.042, "5 Degrees\nof Freedom", bty="n", lty=4, col="blue",lwd=3) legend(5.5,0.052, "15 Degrees\nof Freedom", bty="n", lty=5, col="green",lwd=3) legend(5.5,0.042, "35 Degrees\nof Freedom", bty="n", lty=6, col="pink2",lwd=3) #dev.off()