library(nlme)
bookstore<-read.csv("bookstore.txt",sep="")

(a)

plot(Sales~Time,bookstore)

m1<-lm(Sales~Time,bookstore)
plot(m1)

(b)

ac<-acf(bookstore$Sales,96)

print(head(ac,n=10))
## 
## Autocorrelations of series 'bookstore$Sales', by lag
## 
##      1      2      3      4      5      6 
##  0.109 -0.131 -0.084 -0.145 -0.148 -0.096
ac[[1]][2]^2
## [1] 0.01181258
m2<-gls(Sales~Time+Advert+Lag1Advert,bookstore,method='ML')
summary(m2)
## Generalized least squares fit by maximum likelihood
##   Model: Sales ~ Time + Advert + Lag1Advert 
##   Data: bookstore 
##        AIC      BIC    logLik
##   1262.395 1275.058 -626.1973
## 
## Coefficients:
##                 Value Std.Error   t-value p-value
## (Intercept) 180.19576  56.30156  3.200547  0.0019
## Time         -0.17294   0.80555 -0.214684  0.8305
## Advert       34.52651   5.17806  6.667847  0.0000
## Lag1Advert   33.11461   5.25264  6.304370  0.0000
## 
##  Correlation: 
##            (Intr) Time   Advert
## Time       -0.630              
## Advert     -0.388 -0.071       
## Lag1Advert -0.411 -0.037 -0.170
## 
## Standardized residuals:
##         Min          Q1         Med          Q3         Max 
## -2.87480719 -0.50916284 -0.01937113  0.48037314  4.62658755 
## 
## Residual standard error: 203.2356 
## Degrees of freedom: 93 total; 89 residual
plot(m2)

m3<-gls(Sales~Time+Advert+Lag1Advert,bookstore,correlation = corAR1())
plot(m3)