## 3-D VIEW OF THE LS GEOMETRY: LS.geom <- function( rot = 4, # number of 360 degree rotations around the z axes spd = .05, # rotation speed, i.e., angular increment between animation frames rg = c(-.07,1.07), # range of x, y, z cex = 1.5, # point fatness lwd = 1.5, # line fatness ra = .08, # right angle size ad = .06, # text moves up and down sq = sqrt(2), phi = 20, # view latitude y = c(x=.7, y=.7, z=.7), # response vector x = c(.1, .5)) # coordinates of x0 and x1: this and switched { for(theta in seq(0,360*rot,by=spd)) { persp(x=0:1, y=0:1, z=matrix(c(0,0,0,1),nrow=2,ncol=2), xlim=rg, ylim=rg, zlim=rg, mar=rep(0,4), xlab="", ylab="", zlab="", border=NA, box=F, axes=F, theta=theta, phi=phi, r=10) -> tr # Hor square = space of fits lines(trans3d(x=c(0,1,1,0,0), y=c(0,0,1,1,0), z=c(0,0,0,0,0), pmat=tr), lwd=2) # Vert line = residual space lines(trans3d(x=c(0,0), y=c(0,0), z=c(0,1), pmat=tr), lwd=2) # Indicators of right angles: lines(trans3d(x=c( 0, ra, ra,NA, 0, 0, 0,NA, y[1], y[1]-ra/sq, y[1]-ra/sq), y=c( 0, 0, 0,NA, 0, ra, ra,NA, y[2], y[2]-ra/sq, y[2]-ra/sq), z=c(ra, ra, 0,NA, ra, ra, 0,NA, ra, ra, 0), pmat=tr), lwd=1) # Predictor vectors: lines(trans3d(x=c(0,.5,NA,0,.1), y=c(0,.1,NA,0,.5), z=c(0,0,NA,0,0), pmat=tr), pch=16, cex=cex, col="blue", lwd=lwd, type="o") # origin, y, yhat, r: lines(trans3d(x=c(0, y[1], 0, 0, y[1], y[1]), y=c(0, y[2], 0, 0, y[2], y[2]), z=c(0, y[3], y[3], 0, 0, y[3]), pmat=tr), pch=16, cex=cex, col="red", lwd=lwd, type="o") text(trans3d(x=c( 0, x[1], x[2], y[1], y[1]+ad, -ad/2), y=c( 0, x[2], x[1], y[2], y[2]+ad, -ad/2), z=c(-ad, -ad, -ad, -ad, y[3]+ad, y[3]), pmat=tr), lab=c(expression(bold(O)), expression(bold(x)[0]), expression(bold(x)[1]), expression(hat(bold(y))), expression(bold(y)), expression(bold(r))) ) text(trans3d(x=1, y=1, z=-.1, pmat=tr), adj=0, cex=.8, lab=" Space of Fits\n = Range(P)\n = Null(I-P)" ) text(trans3d(x=0, y=0, z=.9, pmat=tr), adj=0, cex=.8, lab=" Resid. Space\n = Range(I-P)\n = Null(P)" ) } } LS.geom()