Seasonal Variation

Constant seasonal variation (also call addiative seasonal variation ) magnitude of swing constant through time

increasing seasonal variation

library(faraway)
## Warning: package 'faraway' was built under R version 3.4.4
library(alr3)
## Warning: package 'alr3' was built under R version 3.4.3
## Loading required package: car
## Warning: package 'car' was built under R version 3.4.3
## 
## Attaching package: 'car'
## The following objects are masked from 'package:faraway':
## 
##     logit, vif
## 
## Attaching package: 'alr3'
## The following objects are masked from 'package:faraway':
## 
##     cathedral, pipeline, twins
data(Mitchell)
with(Mitchell, plot(Temp~Month,type="l"))

with(airpass,plot(pass~year,type="l"))

attach(airpass)
par(mfrow=c(2,2))
y<-sqrt(pass)
x<-log(pass)
with(airpass,plot(y~sqrt(year),type="l"))
with(airpass,plot(y~(year),type="l"))
with(airpass,plot(x~(year),type="l"))
with(airpass,plot((log(pass,base = 10))~sqrt(year),type="l"))

#with(airpass,plot((log(pass,base=100))~sqrt(year),type="l"#"))
#with(airpass,plot(((pass^.1)~sqrt(year),type="l"))

6.4 Modeling Seasonal Variation

This section covers dummy variables and trig. functions. An example of dummy variables is I(mo=June)={1 if June, 0 if not June}. As such 12 months = 12 dummies, and 4 months= 4 dummies.

imagine time series model \(Y_t=TR_t+SN_t+\epsilon_t\) \(Y_t\) measure the at time. \(TR_t\) is the trend such as \(\beta_0+\beta_1*t\). \(SN_t\) is the seasonal factor. \(\epsilon_t\) is the error/resid.

So lm(y~year+month)

justyear<-floor(airpass$year)
modecimal <- airpass$year - justyear 
mofactor <-factor(round(modecimal*12))
airpass$mofactor<-mofactor
mod <- lm(log(pass) ~ justyear + mofactor, data=airpass)

coef(mod)
##  (Intercept)     justyear    mofactor1    mofactor2    mofactor3 
## -1.214997885  0.120825657  0.031389870  0.019403852  0.159699778 
##    mofactor4    mofactor5    mofactor6    mofactor7    mofactor8 
##  0.138499729  0.146195892  0.278410898  0.392422029  0.393195995 
##    mofactor9   mofactor10   mofactor11 
##  0.258630198  0.130540762 -0.003108143
summary(mod)
## 
## Call:
## lm(formula = log(pass) ~ justyear + mofactor, data = airpass)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.156370 -0.041016  0.003677  0.044069  0.132324 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.214998   0.081277 -14.949  < 2e-16 ***
## justyear     0.120826   0.001432  84.399  < 2e-16 ***
## mofactor1    0.031390   0.024253   1.294    0.198    
## mofactor2    0.019404   0.024253   0.800    0.425    
## mofactor3    0.159700   0.024253   6.585 1.00e-09 ***
## mofactor4    0.138500   0.024253   5.711 7.19e-08 ***
## mofactor5    0.146196   0.024253   6.028 1.58e-08 ***
## mofactor6    0.278411   0.024253  11.480  < 2e-16 ***
## mofactor7    0.392422   0.024253  16.180  < 2e-16 ***
## mofactor8    0.393196   0.024253  16.212  < 2e-16 ***
## mofactor9    0.258630   0.024253  10.664  < 2e-16 ***
## mofactor10   0.130541   0.024253   5.382 3.28e-07 ***
## mofactor11  -0.003108   0.024253  -0.128    0.898    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0593 on 131 degrees of freedom
## Multiple R-squared:  0.9835, Adjusted R-squared:  0.982 
## F-statistic: 649.4 on 12 and 131 DF,  p-value: < 2.2e-16
with(airpass, plot(log(pass)~ year, type="l" ))
lines(airpass$year, mod$fitted.values,col="blue")

Create seasonal dummies Create model with seasons dummies plot data in black months in blue seasons model in red

season<-airpass$mofactor
winter<-c("Dec","Jan","Feb")
spring<-c("Mar","Apr","May")
fall<-c("Jun","Jul","Aug")
summer<-c("Oct","Nov","Sep")
#levels(season)<-list(winter<-c("Dec","Jan","Feb"), spring<-c("Mar","Apr","May"), fall<-c("Jun","Jul","Aug"), summer<-c("Oct","Nov","Sep"))