Professional Documents
Culture Documents
Example 1
(1)Simulation
set.seed(1)
TIME <- 1:(10 * 12)
w <- rnorm(10 * 12, sd = 0.5)
10
15
20
40
60
Index
80
100
120
Call:
lm(formula = x ~ TIME + I(TIME^2) + COS[, 1] + SIN[, 1] + COS[,
2] + SIN[, 2] + COS[, 3] + SIN[, 3] + COS[, 4] + SIN[, 4] +
COS[, 5] + SIN[, 5] + COS[, 6] + SIN[, 6])
Residuals:
Min
1Q
-1.0782 -0.2871
Median
0.0045
3Q
0.2547
Max
1.1128
Coefficients:
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
3Q
0.3074
Max
1.2774
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.804e-01 6.059e-02
4.628 9.69e-06 ***
I(TIME^2)
1.036e-03 9.325e-06 111.144 < 2e-16 ***
SIN[, 1]
9.002e-01 5.702e-02 15.786 < 2e-16 ***
SIN[, 2]
1.989e-01 5.690e-02
3.495 0.000673 ***
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4405 on 116 degrees of freedom
Multiple R-squared: 0.9907, Adjusted R-squared: 0.9905
F-statistic: 4137 on 3 and 116 DF, p-value: < 2.2e-16
AIC(x.lm1);AIC(x.lm2)
## [1] 165.3527
## [1] 149.7256
plot(x, type = "l")
lines(TIME,predict(x.lm2),col="red")
15
10
0
20
40
60
80
100
120
Index
0.8
0.6
0.4
0.2
0.4
0.0
temp
1970
1975
1980
1985
1990
1995
Time
~ TIME + I(TIME^2) +
COS[,2] + SIN[,2] +
COS[,4] + SIN[,4] +
COS[,6] + SIN[,6])
Call:
lm(formula = temp ~ TIME + I(TIME^2) + COS[, 1] + SIN[, 1] +
COS[, 2] + SIN[, 2] + COS[, 3] + SIN[, 3] + COS[, 4] + SIN[,
4] + COS[, 5] + SIN[, 5] + COS[, 6] + SIN[, 6])
Residuals:
Min
1Q
-0.34970 -0.06080
Median
0.01032
3Q
0.06051
Max
0.30392
2000
2005
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.166498
0.007653 21.755 < 2e-16 ***
TIME
0.182793
0.005096 35.868 < 2e-16 ***
I(TIME^2)
0.008240
0.005955
1.384 0.167202
COS[, 1]
0.011978
0.007500
1.597 0.110981
SIN[, 1]
0.031247
0.007244
4.313 2.01e-05 ***
COS[, 2]
0.029817
0.007241
4.118 4.61e-05 ***
SIN[, 2]
0.011700
0.007214
1.622 0.105621
COS[, 3]
0.058641
0.007206
8.138 4.67e-15 ***
SIN[, 3]
-0.041532
0.007241 -5.736 1.87e-08 ***
COS[, 4]
0.043672
0.007236
6.035 3.51e-09 ***
SIN[, 4]
0.016601
0.007181
2.312 0.021271 *
COS[, 5]
0.024563
0.007184
3.419 0.000690 ***
SIN[, 5]
-0.025692
0.007233 -3.552 0.000426 ***
COS[, 6]
0.021111
0.007201
2.932 0.003556 **
SIN[, 6]
0.005659
0.007151
0.791 0.429214
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1049 on 417 degrees of freedom
Multiple R-squared: 0.7859, Adjusted R-squared: 0.7787
F-statistic: 109.3 on 14 and 417 DF, p-value: < 2.2e-16
Call:
lm(formula = temp ~ TIME + SIN[, 1] + COS[, 2] + COS[, 3] + SIN[,
3] + COS[, 4] + SIN[, 5])
Residuals:
Min
1Q
-0.34410 -0.06407
Median
0.01111
3Q
0.06032
Max
0.32233
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.173416
0.005191 33.410 < 2e-16 ***
TIME
0.183225
0.005195 35.272 < 2e-16 ***
SIN[, 1]
0.030436
0.007379
4.125 4.47e-05 ***
COS[, 2]
0.029933
0.007418
4.035 6.47e-05 ***
COS[, 3]
0.060070
0.007366
8.155 3.99e-15 ***
SIN[, 3]
-0.043848
0.007378 -5.943 5.83e-09 ***
COS[, 4]
0.041661
0.007395
5.634 3.22e-08 ***
SIN[, 5]
-0.027424
0.007371 -3.720 0.000226 ***
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1078 on 424 degrees of freedom
Multiple R-squared: 0.7702, Adjusted R-squared: 0.7664
F-statistic:
203 on 7 and 424 DF, p-value: < 2.2e-16
0.2
0.4
0.0
temp
0.4
0.6
0.8
plot(TIME,temp,type="l")
lines(as.numeric(TIME),predict(temp.lm2),col="red",type="l")
1.5
1.0
0.5
0.0
TIME
acf(resid(temp.lm2))
0.5
1.0
1.5
0.4
0.0
0.2
ACF
0.6
0.8
1.0
Series resid(temp.lm2)
10
15
Lag
pacf(resid(temp.lm2)) #AR(2)
20
25
0.3
0.1
0.1
Partial ACF
0.5
Series resid(temp.lm2)
10
15
20
Lag
Call:
arima(x = resid(temp.lm2), order = c(2, 0, 0))
Coefficients:
ar1
ar2
0.4448 0.2612
s.e. 0.0466 0.0468
intercept
0.0004
0.0134
9
25
##
## sigma^2 estimated as 0.006804:
aic = -921.24
10