##### R-code for Example 7.1. It writes the related data to ##### the file "example71.dat." It also makes "fig73.ps". #### Generate 30 random vectors from N_3(mu,Sigma) library(MASS) ### R package for generating multivariate normal random vectors. set.seed(100) mu1 = c(0,0,0) mu2 = c(1,1,1) Sigma = matrix(c(1,0.8,0.5,0.8,1,0.8,0.5,0.8,1),3,3) x1 = mvrnorm(20,mu1,Sigma) x2 = mvrnorm(10,mu2,Sigma) x = rbind(x1,x2) n = length(x[,1]) xbar = colMeans(x) S2 = cov(x) T12 = rep(0,n) for(i in 1:n){ T12[i] = t(x[i,]-xbar) %*% solve(S2) %*% (x[i,]-xbar) } write.table(round(cbind(x,xbar,T12),digits=3), file="example71.dat",col.names=T, row.names=F) postscript("fig73.ps",width=4.5,height=4.5,horizontal=F) ii = seq(1,n) plot(ii,T12,type="o",lty=1,pch=16,xlab="i", ylab=expression(T[list(1,i)]^{2}),mgp=c(2,1,0),xlim=c(0,31), ylim=c(0,15),cex=0.8) lines(ii,rep(10.77279,n),lty=2,cex=0.8) graphics.off()