------------- # Aufgabe 1 # ------------- # 1a) mycol = rainbow(10) curve( dchisq(x,df=1), xlim=c(0,12), ylim=c(0,0.6), col=mycol[1], xlab="xi", ylab="densities", main="Dichte der chi^2-Verteilung mit n=1,2,...,10 Freiheitsgraden" ) for(i in 2:10) { curve(dchisq(x,df=i),add=TRUE,col=mycol[i]) } # 1b-d) n = 5 N = 10000 x = rnorm(n*N) Phi = matrix(x,nrow=N,ncol=n,byrow=TRUE) PhiSquared = Phi*Phi xi = rowSums(PhiSquared) hist(xi,prob=TRUE,breaks=50) curve(dchisq(x,df=n),add=TRUE,col="red") # 1e) # let's check for all n=1,2,...,10: N=10000 for(n in 1:10) { x = rnorm(n*N) Phi = matrix(x,nrow=N,ncol=n,byrow=TRUE) PhiSquared = Phi*Phi xi = rowSums(PhiSquared) info = paste("n =",n) hist(xi,prob=TRUE,breaks=50,xlim=c(0,30),ylim=c(0,0.5),main=info) curve(dchisq(x,df=n),add=TRUE,col="red") # wait a bit until next plot is shown: readline(prompt = "press Enter to continue..") }