```r
# Read a txt file, named "boxoffice.txt"
dta <- read.delim("C:/Users/ASUS/Desktop/data/boxoffice.txt")
#
m0 <- lm(GrossBoxOffice ~ year, data=dta)
summary(m0)
## 
## Call:
## lm(formula = GrossBoxOffice ~ year, data = dta)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -116.382  -79.197    6.083   62.260  121.697 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -58386.485   2952.825  -19.77   <2e-16 ***
## year            29.534      1.483   19.92   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 77.44 on 30 degrees of freedom
## Multiple R-squared:  0.9297, Adjusted R-squared:  0.9274 
## F-statistic: 396.8 on 1 and 30 DF,  p-value: < 2.2e-16
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
dwtest(data=dta,GrossBoxOffice ~ year, alternative="two.sided")
## 
##  Durbin-Watson test
## 
## data:  GrossBoxOffice ~ year
## DW = 0.24809, p-value = 4.689e-13
## alternative hypothesis: true autocorrelation is not 0
library(nlme)
m1 <- gls(GrossBoxOffice ~ year,data=dta, corr = corAR1(0.87821 , form = ~ 1 | year), method="ML")
summary(m1)
## Generalized least squares fit by maximum likelihood
##   Model: GrossBoxOffice ~ year 
##   Data: dta 
##        AIC      BIC    logLik
##   375.1165 380.9794 -183.5582
## 
## Correlation Structure: AR(1)
##  Formula: ~1 | year 
##  Parameter estimate(s):
##     Phi 
## 0.87821 
## 
## Coefficients:
##                 Value Std.Error  t-value p-value
## (Intercept) -58386.48 2952.8247 -19.7731       0
## year            29.53    1.4827  19.9194       0
## 
##  Correlation: 
##      (Intr)
## year -1    
## 
## Standardized residuals:
##         Min          Q1         Med          Q3         Max 
## -1.55212595 -1.05620690  0.08113172  0.83032067  1.62299772 
## 
## Residual standard error: 74.9826 
## Degrees of freedom: 32 total; 30 residual
knitr::spin("C:/Users/ASUS/Desktop/Boxoffice.R", knit=FALSE)
## [1] "C:/Users/ASUS/Desktop/Boxoffice.Rmd"