R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i686-pc-linux-gnu (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> x <- array(list(31/12/1961
+ ,9190
+ ,0
+ ,5064
+ ,0
+ ,3103
+ ,0
+ ,1023
+ ,0
+ ,31/12/1962
+ ,9251
+ ,1
+ ,5109
+ ,5109
+ ,3112
+ ,3112
+ ,1030
+ ,1030
+ ,31/12/1963
+ ,9328
+ ,0
+ ,5161
+ ,0
+ ,3127
+ ,0
+ ,1041
+ ,0
+ ,31/12/1964
+ ,9428
+ ,1
+ ,5218
+ ,5218
+ ,3153
+ ,3153
+ ,1058
+ ,1058
+ ,31/12/1965
+ ,9499
+ ,0
+ ,5264
+ ,0
+ ,3169
+ ,0
+ ,1066
+ ,0
+ ,31/12/1966
+ ,9556
+ ,1
+ ,5308
+ ,5308
+ ,3174
+ ,3174
+ ,1074
+ ,1074
+ ,31/12/1967
+ ,9606
+ ,0
+ ,5347
+ ,0
+ ,3179
+ ,0
+ ,1079
+ ,0
+ ,31/12/1968
+ ,9632
+ ,1
+ ,5373
+ ,5373
+ ,3181
+ ,3181
+ ,1077
+ ,1077
+ ,31/12/1969
+ ,9660
+ ,0
+ ,5404
+ ,0
+ ,3183
+ ,0
+ ,1073
+ ,0
+ ,31/12/1970
+ ,9651
+ ,1
+ ,5416
+ ,5416
+ ,3160
+ ,3160
+ ,1075
+ ,1075
+ ,31/12/1971
+ ,9695
+ ,0
+ ,5452
+ ,0
+ ,3170
+ ,0
+ ,1074
+ ,0
+ ,31/12/1972
+ ,9727
+ ,1
+ ,5478
+ ,5478
+ ,3180
+ ,3180
+ ,1069
+ ,1069
+ ,31/12/1973
+ ,9757
+ ,0
+ ,5501
+ ,0
+ ,3192
+ ,0
+ ,1064
+ ,0
+ ,31/12/1974
+ ,9788
+ ,1
+ ,5527
+ ,5527
+ ,3206
+ ,3206
+ ,1055
+ ,1055
+ ,31/12/1975
+ ,9813
+ ,0
+ ,5548
+ ,0
+ ,3213
+ ,0
+ ,1051
+ ,0
+ ,31/12/1976
+ ,9823
+ ,1
+ ,5566
+ ,5566
+ ,3215
+ ,3215
+ ,1042
+ ,1042
+ ,31/12/1977
+ ,9837
+ ,0
+ ,5584
+ ,0
+ ,3224
+ ,0
+ ,1029
+ ,0
+ ,31/12/1978
+ ,9842
+ ,1
+ ,5601
+ ,5601
+ ,3225
+ ,3225
+ ,1016
+ ,1016
+ ,31/12/1979
+ ,9855
+ ,0
+ ,5619
+ ,0
+ ,3228
+ ,0
+ ,1009
+ ,0
+ ,31/12/1980
+ ,9863
+ ,1
+ ,5635
+ ,5635
+ ,3229
+ ,3229
+ ,1000
+ ,1000
+ ,31/12/1981
+ ,9855
+ ,0
+ ,5642
+ ,0
+ ,3218
+ ,0
+ ,994
+ ,0
+ ,31/12/1982
+ ,9858
+ ,1
+ ,5655
+ ,5655
+ ,3213
+ ,3213
+ ,990
+ ,990
+ ,31/12/1983
+ ,9853
+ ,0
+ ,5662
+ ,0
+ ,3208
+ ,0
+ ,983
+ ,0
+ ,31/12/1984
+ ,9858
+ ,1
+ ,5670
+ ,5670
+ ,3208
+ ,3208
+ ,979
+ ,979
+ ,31/12/1985
+ ,9859
+ ,0
+ ,5676
+ ,0
+ ,3206
+ ,0
+ ,976
+ ,0
+ ,31/12/1986
+ ,9865
+ ,1
+ ,5685
+ ,5685
+ ,3206
+ ,3206
+ ,973
+ ,973
+ ,31/12/1987
+ ,9876
+ ,0
+ ,5696
+ ,0
+ ,3210
+ ,0
+ ,970
+ ,0
+ ,31/12/1988
+ ,9928
+ ,1
+ ,5722
+ ,5722
+ ,3235
+ ,3235
+ ,970
+ ,970
+ ,31/12/1989
+ ,9948
+ ,0
+ ,5740
+ ,0
+ ,3244
+ ,0
+ ,964
+ ,0
+ ,31/12/1990
+ ,9987
+ ,1
+ ,5768
+ ,5768
+ ,3259
+ ,3259
+ ,961
+ ,961
+ ,31/12/1991
+ ,10022
+ ,0
+ ,5795
+ ,0
+ ,3276
+ ,0
+ ,951
+ ,0
+ ,31/12/1992
+ ,10068
+ ,1
+ ,5825
+ ,5825
+ ,3293
+ ,3293
+ ,950
+ ,950
+ ,31/12/1993
+ ,10101
+ ,0
+ ,5847
+ ,0
+ ,3305
+ ,0
+ ,949
+ ,0
+ ,31/12/1994
+ ,10131
+ ,1
+ ,5866
+ ,5866
+ ,3313
+ ,3313
+ ,952
+ ,952
+ ,31/12/1995
+ ,10143
+ ,0
+ ,5880
+ ,0
+ ,3315
+ ,0
+ ,948
+ ,0
+ ,31/12/1996
+ ,10170
+ ,1
+ ,5899
+ ,5899
+ ,3320
+ ,3320
+ ,951
+ ,951
+ ,31/12/1997
+ ,10192
+ ,0
+ ,5913
+ ,0
+ ,3326
+ ,0
+ ,953
+ ,0
+ ,31/12/1998
+ ,10214
+ ,1
+ ,5927
+ ,5927
+ ,3332
+ ,3332
+ ,955
+ ,955
+ ,31/12/1999
+ ,10239
+ ,0
+ ,5941
+ ,0
+ ,3340
+ ,0
+ ,959
+ ,0
+ ,31/12/2000
+ ,10263
+ ,1
+ ,5953
+ ,5953
+ ,3346
+ ,3346
+ ,964
+ ,964
+ ,31/12/2001
+ ,10310
+ ,0
+ ,5973
+ ,0
+ ,3358
+ ,0
+ ,979
+ ,0
+ ,31/12/2002
+ ,10355
+ ,1
+ ,5995
+ ,5995
+ ,3369
+ ,3369
+ ,992
+ ,992
+ ,31/12/2003
+ ,10396
+ ,0
+ ,6016
+ ,0
+ ,3380
+ ,0
+ ,1000
+ ,0
+ ,31/12/2004
+ ,10446
+ ,1
+ ,6043
+ ,6043
+ ,3396
+ ,3396
+ ,1007
+ ,1007
+ ,31/12/2005
+ ,10511
+ ,0
+ ,6078
+ ,0
+ ,3414
+ ,0
+ ,1019
+ ,0
+ ,31/12/2006
+ ,10585
+ ,1
+ ,6117
+ ,6117
+ ,3436
+ ,3436
+ ,1031
+ ,1031
+ ,31/12/2007
+ ,10667
+ ,0
+ ,6162
+ ,0
+ ,3456
+ ,0
+ ,1049
+ ,0
+ ,31/12/2008
+ ,10753
+ ,1
+ ,6209
+ ,6209
+ ,3476
+ ,3476
+ ,1069
+ ,1069
+ ,31/12/2009
+ ,10840
+ ,0
+ ,6252
+ ,0
+ ,3498
+ ,0
+ ,1090
+ ,0
+ ,31/12/2010
+ ,10951
+ ,1
+ ,6306
+ ,6306
+ ,3525
+ ,3525
+ ,1119
+ ,1119)
+ ,dim=c(9
+ ,50)
+ ,dimnames=list(c('jaar'
+ ,'totaal'
+ ,'pop'
+ ,'totaal_vlaams_gewest'
+ ,'pop_vlaams_gewest'
+ ,'totaal_waals_gewest'
+ ,'waals_gewest_pop'
+ ,'totaal_brussel'
+ ,'totaal_brussel_pop')
+ ,1:50))
> y <- array(NA,dim=c(9,50),dimnames=list(c('jaar','totaal','pop','totaal_vlaams_gewest','pop_vlaams_gewest','totaal_waals_gewest','waals_gewest_pop','totaal_brussel','totaal_brussel_pop'),1:50))
> for (i in 1:dim(x)[1])
+ {
+ for (j in 1:dim(x)[2])
+ {
+ y[i,j] <- as.numeric(x[i,j])
+ }
+ }
> par3 = 'Linear Trend'
> par2 = 'Do not include Seasonal Dummies'
> par1 = '2'
> library(lattice)
> library(lmtest)
Loading required package: zoo
Attaching package: 'zoo'
The following object(s) are masked from 'package:base':
as.Date, as.Date.numeric
> n25 <- 25 #minimum number of obs. for Goldfeld-Quandt test
> par1 <- as.numeric(par1)
> x <- t(y)
> k <- length(x[1,])
> n <- length(x[,1])
> x1 <- cbind(x[,par1], x[,1:k!=par1])
> mycolnames <- c(colnames(x)[par1], colnames(x)[1:k!=par1])
> colnames(x1) <- mycolnames #colnames(x)[par1]
> x <- x1
> if (par3 == 'First Differences'){
+ x2 <- array(0, dim=c(n-1,k), dimnames=list(1:(n-1), paste('(1-B)',colnames(x),sep='')))
+ for (i in 1:n-1) {
+ for (j in 1:k) {
+ x2[i,j] <- x[i+1,j] - x[i,j]
+ }
+ }
+ x <- x2
+ }
> if (par2 == 'Include Monthly Dummies'){
+ x2 <- array(0, dim=c(n,11), dimnames=list(1:n, paste('M', seq(1:11), sep ='')))
+ for (i in 1:11){
+ x2[seq(i,n,12),i] <- 1
+ }
+ x <- cbind(x, x2)
+ }
> if (par2 == 'Include Quarterly Dummies'){
+ x2 <- array(0, dim=c(n,3), dimnames=list(1:n, paste('Q', seq(1:3), sep ='')))
+ for (i in 1:3){
+ x2[seq(i,n,4),i] <- 1
+ }
+ x <- cbind(x, x2)
+ }
> k <- length(x[1,])
> if (par3 == 'Linear Trend'){
+ x <- cbind(x, c(1:n))
+ colnames(x)[k+1] <- 't'
+ }
> x
totaal jaar pop totaal_vlaams_gewest pop_vlaams_gewest
1 9190 0.001317355 0 5064 0
2 9251 0.001316684 1 5109 5109
3 9328 0.001316013 0 5161 0
4 9428 0.001315343 1 5218 5218
5 9499 0.001314673 0 5264 0
6 9556 0.001314005 1 5308 5308
7 9606 0.001313337 0 5347 0
8 9632 0.001312669 1 5373 5373
9 9660 0.001312003 0 5404 0
10 9651 0.001311337 1 5416 5416
11 9695 0.001310671 0 5452 0
12 9727 0.001310007 1 5478 5478
13 9757 0.001309343 0 5501 0
14 9788 0.001308680 1 5527 5527
15 9813 0.001308017 0 5548 0
16 9823 0.001307355 1 5566 5566
17 9837 0.001306694 0 5584 0
18 9842 0.001306033 1 5601 5601
19 9855 0.001305373 0 5619 0
20 9863 0.001304714 1 5635 5635
21 9855 0.001304055 0 5642 0
22 9858 0.001303397 1 5655 5655
23 9853 0.001302740 0 5662 0
24 9858 0.001302083 1 5670 5670
25 9859 0.001301427 0 5676 0
26 9865 0.001300772 1 5685 5685
27 9876 0.001300117 0 5696 0
28 9928 0.001299463 1 5722 5722
29 9948 0.001298810 0 5740 0
30 9987 0.001298157 1 5768 5768
31 10022 0.001297505 0 5795 0
32 10068 0.001296854 1 5825 5825
33 10101 0.001296203 0 5847 0
34 10131 0.001295553 1 5866 5866
35 10143 0.001294904 0 5880 0
36 10170 0.001294255 1 5899 5899
37 10192 0.001293607 0 5913 0
38 10214 0.001292960 1 5927 5927
39 10239 0.001292313 0 5941 0
40 10263 0.001291667 1 5953 5953
41 10310 0.001291021 0 5973 0
42 10355 0.001290376 1 5995 5995
43 10396 0.001289732 0 6016 0
44 10446 0.001289088 1 6043 6043
45 10511 0.001288446 0 6078 0
46 10585 0.001287803 1 6117 6117
47 10667 0.001287162 0 6162 0
48 10753 0.001286521 1 6209 6209
49 10840 0.001285880 0 6252 0
50 10951 0.001285240 1 6306 6306
totaal_waals_gewest waals_gewest_pop totaal_brussel totaal_brussel_pop t
1 3103 0 1023 0 1
2 3112 3112 1030 1030 2
3 3127 0 1041 0 3
4 3153 3153 1058 1058 4
5 3169 0 1066 0 5
6 3174 3174 1074 1074 6
7 3179 0 1079 0 7
8 3181 3181 1077 1077 8
9 3183 0 1073 0 9
10 3160 3160 1075 1075 10
11 3170 0 1074 0 11
12 3180 3180 1069 1069 12
13 3192 0 1064 0 13
14 3206 3206 1055 1055 14
15 3213 0 1051 0 15
16 3215 3215 1042 1042 16
17 3224 0 1029 0 17
18 3225 3225 1016 1016 18
19 3228 0 1009 0 19
20 3229 3229 1000 1000 20
21 3218 0 994 0 21
22 3213 3213 990 990 22
23 3208 0 983 0 23
24 3208 3208 979 979 24
25 3206 0 976 0 25
26 3206 3206 973 973 26
27 3210 0 970 0 27
28 3235 3235 970 970 28
29 3244 0 964 0 29
30 3259 3259 961 961 30
31 3276 0 951 0 31
32 3293 3293 950 950 32
33 3305 0 949 0 33
34 3313 3313 952 952 34
35 3315 0 948 0 35
36 3320 3320 951 951 36
37 3326 0 953 0 37
38 3332 3332 955 955 38
39 3340 0 959 0 39
40 3346 3346 964 964 40
41 3358 0 979 0 41
42 3369 3369 992 992 42
43 3380 0 1000 0 43
44 3396 3396 1007 1007 44
45 3414 0 1019 0 45
46 3436 3436 1031 1031 46
47 3456 0 1049 0 47
48 3476 3476 1069 1069 48
49 3498 0 1090 0 49
50 3525 3525 1119 1119 50
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) jaar pop
4.260e+03 -3.221e+06 1.065e+00
totaal_vlaams_gewest pop_vlaams_gewest totaal_waals_gewest
9.979e-01 1.608e-03 9.963e-01
waals_gewest_pop totaal_brussel totaal_brussel_pop
-3.932e-03 1.007e+00 2.600e-03
t
-2.036e+00
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-1.21387 -0.18806 0.03091 0.20211 1.00864
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.260e+03 1.387e+04 0.307 0.760
jaar -3.221e+06 1.052e+07 -0.306 0.761
pop 1.065e+00 9.506e+00 0.112 0.911
totaal_vlaams_gewest 9.979e-01 1.066e-02 93.634 <2e-16 ***
pop_vlaams_gewest 1.608e-03 2.987e-03 0.538 0.593
totaal_waals_gewest 9.963e-01 1.285e-02 77.527 <2e-16 ***
waals_gewest_pop -3.932e-03 8.387e-03 -0.469 0.642
totaal_brussel 1.007e+00 1.035e-02 97.290 <2e-16 ***
totaal_brussel_pop 2.600e-03 5.529e-03 0.470 0.641
t -2.036e+00 6.742e+00 -0.302 0.764
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.6587 on 40 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 1.952e+06 on 9 and 40 DF, p-value: < 2.2e-16
> if (n > n25) {
+ kp3 <- k + 3
+ nmkm3 <- n - k - 3
+ gqarr <- array(NA, dim=c(nmkm3-kp3+1,3))
+ numgqtests <- 0
+ numsignificant1 <- 0
+ numsignificant5 <- 0
+ numsignificant10 <- 0
+ for (mypoint in kp3:nmkm3) {
+ j <- 0
+ numgqtests <- numgqtests + 1
+ for (myalt in c('greater', 'two.sided', 'less')) {
+ j <- j + 1
+ gqarr[mypoint-kp3+1,j] <- gqtest(mylm, point=mypoint, alternative=myalt)$p.value
+ }
+ if (gqarr[mypoint-kp3+1,2] < 0.01) numsignificant1 <- numsignificant1 + 1
+ if (gqarr[mypoint-kp3+1,2] < 0.05) numsignificant5 <- numsignificant5 + 1
+ if (gqarr[mypoint-kp3+1,2] < 0.10) numsignificant10 <- numsignificant10 + 1
+ }
+ gqarr
+ }
[,1] [,2] [,3]
[1,] 0.8763476 0.2473047 0.1236524
[2,] 0.7888687 0.4222626 0.2111313
[3,] 0.7179122 0.5641756 0.2820878
[4,] 0.6028537 0.7942926 0.3971463
[5,] 0.7058718 0.5882564 0.2941282
[6,] 0.6347704 0.7304591 0.3652296
[7,] 0.7245125 0.5509750 0.2754875
[8,] 0.6476274 0.7047452 0.3523726
[9,] 0.7602449 0.4795103 0.2397551
[10,] 0.7410635 0.5178730 0.2589365
[11,] 0.7554091 0.4891818 0.2445909
[12,] 0.6933081 0.6133839 0.3066919
[13,] 0.6050949 0.7898102 0.3949051
[14,] 0.5527514 0.8944973 0.4472486
[15,] 0.5776747 0.8446507 0.4223253
[16,] 0.7724643 0.4550714 0.2275357
[17,] 0.7380905 0.5238191 0.2619095
[18,] 0.6755132 0.6489736 0.3244868
[19,] 0.5802870 0.8394259 0.4197130
[20,] 0.6884517 0.6230966 0.3115483
[21,] 0.5789305 0.8421389 0.4210695
[22,] 0.4821982 0.9643963 0.5178018
[23,] 0.5181564 0.9636871 0.4818436
[24,] 0.5023947 0.9952106 0.4976053
[25,] 0.5514008 0.8971983 0.4485992
> postscript(file="/var/wessaorg/rcomp/tmp/1ejvc1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> plot(x[,1], type='l', main='Actuals and Interpolation', ylab='value of Actuals and Interpolation (dots)', xlab='time or index')
> points(x[,1]-mysum$resid)
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/22zia1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> plot(mysum$resid, type='b', pch=19, main='Residuals', ylab='value of Residuals', xlab='time or index')
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/3r4181354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> hist(mysum$resid, main='Residual Histogram', xlab='values of Residuals')
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/41m8b1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> densityplot(~mysum$resid,col='black',main='Residual Density Plot', xlab='values of Residuals')
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/5q1lv1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> qqnorm(mysum$resid, main='Residual Normal Q-Q Plot')
> qqline(mysum$resid)
> grid()
> dev.off()
null device
1
> (myerror <- as.ts(mysum$resid))
Time Series:
Start = 1
End = 50
Frequency = 1
1 2 3 4 5
0.2613502114 0.4895315050 -0.8264051269 -0.6629514644 0.1246799230
6 7 8 9 10
0.1470977975 1.0086389505 0.9722792593 -0.0415898424 -0.3698584984
11 12 13 14 15
-1.2138653055 -0.3428336253 -0.1685479246 -0.1904770636 0.8986234552
16 17 18 19 20
-0.1735848524 -0.0223186156 -0.0173138101 -0.9766834575 -0.9948721283
21 22 23 24 25
0.9656876827 -0.1808269211 -0.1176650903 0.7330468024 0.7966407115
26 27 28 29 30
0.6302834889 -0.2528711074 0.7542105630 -0.1329271637 -1.0896754219
31 32 33 34 35
0.0600083200 0.1756298831 0.1668758618 0.2099690085 0.1653005967
36 37 38 39 40
0.1785261079 0.1337268219 0.1432268515 -0.8957700578 0.0825398946
41 42 43 44 45
0.0079871411 -1.0762788804 -0.0493037488 -0.0684604789 -0.0003766129
46 47 48 49 50
0.9725462595 0.0549651361 -1.1043764276 0.0538392416 0.7826221513
> postscript(file="/var/wessaorg/rcomp/tmp/6nbv91354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> dum <- cbind(lag(myerror,k=1),myerror)
> dum
Time Series:
Start = 0
End = 50
Frequency = 1
lag(myerror, k = 1) myerror
0 0.2613502114 NA
1 0.4895315050 0.2613502114
2 -0.8264051269 0.4895315050
3 -0.6629514644 -0.8264051269
4 0.1246799230 -0.6629514644
5 0.1470977975 0.1246799230
6 1.0086389505 0.1470977975
7 0.9722792593 1.0086389505
8 -0.0415898424 0.9722792593
9 -0.3698584984 -0.0415898424
10 -1.2138653055 -0.3698584984
11 -0.3428336253 -1.2138653055
12 -0.1685479246 -0.3428336253
13 -0.1904770636 -0.1685479246
14 0.8986234552 -0.1904770636
15 -0.1735848524 0.8986234552
16 -0.0223186156 -0.1735848524
17 -0.0173138101 -0.0223186156
18 -0.9766834575 -0.0173138101
19 -0.9948721283 -0.9766834575
20 0.9656876827 -0.9948721283
21 -0.1808269211 0.9656876827
22 -0.1176650903 -0.1808269211
23 0.7330468024 -0.1176650903
24 0.7966407115 0.7330468024
25 0.6302834889 0.7966407115
26 -0.2528711074 0.6302834889
27 0.7542105630 -0.2528711074
28 -0.1329271637 0.7542105630
29 -1.0896754219 -0.1329271637
30 0.0600083200 -1.0896754219
31 0.1756298831 0.0600083200
32 0.1668758618 0.1756298831
33 0.2099690085 0.1668758618
34 0.1653005967 0.2099690085
35 0.1785261079 0.1653005967
36 0.1337268219 0.1785261079
37 0.1432268515 0.1337268219
38 -0.8957700578 0.1432268515
39 0.0825398946 -0.8957700578
40 0.0079871411 0.0825398946
41 -1.0762788804 0.0079871411
42 -0.0493037488 -1.0762788804
43 -0.0684604789 -0.0493037488
44 -0.0003766129 -0.0684604789
45 0.9725462595 -0.0003766129
46 0.0549651361 0.9725462595
47 -1.1043764276 0.0549651361
48 0.0538392416 -1.1043764276
49 0.7826221513 0.0538392416
50 NA 0.7826221513
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] 0.4895315050 0.2613502114
[2,] -0.8264051269 0.4895315050
[3,] -0.6629514644 -0.8264051269
[4,] 0.1246799230 -0.6629514644
[5,] 0.1470977975 0.1246799230
[6,] 1.0086389505 0.1470977975
[7,] 0.9722792593 1.0086389505
[8,] -0.0415898424 0.9722792593
[9,] -0.3698584984 -0.0415898424
[10,] -1.2138653055 -0.3698584984
[11,] -0.3428336253 -1.2138653055
[12,] -0.1685479246 -0.3428336253
[13,] -0.1904770636 -0.1685479246
[14,] 0.8986234552 -0.1904770636
[15,] -0.1735848524 0.8986234552
[16,] -0.0223186156 -0.1735848524
[17,] -0.0173138101 -0.0223186156
[18,] -0.9766834575 -0.0173138101
[19,] -0.9948721283 -0.9766834575
[20,] 0.9656876827 -0.9948721283
[21,] -0.1808269211 0.9656876827
[22,] -0.1176650903 -0.1808269211
[23,] 0.7330468024 -0.1176650903
[24,] 0.7966407115 0.7330468024
[25,] 0.6302834889 0.7966407115
[26,] -0.2528711074 0.6302834889
[27,] 0.7542105630 -0.2528711074
[28,] -0.1329271637 0.7542105630
[29,] -1.0896754219 -0.1329271637
[30,] 0.0600083200 -1.0896754219
[31,] 0.1756298831 0.0600083200
[32,] 0.1668758618 0.1756298831
[33,] 0.2099690085 0.1668758618
[34,] 0.1653005967 0.2099690085
[35,] 0.1785261079 0.1653005967
[36,] 0.1337268219 0.1785261079
[37,] 0.1432268515 0.1337268219
[38,] -0.8957700578 0.1432268515
[39,] 0.0825398946 -0.8957700578
[40,] 0.0079871411 0.0825398946
[41,] -1.0762788804 0.0079871411
[42,] -0.0493037488 -1.0762788804
[43,] -0.0684604789 -0.0493037488
[44,] -0.0003766129 -0.0684604789
[45,] 0.9725462595 -0.0003766129
[46,] 0.0549651361 0.9725462595
[47,] -1.1043764276 0.0549651361
[48,] 0.0538392416 -1.1043764276
[49,] 0.7826221513 0.0538392416
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 0.4895315050 0.2613502114
2 -0.8264051269 0.4895315050
3 -0.6629514644 -0.8264051269
4 0.1246799230 -0.6629514644
5 0.1470977975 0.1246799230
6 1.0086389505 0.1470977975
7 0.9722792593 1.0086389505
8 -0.0415898424 0.9722792593
9 -0.3698584984 -0.0415898424
10 -1.2138653055 -0.3698584984
11 -0.3428336253 -1.2138653055
12 -0.1685479246 -0.3428336253
13 -0.1904770636 -0.1685479246
14 0.8986234552 -0.1904770636
15 -0.1735848524 0.8986234552
16 -0.0223186156 -0.1735848524
17 -0.0173138101 -0.0223186156
18 -0.9766834575 -0.0173138101
19 -0.9948721283 -0.9766834575
20 0.9656876827 -0.9948721283
21 -0.1808269211 0.9656876827
22 -0.1176650903 -0.1808269211
23 0.7330468024 -0.1176650903
24 0.7966407115 0.7330468024
25 0.6302834889 0.7966407115
26 -0.2528711074 0.6302834889
27 0.7542105630 -0.2528711074
28 -0.1329271637 0.7542105630
29 -1.0896754219 -0.1329271637
30 0.0600083200 -1.0896754219
31 0.1756298831 0.0600083200
32 0.1668758618 0.1756298831
33 0.2099690085 0.1668758618
34 0.1653005967 0.2099690085
35 0.1785261079 0.1653005967
36 0.1337268219 0.1785261079
37 0.1432268515 0.1337268219
38 -0.8957700578 0.1432268515
39 0.0825398946 -0.8957700578
40 0.0079871411 0.0825398946
41 -1.0762788804 0.0079871411
42 -0.0493037488 -1.0762788804
43 -0.0684604789 -0.0493037488
44 -0.0003766129 -0.0684604789
45 0.9725462595 -0.0003766129
46 0.0549651361 0.9725462595
47 -1.1043764276 0.0549651361
48 0.0538392416 -1.1043764276
49 0.7826221513 0.0538392416
> plot(z,main=paste('Residual Lag plot, lowess, and regression line'), ylab='values of Residuals', xlab='lagged values of Residuals')
> lines(lowess(z))
> abline(lm(z))
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/7qjcf1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> acf(mysum$resid, lag.max=length(mysum$resid)/2, main='Residual Autocorrelation Function')
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/8yf681354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> pacf(mysum$resid, lag.max=length(mysum$resid)/2, main='Residual Partial Autocorrelation Function')
> grid()
> dev.off()
null device
1
> postscript(file="/var/wessaorg/rcomp/tmp/9y1ug1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
> plot(mylm, las = 1, sub='Residual Diagnostics')
> par(opar)
> dev.off()
null device
1
> if (n > n25) {
+ postscript(file="/var/wessaorg/rcomp/tmp/10iw6c1354824224.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
+ plot(kp3:nmkm3,gqarr[,2], main='Goldfeld-Quandt test',ylab='2-sided p-value',xlab='breakpoint')
+ grid()
+ dev.off()
+ }
null device
1
>
> #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
> load(file="/var/wessaorg/rcomp/createtable")
>
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Estimated Regression Equation', 1, TRUE)
> a<-table.row.end(a)
> myeq <- colnames(x)[1]
> myeq <- paste(myeq, '[t] = ', sep='')
> for (i in 1:k){
+ if (mysum$coefficients[i,1] > 0) myeq <- paste(myeq, '+', '')
+ myeq <- paste(myeq, mysum$coefficients[i,1], sep=' ')
+ if (rownames(mysum$coefficients)[i] != '(Intercept)') {
+ myeq <- paste(myeq, rownames(mysum$coefficients)[i], sep='')
+ if (rownames(mysum$coefficients)[i] != 't') myeq <- paste(myeq, '[t]', sep='')
+ }
+ }
> myeq <- paste(myeq, ' + e[t]')
> a<-table.row.start(a)
> a<-table.element(a, myeq)
> a<-table.row.end(a)
> a<-table.end(a)
> table.save(a,file="/var/wessaorg/rcomp/tmp/11yxqs1354824224.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a,hyperlink('http://www.xycoon.com/ols1.htm','Multiple Linear Regression - Ordinary Least Squares',''), 6, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a,'Variable',header=TRUE)
> a<-table.element(a,'Parameter',header=TRUE)
> a<-table.element(a,'S.D.',header=TRUE)
> a<-table.element(a,'T-STAT
H0: parameter = 0',header=TRUE)
> a<-table.element(a,'2-tail p-value',header=TRUE)
> a<-table.element(a,'1-tail p-value',header=TRUE)
> a<-table.row.end(a)
> for (i in 1:k){
+ a<-table.row.start(a)
+ a<-table.element(a,rownames(mysum$coefficients)[i],header=TRUE)
+ a<-table.element(a,mysum$coefficients[i,1])
+ a<-table.element(a, round(mysum$coefficients[i,2],6))
+ a<-table.element(a, round(mysum$coefficients[i,3],4))
+ a<-table.element(a, round(mysum$coefficients[i,4],6))
+ a<-table.element(a, round(mysum$coefficients[i,4]/2,6))
+ a<-table.row.end(a)
+ }
> a<-table.end(a)
> table.save(a,file="/var/wessaorg/rcomp/tmp/12txyj1354824224.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Regression Statistics', 2, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple R',1,TRUE)
> a<-table.element(a, sqrt(mysum$r.squared))
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'R-squared',1,TRUE)
> a<-table.element(a, mysum$r.squared)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Adjusted R-squared',1,TRUE)
> a<-table.element(a, mysum$adj.r.squared)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (value)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[1])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (DF numerator)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[2])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (DF denominator)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[3])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'p-value',1,TRUE)
> a<-table.element(a, 1-pf(mysum$fstatistic[1],mysum$fstatistic[2],mysum$fstatistic[3]))
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Residual Statistics', 2, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Residual Standard Deviation',1,TRUE)
> a<-table.element(a, mysum$sigma)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Sum Squared Residuals',1,TRUE)
> a<-table.element(a, sum(myerror*myerror))
> a<-table.row.end(a)
> a<-table.end(a)
> table.save(a,file="/var/wessaorg/rcomp/tmp/13ae0d1354824225.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Actuals, Interpolation, and Residuals', 4, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Time or Index', 1, TRUE)
> a<-table.element(a, 'Actuals', 1, TRUE)
> a<-table.element(a, 'Interpolation
Forecast', 1, TRUE)
> a<-table.element(a, 'Residuals
Prediction Error', 1, TRUE)
> a<-table.row.end(a)
> for (i in 1:n) {
+ a<-table.row.start(a)
+ a<-table.element(a,i, 1, TRUE)
+ a<-table.element(a,x[i])
+ a<-table.element(a,x[i]-mysum$resid[i])
+ a<-table.element(a,mysum$resid[i])
+ a<-table.row.end(a)
+ }
> a<-table.end(a)
> table.save(a,file="/var/wessaorg/rcomp/tmp/14ukuj1354824225.tab")
> if (n > n25) {
+ a<-table.start()
+ a<-table.row.start(a)
+ a<-table.element(a,'Goldfeld-Quandt test for Heteroskedasticity',4,TRUE)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'p-values',header=TRUE)
+ a<-table.element(a,'Alternative Hypothesis',3,header=TRUE)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'breakpoint index',header=TRUE)
+ a<-table.element(a,'greater',header=TRUE)
+ a<-table.element(a,'2-sided',header=TRUE)
+ a<-table.element(a,'less',header=TRUE)
+ a<-table.row.end(a)
+ for (mypoint in kp3:nmkm3) {
+ a<-table.row.start(a)
+ a<-table.element(a,mypoint,header=TRUE)
+ a<-table.element(a,gqarr[mypoint-kp3+1,1])
+ a<-table.element(a,gqarr[mypoint-kp3+1,2])
+ a<-table.element(a,gqarr[mypoint-kp3+1,3])
+ a<-table.row.end(a)
+ }
+ a<-table.end(a)
+ table.save(a,file="/var/wessaorg/rcomp/tmp/15eel01354824225.tab")
+ a<-table.start()
+ a<-table.row.start(a)
+ a<-table.element(a,'Meta Analysis of Goldfeld-Quandt test for Heteroskedasticity',4,TRUE)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'Description',header=TRUE)
+ a<-table.element(a,'# significant tests',header=TRUE)
+ a<-table.element(a,'% significant tests',header=TRUE)
+ a<-table.element(a,'OK/NOK',header=TRUE)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'1% type I error level',header=TRUE)
+ a<-table.element(a,numsignificant1)
+ a<-table.element(a,numsignificant1/numgqtests)
+ if (numsignificant1/numgqtests < 0.01) dum <- 'OK' else dum <- 'NOK'
+ a<-table.element(a,dum)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'5% type I error level',header=TRUE)
+ a<-table.element(a,numsignificant5)
+ a<-table.element(a,numsignificant5/numgqtests)
+ if (numsignificant5/numgqtests < 0.05) dum <- 'OK' else dum <- 'NOK'
+ a<-table.element(a,dum)
+ a<-table.row.end(a)
+ a<-table.row.start(a)
+ a<-table.element(a,'10% type I error level',header=TRUE)
+ a<-table.element(a,numsignificant10)
+ a<-table.element(a,numsignificant10/numgqtests)
+ if (numsignificant10/numgqtests < 0.1) dum <- 'OK' else dum <- 'NOK'
+ a<-table.element(a,dum)
+ a<-table.row.end(a)
+ a<-table.end(a)
+ table.save(a,file="/var/wessaorg/rcomp/tmp/1657et1354824225.tab")
+ }
>
> try(system("convert tmp/1ejvc1354824224.ps tmp/1ejvc1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/22zia1354824224.ps tmp/22zia1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/3r4181354824224.ps tmp/3r4181354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/41m8b1354824224.ps tmp/41m8b1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/5q1lv1354824224.ps tmp/5q1lv1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/6nbv91354824224.ps tmp/6nbv91354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/7qjcf1354824224.ps tmp/7qjcf1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/8yf681354824224.ps tmp/8yf681354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/9y1ug1354824224.ps tmp/9y1ug1354824224.png",intern=TRUE))
character(0)
> try(system("convert tmp/10iw6c1354824224.ps tmp/10iw6c1354824224.png",intern=TRUE))
character(0)
>
>
> proc.time()
user system elapsed
5.824 1.154 6.983