R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-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(1
+ ,1
+ ,1
+ ,1167
+ ,333
+ ,333
+ ,70
+ ,70
+ ,1
+ ,2
+ ,2
+ ,669
+ ,223
+ ,223
+ ,44
+ ,44
+ ,1
+ ,3
+ ,3
+ ,1053
+ ,371
+ ,371
+ ,35
+ ,35
+ ,1
+ ,4
+ ,4
+ ,1939
+ ,873
+ ,873
+ ,119
+ ,119
+ ,1
+ ,5
+ ,5
+ ,678
+ ,186
+ ,186
+ ,30
+ ,30
+ ,1
+ ,6
+ ,6
+ ,321
+ ,111
+ ,111
+ ,23
+ ,23
+ ,1
+ ,7
+ ,7
+ ,2667
+ ,1277
+ ,1277
+ ,46
+ ,46
+ ,1
+ ,8
+ ,8
+ ,345
+ ,102
+ ,102
+ ,39
+ ,39
+ ,1
+ ,9
+ ,9
+ ,1367
+ ,580
+ ,580
+ ,58
+ ,58
+ ,1
+ ,10
+ ,10
+ ,1158
+ ,420
+ ,420
+ ,51
+ ,51
+ ,1
+ ,11
+ ,11
+ ,1385
+ ,521
+ ,521
+ ,65
+ ,65
+ ,1
+ ,12
+ ,12
+ ,1155
+ ,358
+ ,358
+ ,40
+ ,40
+ ,1
+ ,13
+ ,13
+ ,1120
+ ,435
+ ,435
+ ,41
+ ,41
+ ,1
+ ,14
+ ,14
+ ,1703
+ ,690
+ ,690
+ ,76
+ ,76
+ ,1
+ ,15
+ ,15
+ ,1189
+ ,393
+ ,393
+ ,31
+ ,31
+ ,1
+ ,16
+ ,16
+ ,3083
+ ,1149
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+ ,753
+ ,0
+ ,158
+ ,0
+ ,0
+ ,59
+ ,0
+ ,1653
+ ,689
+ ,0
+ ,46
+ ,0
+ ,0
+ ,60
+ ,0
+ ,1234
+ ,470
+ ,0
+ ,45
+ ,0)
+ ,dim=c(8
+ ,60)
+ ,dimnames=list(c('Pop'
+ ,'t'
+ ,'pop_t'
+ ,'y'
+ ,'x1'
+ ,'x1_p'
+ ,'x2'
+ ,'x2_p')
+ ,1:60))
> y <- array(NA,dim=c(8,60),dimnames=list(c('Pop','t','pop_t','y','x1','x1_p','x2','x2_p'),1:60))
> for (i in 1:dim(x)[1])
+ {
+ for (j in 1:dim(x)[2])
+ {
+ y[i,j] <- as.numeric(x[i,j])
+ }
+ }
> par3 = 'No Linear Trend'
> par2 = 'Do not include Seasonal Dummies'
> par1 = '4'
> library(lattice)
> library(lmtest)
Loading required package: zoo
> 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
y Pop t pop_t x1 x1_p x2 x2_p
1 1167 1 1 1 333 333 70 70
2 669 1 2 2 223 223 44 44
3 1053 1 3 3 371 371 35 35
4 1939 1 4 4 873 873 119 119
5 678 1 5 5 186 186 30 30
6 321 1 6 6 111 111 23 23
7 2667 1 7 7 1277 1277 46 46
8 345 1 8 8 102 102 39 39
9 1367 1 9 9 580 580 58 58
10 1158 1 10 10 420 420 51 51
11 1385 1 11 11 521 521 65 65
12 1155 1 12 12 358 358 40 40
13 1120 1 13 13 435 435 41 41
14 1703 1 14 14 690 690 76 76
15 1189 1 15 15 393 393 31 31
16 3083 1 16 16 1149 1149 82 82
17 1357 1 17 17 486 486 36 36
18 1892 1 18 18 767 767 62 62
19 883 1 19 19 338 338 28 28
20 1627 1 20 20 485 485 38 38
21 1412 1 21 21 465 465 70 70
22 1900 1 22 22 816 816 76 76
23 777 1 23 23 265 265 33 33
24 904 1 24 24 307 307 40 40
25 2115 1 25 25 850 850 126 126
26 1858 1 26 26 704 704 56 56
27 1781 1 27 27 693 693 63 63
28 1286 1 28 28 387 387 46 46
29 1035 1 29 29 406 406 35 35
30 1557 1 30 30 573 573 108 108
31 1527 0 31 0 595 0 34 0
32 1220 0 32 0 394 0 54 0
33 1368 0 33 0 521 0 35 0
34 564 0 34 0 172 0 23 0
35 1990 0 35 0 835 0 46 0
36 1557 0 36 0 669 0 49 0
37 2057 0 37 0 749 0 56 0
38 1111 0 38 0 368 0 38 0
39 686 0 39 0 216 0 19 0
40 2011 0 40 0 772 0 29 0
41 2232 0 41 0 1084 0 26 0
42 1032 0 42 0 445 0 52 0
43 1166 0 43 0 451 0 54 0
44 1020 0 44 0 300 0 45 0
45 1735 0 45 0 836 0 56 0
46 3623 0 46 0 1417 0 596 0
47 918 0 47 0 330 0 57 0
48 1579 0 48 0 477 0 55 0
49 2790 0 49 0 1028 0 99 0
50 1496 0 50 0 646 0 51 0
51 1108 0 51 0 342 0 21 0
52 496 0 52 0 218 0 20 0
53 1750 0 53 0 591 0 58 0
54 744 0 54 0 255 0 21 0
55 1101 0 55 0 434 0 66 0
56 1612 0 56 0 654 0 47 0
57 1805 0 57 0 478 0 55 0
58 2460 0 58 0 753 0 158 0
59 1653 0 59 0 689 0 46 0
60 1234 0 60 0 470 0 45 0
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) Pop t pop_t x1 x1_p
61.407593 127.734587 4.823237 0.136681 2.054663 0.008315
x2 x2_p
0.945522 -0.169169
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-314.10 -122.37 -24.78 88.23 434.54
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 61.407593 195.515413 0.314 0.7547
Pop 127.734587 216.831301 0.589 0.5583
t 4.823237 3.843805 1.255 0.2152
pop_t 0.136681 5.465292 0.025 0.9801
x1 2.054663 0.153570 13.379 <2e-16 ***
x1_p 0.008315 0.214291 0.039 0.9692
x2 0.945522 0.421586 2.243 0.0292 *
x2_p -0.169169 1.642450 -0.103 0.9184
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 180.9 on 52 degrees of freedom
Multiple R-squared: 0.9311, Adjusted R-squared: 0.9218
F-statistic: 100.3 on 7 and 52 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.6394027188 0.7211945624 0.3605973
[2,] 0.6197420085 0.7605159829 0.3802580
[3,] 0.4764288223 0.9528576447 0.5235712
[4,] 0.3510858843 0.7021717685 0.6489141
[5,] 0.2780706357 0.5561412713 0.7219294
[6,] 0.6255827534 0.7488344932 0.3744172
[7,] 0.5173891140 0.9652217720 0.4826109
[8,] 0.4302310986 0.8604621972 0.5697689
[9,] 0.4052727213 0.8105454425 0.5947273
[10,] 0.4773160503 0.9546321007 0.5226839
[11,] 0.3997208505 0.7994417010 0.6002791
[12,] 0.4067409910 0.8134819819 0.5932590
[13,] 0.3596359344 0.7192718687 0.6403641
[14,] 0.2998189426 0.5996378853 0.7001811
[15,] 0.2572760052 0.5145520104 0.7427240
[16,] 0.1914529045 0.3829058090 0.8085471
[17,] 0.1377968588 0.2755937176 0.8622031
[18,] 0.1016171967 0.2032343935 0.8983828
[19,] 0.0870510445 0.1741020890 0.9129490
[20,] 0.0586086583 0.1172173165 0.9413913
[21,] 0.0377871581 0.0755743162 0.9622128
[22,] 0.0261715473 0.0523430947 0.9738285
[23,] 0.0159557331 0.0319114662 0.9840443
[24,] 0.0090414653 0.0180829307 0.9909585
[25,] 0.0049574011 0.0099148021 0.9950426
[26,] 0.0027806906 0.0055613811 0.9972193
[27,] 0.0038874073 0.0077748146 0.9961126
[28,] 0.0024525125 0.0049050251 0.9975475
[29,] 0.0012707258 0.0025414516 0.9987293
[30,] 0.0013302429 0.0026604857 0.9986698
[31,] 0.0013573193 0.0027146387 0.9986427
[32,] 0.0012031017 0.0024062034 0.9987969
[33,] 0.0005313627 0.0010627253 0.9994686
[34,] 0.0004195976 0.0008391952 0.9995804
[35,] 0.0009031596 0.0018063192 0.9990968
[36,] 0.0063310372 0.0126620744 0.9936690
[37,] 0.0045280544 0.0090561089 0.9954719
[38,] 0.0064662553 0.0129325105 0.9935337
[39,] 0.0058770639 0.0117541277 0.9941229
> postscript(file="/var/wessaorg/rcomp/tmp/11w161321960222.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/2hqlq1321960222.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/3trba1321960222.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/49uzz1321960222.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/5yxa01321960222.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 = 60
Frequency = 1
1 2 3 4 5 6
231.5814384 -24.2656931 56.4408075 -163.3478281 57.0536946 -144.7483884
7 8 9 10 11 12
-226.9969391 -124.5230765 -108.3372581 13.2138002 16.0241420 136.7384981
13 14 15 16 17 18
-62.8470891 -38.0388036 90.6416926 380.4762775 52.9831237 -16.8588405
19 20 21 22 23 24
-119.4051196 308.6136423 105.0699748 -140.6533883 -98.5291535 -68.5686273
25 26 27 28 29 30
-49.4920733 44.0875629 -20.6140698 123.8953310 -162.7212823 -46.8723548
31 32 33 34 35 36
61.3995959 143.6532602 43.8526911 -36.5467575 0.6411699 -98.9445100
37 38 39 40 41 42
225.2405275 74.2634396 -25.2860431 143.0426537 -278.9989954 -195.4758976
43 44 45 46 47 48
-80.5181589 87.4224747 -314.1010827 -135.2656482 -102.0334021 253.9988864
49 50 51 52 53 54
286.4531511 -182.1036125 78.0564828 -283.0429714 163.8145092 -121.6575127
55 56 57 58 59 60
-179.8139883 -107.6982528 434.5350911 422.2906520 -152.1356601 -125.0420921
> postscript(file="/var/wessaorg/rcomp/tmp/64lgl1321960222.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 = 60
Frequency = 1
lag(myerror, k = 1) myerror
0 231.5814384 NA
1 -24.2656931 231.5814384
2 56.4408075 -24.2656931
3 -163.3478281 56.4408075
4 57.0536946 -163.3478281
5 -144.7483884 57.0536946
6 -226.9969391 -144.7483884
7 -124.5230765 -226.9969391
8 -108.3372581 -124.5230765
9 13.2138002 -108.3372581
10 16.0241420 13.2138002
11 136.7384981 16.0241420
12 -62.8470891 136.7384981
13 -38.0388036 -62.8470891
14 90.6416926 -38.0388036
15 380.4762775 90.6416926
16 52.9831237 380.4762775
17 -16.8588405 52.9831237
18 -119.4051196 -16.8588405
19 308.6136423 -119.4051196
20 105.0699748 308.6136423
21 -140.6533883 105.0699748
22 -98.5291535 -140.6533883
23 -68.5686273 -98.5291535
24 -49.4920733 -68.5686273
25 44.0875629 -49.4920733
26 -20.6140698 44.0875629
27 123.8953310 -20.6140698
28 -162.7212823 123.8953310
29 -46.8723548 -162.7212823
30 61.3995959 -46.8723548
31 143.6532602 61.3995959
32 43.8526911 143.6532602
33 -36.5467575 43.8526911
34 0.6411699 -36.5467575
35 -98.9445100 0.6411699
36 225.2405275 -98.9445100
37 74.2634396 225.2405275
38 -25.2860431 74.2634396
39 143.0426537 -25.2860431
40 -278.9989954 143.0426537
41 -195.4758976 -278.9989954
42 -80.5181589 -195.4758976
43 87.4224747 -80.5181589
44 -314.1010827 87.4224747
45 -135.2656482 -314.1010827
46 -102.0334021 -135.2656482
47 253.9988864 -102.0334021
48 286.4531511 253.9988864
49 -182.1036125 286.4531511
50 78.0564828 -182.1036125
51 -283.0429714 78.0564828
52 163.8145092 -283.0429714
53 -121.6575127 163.8145092
54 -179.8139883 -121.6575127
55 -107.6982528 -179.8139883
56 434.5350911 -107.6982528
57 422.2906520 434.5350911
58 -152.1356601 422.2906520
59 -125.0420921 -152.1356601
60 NA -125.0420921
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] -24.2656931 231.5814384
[2,] 56.4408075 -24.2656931
[3,] -163.3478281 56.4408075
[4,] 57.0536946 -163.3478281
[5,] -144.7483884 57.0536946
[6,] -226.9969391 -144.7483884
[7,] -124.5230765 -226.9969391
[8,] -108.3372581 -124.5230765
[9,] 13.2138002 -108.3372581
[10,] 16.0241420 13.2138002
[11,] 136.7384981 16.0241420
[12,] -62.8470891 136.7384981
[13,] -38.0388036 -62.8470891
[14,] 90.6416926 -38.0388036
[15,] 380.4762775 90.6416926
[16,] 52.9831237 380.4762775
[17,] -16.8588405 52.9831237
[18,] -119.4051196 -16.8588405
[19,] 308.6136423 -119.4051196
[20,] 105.0699748 308.6136423
[21,] -140.6533883 105.0699748
[22,] -98.5291535 -140.6533883
[23,] -68.5686273 -98.5291535
[24,] -49.4920733 -68.5686273
[25,] 44.0875629 -49.4920733
[26,] -20.6140698 44.0875629
[27,] 123.8953310 -20.6140698
[28,] -162.7212823 123.8953310
[29,] -46.8723548 -162.7212823
[30,] 61.3995959 -46.8723548
[31,] 143.6532602 61.3995959
[32,] 43.8526911 143.6532602
[33,] -36.5467575 43.8526911
[34,] 0.6411699 -36.5467575
[35,] -98.9445100 0.6411699
[36,] 225.2405275 -98.9445100
[37,] 74.2634396 225.2405275
[38,] -25.2860431 74.2634396
[39,] 143.0426537 -25.2860431
[40,] -278.9989954 143.0426537
[41,] -195.4758976 -278.9989954
[42,] -80.5181589 -195.4758976
[43,] 87.4224747 -80.5181589
[44,] -314.1010827 87.4224747
[45,] -135.2656482 -314.1010827
[46,] -102.0334021 -135.2656482
[47,] 253.9988864 -102.0334021
[48,] 286.4531511 253.9988864
[49,] -182.1036125 286.4531511
[50,] 78.0564828 -182.1036125
[51,] -283.0429714 78.0564828
[52,] 163.8145092 -283.0429714
[53,] -121.6575127 163.8145092
[54,] -179.8139883 -121.6575127
[55,] -107.6982528 -179.8139883
[56,] 434.5350911 -107.6982528
[57,] 422.2906520 434.5350911
[58,] -152.1356601 422.2906520
[59,] -125.0420921 -152.1356601
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 -24.2656931 231.5814384
2 56.4408075 -24.2656931
3 -163.3478281 56.4408075
4 57.0536946 -163.3478281
5 -144.7483884 57.0536946
6 -226.9969391 -144.7483884
7 -124.5230765 -226.9969391
8 -108.3372581 -124.5230765
9 13.2138002 -108.3372581
10 16.0241420 13.2138002
11 136.7384981 16.0241420
12 -62.8470891 136.7384981
13 -38.0388036 -62.8470891
14 90.6416926 -38.0388036
15 380.4762775 90.6416926
16 52.9831237 380.4762775
17 -16.8588405 52.9831237
18 -119.4051196 -16.8588405
19 308.6136423 -119.4051196
20 105.0699748 308.6136423
21 -140.6533883 105.0699748
22 -98.5291535 -140.6533883
23 -68.5686273 -98.5291535
24 -49.4920733 -68.5686273
25 44.0875629 -49.4920733
26 -20.6140698 44.0875629
27 123.8953310 -20.6140698
28 -162.7212823 123.8953310
29 -46.8723548 -162.7212823
30 61.3995959 -46.8723548
31 143.6532602 61.3995959
32 43.8526911 143.6532602
33 -36.5467575 43.8526911
34 0.6411699 -36.5467575
35 -98.9445100 0.6411699
36 225.2405275 -98.9445100
37 74.2634396 225.2405275
38 -25.2860431 74.2634396
39 143.0426537 -25.2860431
40 -278.9989954 143.0426537
41 -195.4758976 -278.9989954
42 -80.5181589 -195.4758976
43 87.4224747 -80.5181589
44 -314.1010827 87.4224747
45 -135.2656482 -314.1010827
46 -102.0334021 -135.2656482
47 253.9988864 -102.0334021
48 286.4531511 253.9988864
49 -182.1036125 286.4531511
50 78.0564828 -182.1036125
51 -283.0429714 78.0564828
52 163.8145092 -283.0429714
53 -121.6575127 163.8145092
54 -179.8139883 -121.6575127
55 -107.6982528 -179.8139883
56 434.5350911 -107.6982528
57 422.2906520 434.5350911
58 -152.1356601 422.2906520
59 -125.0420921 -152.1356601
> 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/7k5n21321960222.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/86bw81321960222.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/97xfo1321960222.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/10o1ei1321960222.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/11sqs21321960222.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/12kr1i1321960222.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/13ocit1321960222.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/14xzeh1321960222.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/1551jb1321960222.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/16cgkk1321960222.tab")
+ }
>
> try(system("convert tmp/11w161321960222.ps tmp/11w161321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/2hqlq1321960222.ps tmp/2hqlq1321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/3trba1321960222.ps tmp/3trba1321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/49uzz1321960222.ps tmp/49uzz1321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/5yxa01321960222.ps tmp/5yxa01321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/64lgl1321960222.ps tmp/64lgl1321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/7k5n21321960222.ps tmp/7k5n21321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/86bw81321960222.ps tmp/86bw81321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/97xfo1321960222.ps tmp/97xfo1321960222.png",intern=TRUE))
character(0)
> try(system("convert tmp/10o1ei1321960222.ps tmp/10o1ei1321960222.png",intern=TRUE))
character(0)
>
>
> proc.time()
user system elapsed
3.249 0.486 3.764