#n=500
#x=numeric(n)
#w = rnorm(n)
#s = rep( c(.4, 0.8, -0.8, -.4 ), n/4 )
#x[1] = 0
#for (i in 2:n) x[i] = x[i-1] + s[i] + w[i]
#x = ts(x, start=0, frequency=4 )
x = scan("1_10.csv")
x = ts(x, start=0, frequency=4 )
plot(x, type="l")
q1 = ifelse(cycle(x)==1,1,0)
q2 = ifelse(cycle(x)==2,1,0)
q3 = ifelse(cycle(x)==3,1,0)
q4 = ifelse(cycle(x)==4,1,0)
A = ts.intersect( x, xL1=lag(x,-1), q1, q2, q3, q4, dframe=TRUE )
fit01 = lm( x ~ 0, offset=xL1, data=A )
fit02 = lm( x ~ 1, offset=xL1, data=A )
summary(fit01)
##
## Call:
## lm(formula = x ~ 0, data = A, offset = xL1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8887 -0.8441 0.0438 0.8474 2.8330
##
## No Coefficients
##
## Residual standard error: 1.183 on 499 degrees of freedom
summary(fit02)
##
## Call:
## lm(formula = x ~ 1, data = A, offset = xL1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.9054 -0.8608 0.0271 0.8307 2.8163
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.01671 0.05299 0.315 0.753
##
## Residual standard error: 1.184 on 498 degrees of freedom
AIC(fit01,fit02)
## df AIC
## fit01 1 1585.543
## fit02 2 1587.443
BIC(fit01,fit02)
## df BIC
## fit01 1 1589.756
## fit02 2 1595.869
The model with no drift is preferred according to both AIC and BIC.
r01 = residuals( fit01 )
plot(r01, type="l")
acf(r01, lag.max=50)
The ACF suggests quarterly seasonality.
fit03 = lm( x ~ 0 + q1 + q2 + q3 + q4, offset=xL1, data=A )
summary(fit03)
##
## Call:
## lm(formula = x ~ 0 + q1 + q2 + q3 + q4, data = A, offset = xL1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3128 -0.7443 0.0240 0.7246 2.4770
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## q1 0.42299 0.09236 4.580 5.89e-06 ***
## q2 0.68176 0.09199 7.411 5.45e-13 ***
## q3 -0.84716 0.09199 -9.209 < 2e-16 ***
## q4 -0.18749 0.09199 -2.038 0.0421 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.028 on 495 degrees of freedom
## Multiple R-squared: 0.9903, Adjusted R-squared: 0.9902
## F-statistic: 1.265e+04 on 4 and 495 DF, p-value: < 2.2e-16
The coefficient for Q1 is significant with a p-value of less than 10^{-5}. Reject null hypothesis. The joint hypothesis is also rejected with a p value of less than 10^{-15}.
r03 = residuals(fit03)
plot(r03,type="l")
acf(r03, lag.max=50)
AIC(fit01,fit02,fit03)
## df AIC
## fit01 1 1585.543
## fit02 2 1587.443
## fit03 5 1450.087
BIC(fit01,fit02,fit03)
## df BIC
## fit01 1 1589.756
## fit02 2 1595.869
## fit03 5 1471.150
Model 3 is strongly preferred by both AIC and BIC. Residuals look much more like white noise.