set.seed(12345) n<-10000; par(mfrow=c(1,2)) z1<-rnorm(n,0,1) z2<-rnorm(n,0,1) z3<-rnorm(n,0,1) z4<-rnorm(n,0,1) z5<-rnorm(n,0,1) chi5<-z1^2+z2^2+z3^2+z4^2+z5^2 hist(chi5, freq=F, col="grey", xlab="", xlim=c(0, 25), breaks=100) par(new=T) plot(density(chi5), axes=F, main="", xlim=c(0, 25), lwd=2, col="blue") curve(dchisq(x, 5, ncp=0), col="black", xlim=c(0, 25), ylim=c(0, 0.15), xlab="chisq", ylab="f(chisq)")