### R code from vignette source 'lab8.Rnw'

###################################################
### code chunk number 1: lab8.Rnw:33-35
###################################################
data(longley)
longley[1:4,]


###################################################
### code chunk number 2: res1
###################################################
llm = lm(Employed~GNP+Population, data=longley)
plot(rstudent(llm)~Year,data=longley,pch=19)


###################################################
### code chunk number 3: lab8.Rnw:51-53
###################################################
rho = cor(residuals(llm)[-1],residuals(llm)[-16])
print(rho)


###################################################
### code chunk number 4: lab8.Rnw:65-71
###################################################
x = model.matrix(llm)
Sigma = diag(16)
Sigma = rho^abs(row(Sigma)-col(Sigma))
SigInv = solve(Sigma)
xtxi = solve(t(x) %*% SigInv %*% x)
beta = xtxi %*% t(x) %*% SigInv %*% longley$Employed


###################################################
### code chunk number 5: lab8.Rnw:74-77
###################################################
res = longley$Employed - x%*%beta
(sig = sqrt((t(res)%*%SigInv%*%res)/llm$df))
sqrt(diag(xtxi))*sig


###################################################
### code chunk number 6: lab8.Rnw:81-85
###################################################
sm = chol(Sigma)
smi = solve(t(sm))
sx = smi%*%x
sy = smi%*%longley$Empl


###################################################
### code chunk number 7: lab8.Rnw:99-104
###################################################
library(nlme)
g = gls(Employed~GNP+Population, correlation=corAR1(form=~Year),data=
          longley)
summary(g)
intervals(g)


###################################################
### code chunk number 8: lab8.Rnw:130-132
###################################################
library(faraway)
savings[1,]


###################################################
### code chunk number 9: lab8.Rnw:162-163
###################################################
Stangle("lab8.Rnw")


