### Distribution of order statistics rm(list=ls()) n<-1000 nreps<-1000 k<-1 y<-NULL for (i in 1:nreps) { x<-runif(n,0,1) y[i]<-x[order(x)][k] } hist(y,freq=FALSE) t<-c(1:1000)/1000 lines(t,dbeta(t,k,n+1-k)) ##### Convergence in distribution n<-100 nreps<-1000 #k<-10 y<-z<-NULL for (i in 1:nreps) { x<-runif(n,0,1) y[i]<-max(x) #[order(x)][k] z[i]<-n*(1-y[i]) } hist(y,freq=FALSE) t<-c(1:1000)/1000 k<-n lines(t,dbeta(t,k,n+1-k)) hist(z,freq=FALSE) t<-c(1:10000)/1000 lines(t,dexp(t,1)) ###### Central Limit Theorem n<-100 nreps<-1000 xbar<-NULL for (i in 1:nreps) { x<-rexp(n,.1) xbar[i]<-mean(x) } mu<-10 sigma2<-100 hist(sqrt(n)*(xbar-mu)/sqrt(sigma2),freq=FALSE) t<-c(-300:300)/100 lines(t,dnorm(t,0,1)) ####### Lab questions n<-10000 u<-runif(n,0,1) x<--5*(log(1-u)) z<-NULL for (i in 1:n) { u<-runif(3,0,1) x1<--2*log(1-u) z[i]<-sum(x1) } y<-NULL for (i in 1:n) { u<-runif(3,0,1) x1<--1.5*log(1-u) y[i]<-sum(x1) } mean(x>y) mean(y>z) mean(x>z) mean(y) mean(x) mean(z) hist(x,freq=FALSE) t<-c(1:10000)/100 lines(t,exp(-t/5)/5,col=2) n<-10000 hist(y,freq=FALSE) t<-c(1:1000)/10 lines(t,dchisq(t,df=6)) lines(t,dgamma(t,3,1.5)) hist(x) hist(z)