In: Math
Problem 6: R simulation.
Use different color lines and appropriate legend to
(1) plot the density functions of χ 2 k for k = 1, 2, 3, 4, 6, 9 in one figure;
(2) plot the density functions of tk for k = 3, 5, 10, 30 and N(0, 1) distribution in one figure. Describe respectively what you observe when the degree of freedom increases.
1)
R codes are:
curve(dchisq(x,1),0,15,ylim=c(0,.5),lwd=2,col="black",ylab="Density")
curve(dchisq(x,2),add=T,col="red",lwd=2)
curve(dchisq(x,3),add=T,col="blue",lwd=2)
curve(dchisq(x,4),add=T,col="green",lwd=2)
curve(dchisq(x,6),add=T,col="orange",lwd=2)
curve(dchisq(x,9),add=T,col="steelblue",lwd=2)
legend(10,.45,legend=c("df=1","df=2","df=3","df=4","df=6","df=9"),
col=c("black","red","blue","green","orange","steelblue"),
lwd=c(2,2,2,2,2,2),bty="n")
2).
curve(dt(x,3),from=-3,to=3,ylab="Density",lwd=2,col="orange",ylim=c(0,.45))
curve(dt(x,5),add=T,lwd=2,col="red")
curve(dt(x,10),add=T,lwd=2,col="blue")
curve(dt(x,30),add=T,lwd=2,col="green")
curve(dnorm(x,0,1),add=T,col="black",lwd=2)
legend("topright",legend=c("df=3","df=5","df=10","df=30","N(0,1)"),
col=c("orange","red","blue","green","black"),
lwd=c(2,2,2,2,2),bty="n")
We can observed from the above plot that as degree of freedom increases t distribution approaches to normality.