##### R-code for making Figure 6.2 set.seed(1000) T1jn = rep(0,100) ### This is |T_jn| used in (6.20) ### when the process is IC T2jn = rep(0,100) ### This is |T_jn| used in (6.20) ### when the process is OC x = rnorm(100,0,1) n=length(x) ### Compute the sequence of {|T1_jn|, 1 <= j <= n-1} to ### show that it has a U-shape when the process is IC for(j in 1:(n-1)){ T1jn[j] = sqrt(j*(n-j)/n)*abs(mean(x[1:j])-mean(x[(j+1):n]))/ sqrt(var(x[1:j])*(j-1)+var(x[(j+1):n])*(n-j-1)) } ### Compute the sequence of {|T2_jn|, 1 <= j <= n-1} to ### show that it has a power to detect a shift when the ### process is OC y=x+c(rep(0,50),rep(1,50)) for(j in 1:(n-1)){ T2jn[j] = sqrt(j*(n-j)/n)*abs(mean(y[1:j])-mean(y[(j+1):n]))/ sqrt(var(y[1:j])*(j-1)+var(y[(j+1):n])*(n-j-1)) } ### Make a figure postscript("fig62.ps",width=6.5,height=6.5,horizontal=F) par(mfrow=c(2,2),mar=c(4,4,2,2)) i=seq(1,n) plot(i,x,type="o",lty=1,pch=16,xlab="n", ylab=expression(X[n]),mgp=c(2,1,0),xlim=c(0,n), ylim=c(-2.6,2.6), cex=0.8) title(xlab="(a)",cex=0.9) plot(i[2:(n-1)],T1jn[2:(n-1)],type="o",lty=1,pch=16,xlab="n", ylab=expression(group("|",T[jn],"|")),mgp=c(2,1,0),xlim=c(1,n), ylim=c(0,0.4), cex=0.8) title(xlab="(b)",cex=0.9) plot(i,y,type="o",lty=1,pch=16,xlab="n", ylab=expression(X[n]),mgp=c(2,1,0),xlim=c(0,n), ylim=c(-2.6,3.6), cex=0.8) title(xlab="(c)",cex=0.9) plot(i[2:(n-1)],T2jn[2:(n-1)],type="o",lty=1,pch=16,xlab="n", ylab=expression(group("|",T[jn],"|")),mgp=c(2,1,0),xlim=c(1,n), ylim=c(0,0.8), cex=0.8) title(xlab="(d)",cex=0.9) graphics.off()