# Order statistics in R #Example: max{X} from Unif(0,theta) unifmax <- function(theta,n) { y <- (0:10000)*theta/10000 Gyn <- (y/theta)^n plot(y,Gyn,type="l",main=expression(paste( "Cdf of ",Y[n]," from Uniform(0,",theta,")")), sub = paste("theta = ",theta,"; n = ",n ),ylab = "G(y)" ) } unifmaxdens <- function(theta,n) { y <- (0:10000)*theta/10000 gyn <- n*(y/theta)^(n-1)/theta plot(y,gyn,type="l",main=expression(paste( "pdf of ",Y[n]," from Uniform(0,",theta,")")), sub = paste("theta = ",theta,"; n = ",n ),ylab = "g(y)" ) } p2xmin <- function(n) { # Plots density of minimum order statistic if f(x) = 2x, 0 < x < 1 y <- (0:10000)/10000 gy1 <- n*(1-y^2)^(n-1)*2*y plot(y,gy1,type="l",main=expression(paste( "pdf of ",Y[1]," from f(x) = 2x")), sub = paste("n = ",n ),ylab = "g(y)" ) } p2xmax <- function(n) { # Plots density of maximum order statistic if f(x) = 2x, 0 < x < 1 y <- (0:10000)/10000 gyn <- 2*n*y^(2*n-1) plot(y,gyn,type="l",main=expression(paste( "pdf of ",Y[n]," from f(x) = 2x")), sub = paste("n = ",n ),ylab = "g(y)" ) } unifmax(2,1) unifmax(2,5) unifmax(2,100) unifmax(2,1000) # Example: X_i iid Unif(0,theta) # Let Z_n = n(theta-Y_n) unifz <- function(theta,n) { z <- (0:10000)*theta*n/10000 Hz <- ( 1 - (1 - z/(n*theta) )^n ) plot(z,Hz,type="l",main=expression(paste( "Cdf of ",Z[n],"; Uniform(0,",theta,")")), sub = paste("theta = ",theta,"; n = ",n ),ylab = "H(z)",xlim = c(0,12) ) } unifz(2,1) unifz(2,5) unifz(2,100) unifz(2,1000) # Plot Exp(2) Cdf z <- (0:10000)*13/10000 Hz <- ( 1 - exp(-z/2)) plot(z,Hz,type="l",main="Cdf of Exp(2)",xlim = c(0,12) ) # Problem 2, page 259 prob2cdf <- function(n) { y <- (-10000:10000)*20/21000 Gy <- (1 + exp(-y-log(n)))^(-n) plot(y,Gy,type="l",sub=paste("n= ",n)) } prob2cdf(1) prob2cdf(10) prob2cdf(100) # Limiting distribution y <- (-10000:10000)*20/21000 Gy <- exp(-exp(-y)) plot(y,Gy,type="l",sub="limiting distribution")