##### R-code for Example 6.1. It writes the related data to ##### the file "example61.dat" set.seed(100) x1 = rnorm(10,0,1) x2 = rnorm(10,1,1) x =c(x1,x2) n=length(x) ### Assume that mu0 and mu1 are known S2tilde = rep(0,n-1) for(i in 1:(n-1)){ S2tilde[i] = sum((x[1:i]-0)^2-(x[1:i]-1)^2)+ sum((x-1)^2) } ### Assume that mu0 and mu1 are both unknown S2 = rep(0,n-1) for(i in 1:(n-1)){ S2[i] = sum((x[1:i]-mean(x[1:i]))^2)+sum((x[(i+1):n]-mean(x[(i+1):n]))^2) } write.table(round(cbind(x,c(S2tilde,0),c(S2,0)),digits=3), file="example61.dat",col.names=T, row.names=F)