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(41
+ ,38
+ ,13
+ ,12
+ ,14
+ ,12
+ ,53
+ ,32
+ ,39
+ ,32
+ ,16
+ ,11
+ ,18
+ ,11
+ ,86
+ ,51
+ ,30
+ ,35
+ ,19
+ ,15
+ ,11
+ ,14
+ ,66
+ ,42
+ ,31
+ ,33
+ ,15
+ ,6
+ ,12
+ ,12
+ ,67
+ ,41
+ ,34
+ ,37
+ ,14
+ ,13
+ ,16
+ ,21
+ ,76
+ ,46
+ ,35
+ ,29
+ ,13
+ ,10
+ ,18
+ ,12
+ ,78
+ ,47
+ ,39
+ ,31
+ ,19
+ ,12
+ ,14
+ ,22
+ ,53
+ ,37
+ ,34
+ ,36
+ ,15
+ ,14
+ ,14
+ ,11
+ ,80
+ ,49
+ ,36
+ ,35
+ ,14
+ ,12
+ ,15
+ ,10
+ ,74
+ ,45
+ ,37
+ ,38
+ ,15
+ ,6
+ ,15
+ ,13
+ ,76
+ ,47
+ ,38
+ ,31
+ ,16
+ ,10
+ ,17
+ ,10
+ ,79
+ ,49
+ ,36
+ ,34
+ ,16
+ ,12
+ ,19
+ ,8
+ ,54
+ ,33
+ ,38
+ ,35
+ ,16
+ ,12
+ ,10
+ ,15
+ ,67
+ ,42
+ ,39
+ ,38
+ ,16
+ ,11
+ ,16
+ ,14
+ ,54
+ ,33
+ ,33
+ ,37
+ ,17
+ ,15
+ ,18
+ ,10
+ ,87
+ ,53
+ ,32
+ ,33
+ ,15
+ ,12
+ ,14
+ ,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+ ,11
+ ,12
+ ,10
+ ,73
+ ,43
+ ,35
+ ,34
+ ,16
+ ,10
+ ,12
+ ,15
+ ,70
+ ,43
+ ,30
+ ,28
+ ,12
+ ,7
+ ,8
+ ,20
+ ,53
+ ,32
+ ,38
+ ,34
+ ,16
+ ,12
+ ,13
+ ,12
+ ,77
+ ,45
+ ,34
+ ,35
+ ,16
+ ,14
+ ,11
+ ,12
+ ,77
+ ,45
+ ,31
+ ,35
+ ,14
+ ,11
+ ,14
+ ,14
+ ,52
+ ,31
+ ,34
+ ,31
+ ,16
+ ,12
+ ,15
+ ,13
+ ,54
+ ,33
+ ,35
+ ,37
+ ,17
+ ,13
+ ,10
+ ,11
+ ,80
+ ,49)
+ ,dim=c(8
+ ,66)
+ ,dimnames=list(c('Connected'
+ ,'Separate'
+ ,'Learning'
+ ,'Software'
+ ,'Happiness'
+ ,'Depression'
+ ,'Belonging'
+ ,'Belonging_Final')
+ ,1:66))
> y <- array(NA,dim=c(8,66),dimnames=list(c('Connected','Separate','Learning','Software','Happiness','Depression','Belonging','Belonging_Final'),1:66))
> 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 = '5'
> 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
Happiness Connected Separate Learning Software Depression Belonging
1 14 41 38 13 12 12 53
2 18 39 32 16 11 11 86
3 11 30 35 19 15 14 66
4 12 31 33 15 6 12 67
5 16 34 37 14 13 21 76
6 18 35 29 13 10 12 78
7 14 39 31 19 12 22 53
8 14 34 36 15 14 11 80
9 15 36 35 14 12 10 74
10 15 37 38 15 6 13 76
11 17 38 31 16 10 10 79
12 19 36 34 16 12 8 54
13 10 38 35 16 12 15 67
14 16 39 38 16 11 14 54
15 18 33 37 17 15 10 87
16 14 32 33 15 12 14 58
17 14 36 32 15 10 14 75
18 17 38 38 20 12 11 88
19 14 39 38 18 11 10 64
20 16 32 32 16 12 13 57
21 18 32 33 16 11 7 66
22 11 31 31 16 12 14 68
23 14 39 38 19 13 12 54
24 12 37 39 16 11 14 56
25 17 39 32 17 9 11 86
26 9 41 32 17 13 9 80
27 16 36 35 16 10 11 76
28 14 33 37 15 14 15 69
29 15 33 33 16 12 14 78
30 11 34 33 14 10 13 67
31 16 31 28 15 12 9 80
32 13 27 32 12 8 15 54
33 17 37 31 14 10 10 71
34 15 34 37 16 12 11 84
35 14 34 30 14 12 13 74
36 16 32 33 7 7 8 71
37 9 29 31 10 6 20 63
38 15 36 33 14 12 12 71
39 17 29 31 16 10 10 76
40 13 35 33 16 10 10 69
41 15 37 32 16 10 9 74
42 16 34 33 14 12 14 75
43 16 38 32 20 15 8 54
44 12 35 33 14 10 14 52
45 12 38 28 14 10 11 69
46 11 37 35 11 12 13 68
47 15 38 39 14 13 9 65
48 15 33 34 15 11 11 75
49 17 36 38 16 11 15 74
50 13 38 32 14 12 11 75
51 16 32 38 16 14 10 72
52 14 32 30 14 10 14 67
53 11 32 33 12 12 18 63
54 12 34 38 16 13 14 62
55 12 32 32 9 5 11 63
56 15 37 32 14 6 12 76
57 16 39 34 16 12 13 74
58 15 29 34 16 12 9 67
59 12 37 36 15 11 10 73
60 12 35 34 16 10 15 70
61 8 30 28 12 7 20 53
62 13 38 34 16 12 12 77
63 11 34 35 16 14 12 77
64 14 31 35 14 11 14 52
65 15 34 31 16 12 13 54
66 10 35 37 17 13 11 80
Belonging_Final
1 32
2 51
3 42
4 41
5 46
6 47
7 37
8 49
9 45
10 47
11 49
12 33
13 42
14 33
15 53
16 36
17 45
18 54
19 41
20 36
21 41
22 44
23 33
24 37
25 52
26 47
27 43
28 44
29 45
30 44
31 49
32 33
33 43
34 54
35 42
36 44
37 37
38 43
39 46
40 42
41 45
42 44
43 33
44 31
45 42
46 40
47 43
48 46
49 42
50 45
51 44
52 40
53 37
54 46
55 36
56 47
57 45
58 42
59 43
60 43
61 32
62 45
63 45
64 31
65 33
66 49
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) Connected Separate Learning
12.375113 -0.002763 0.018856 0.182173
Software Depression Belonging Belonging_Final
-0.024719 -0.283784 0.079758 -0.077406
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-6.8293 -1.5180 0.4176 1.5199 4.2506
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 12.375113 5.125311 2.415 0.01893 *
Connected -0.002763 0.099714 -0.028 0.97799
Separate 0.018856 0.113144 0.167 0.86822
Learning 0.182173 0.165518 1.101 0.27561
Software -0.024719 0.162056 -0.153 0.87930
Depression -0.283784 0.101878 -2.786 0.00721 **
Belonging 0.079758 0.101817 0.783 0.43661
Belonging_Final -0.077406 0.173014 -0.447 0.65626
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.326 on 58 degrees of freedom
Multiple R-squared: 0.2179, Adjusted R-squared: 0.1235
F-statistic: 2.308 on 7 and 58 DF, p-value: 0.03803
> 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.04185638 0.08371276 0.95814362
[2,] 0.77651624 0.44696751 0.22348376
[3,] 0.93325613 0.13348773 0.06674387
[4,] 0.90995919 0.18008162 0.09004081
[5,] 0.93142147 0.13715706 0.06857853
[6,] 0.89021343 0.21957315 0.10978657
[7,] 0.88123540 0.23752920 0.11876460
[8,] 0.83097906 0.33804187 0.16902094
[9,] 0.76654471 0.46691058 0.23345529
[10,] 0.75993253 0.48013494 0.24006747
[11,] 0.75686593 0.48626814 0.24313407
[12,] 0.75001659 0.49996681 0.24998341
[13,] 0.71444142 0.57111716 0.28555858
[14,] 0.63808997 0.72382006 0.36191003
[15,] 0.59957616 0.80084768 0.40042384
[16,] 0.98043771 0.03912459 0.01956229
[17,] 0.96962468 0.06075065 0.03037532
[18,] 0.95665244 0.08669513 0.04334756
[19,] 0.93817708 0.12364584 0.06182292
[20,] 0.93939058 0.12121883 0.06060942
[21,] 0.91206019 0.17587961 0.08793981
[22,] 0.87918757 0.24162487 0.12081243
[23,] 0.87745762 0.24508476 0.12254238
[24,] 0.83350928 0.33298144 0.16649072
[25,] 0.79111414 0.41777172 0.20888586
[26,] 0.78222166 0.43555668 0.21777834
[27,] 0.77849756 0.44300487 0.22150244
[28,] 0.74433774 0.51132452 0.25566226
[29,] 0.73795753 0.52408493 0.26204247
[30,] 0.70802917 0.58394165 0.29197083
[31,] 0.63393200 0.73213600 0.36606800
[32,] 0.71356773 0.57286454 0.28643227
[33,] 0.63969278 0.72061443 0.36030722
[34,] 0.61220890 0.77558219 0.38779110
[35,] 0.56203774 0.87592453 0.43796226
[36,] 0.51060702 0.97878595 0.48939298
[37,] 0.41621441 0.83242883 0.58378559
[38,] 0.37426709 0.74853418 0.62573291
[39,] 0.53205319 0.93589362 0.46794681
[40,] 0.46925234 0.93850468 0.53074766
[41,] 0.56983997 0.86032005 0.43016003
[42,] 0.48042014 0.96084029 0.51957986
[43,] 0.53495789 0.93008422 0.46504211
[44,] 0.47858851 0.95717701 0.52141149
[45,] 0.32505151 0.65010302 0.67494849
> postscript(file="/var/fisher/rcomp/tmp/1lo8y1355582229.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/fisher/rcomp/tmp/2mlru1355582229.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/fisher/rcomp/tmp/3uzvz1355582229.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/fisher/rcomp/tmp/43nov1355582229.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/fisher/rcomp/tmp/5x9un1355582229.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 = 66
Frequency = 1
1 2 3 4 5 6
0.605239741 2.696524946 -3.082701383 -2.260731004 4.250599239 3.876065344
7 8 9 10 11 12
2.863531941 -0.812651650 0.229608315 0.691964972 1.807609010 3.982840384
13 14 15 16 17 18
-3.384204490 2.593689840 2.293634517 0.788704290 0.109943608 0.949351047
19 20 21 22 23 24
-1.084125721 2.421361235 2.344291117 -2.536853945 -0.470960281 -1.280586598
25 26 27 28 29 30
1.542319979 -6.829327114 0.785281645 0.791172229 0.710787838 -2.455392820
31 32 33 34 35 36
0.712902826 0.611987406 2.342821532 0.004878059 -0.062502839 2.002187349
37 38 39 40 41 42
-2.037999737 0.919350592 1.789795532 -1.982653982 -0.408627336 2.239765661
43 44 45 46 47 48
0.371542236 -0.978750297 -2.231952710 -2.278237937 0.463654497 0.314713975
49 50 51 52 53 54
2.970676941 -1.504270474 0.929187113 0.569810615 -0.851024365 -1.002480468
55 56 57 58 59 60
-1.522570617 0.703491487 1.743759382 -0.092921298 -3.068429602 -1.584943578
61 62 63 64 65 66
-2.907745262 -1.782061205 -3.762533635 0.997202490 1.452801014 -5.217809596
> postscript(file="/var/fisher/rcomp/tmp/6p98c1355582229.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 = 66
Frequency = 1
lag(myerror, k = 1) myerror
0 0.605239741 NA
1 2.696524946 0.605239741
2 -3.082701383 2.696524946
3 -2.260731004 -3.082701383
4 4.250599239 -2.260731004
5 3.876065344 4.250599239
6 2.863531941 3.876065344
7 -0.812651650 2.863531941
8 0.229608315 -0.812651650
9 0.691964972 0.229608315
10 1.807609010 0.691964972
11 3.982840384 1.807609010
12 -3.384204490 3.982840384
13 2.593689840 -3.384204490
14 2.293634517 2.593689840
15 0.788704290 2.293634517
16 0.109943608 0.788704290
17 0.949351047 0.109943608
18 -1.084125721 0.949351047
19 2.421361235 -1.084125721
20 2.344291117 2.421361235
21 -2.536853945 2.344291117
22 -0.470960281 -2.536853945
23 -1.280586598 -0.470960281
24 1.542319979 -1.280586598
25 -6.829327114 1.542319979
26 0.785281645 -6.829327114
27 0.791172229 0.785281645
28 0.710787838 0.791172229
29 -2.455392820 0.710787838
30 0.712902826 -2.455392820
31 0.611987406 0.712902826
32 2.342821532 0.611987406
33 0.004878059 2.342821532
34 -0.062502839 0.004878059
35 2.002187349 -0.062502839
36 -2.037999737 2.002187349
37 0.919350592 -2.037999737
38 1.789795532 0.919350592
39 -1.982653982 1.789795532
40 -0.408627336 -1.982653982
41 2.239765661 -0.408627336
42 0.371542236 2.239765661
43 -0.978750297 0.371542236
44 -2.231952710 -0.978750297
45 -2.278237937 -2.231952710
46 0.463654497 -2.278237937
47 0.314713975 0.463654497
48 2.970676941 0.314713975
49 -1.504270474 2.970676941
50 0.929187113 -1.504270474
51 0.569810615 0.929187113
52 -0.851024365 0.569810615
53 -1.002480468 -0.851024365
54 -1.522570617 -1.002480468
55 0.703491487 -1.522570617
56 1.743759382 0.703491487
57 -0.092921298 1.743759382
58 -3.068429602 -0.092921298
59 -1.584943578 -3.068429602
60 -2.907745262 -1.584943578
61 -1.782061205 -2.907745262
62 -3.762533635 -1.782061205
63 0.997202490 -3.762533635
64 1.452801014 0.997202490
65 -5.217809596 1.452801014
66 NA -5.217809596
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] 2.696524946 0.605239741
[2,] -3.082701383 2.696524946
[3,] -2.260731004 -3.082701383
[4,] 4.250599239 -2.260731004
[5,] 3.876065344 4.250599239
[6,] 2.863531941 3.876065344
[7,] -0.812651650 2.863531941
[8,] 0.229608315 -0.812651650
[9,] 0.691964972 0.229608315
[10,] 1.807609010 0.691964972
[11,] 3.982840384 1.807609010
[12,] -3.384204490 3.982840384
[13,] 2.593689840 -3.384204490
[14,] 2.293634517 2.593689840
[15,] 0.788704290 2.293634517
[16,] 0.109943608 0.788704290
[17,] 0.949351047 0.109943608
[18,] -1.084125721 0.949351047
[19,] 2.421361235 -1.084125721
[20,] 2.344291117 2.421361235
[21,] -2.536853945 2.344291117
[22,] -0.470960281 -2.536853945
[23,] -1.280586598 -0.470960281
[24,] 1.542319979 -1.280586598
[25,] -6.829327114 1.542319979
[26,] 0.785281645 -6.829327114
[27,] 0.791172229 0.785281645
[28,] 0.710787838 0.791172229
[29,] -2.455392820 0.710787838
[30,] 0.712902826 -2.455392820
[31,] 0.611987406 0.712902826
[32,] 2.342821532 0.611987406
[33,] 0.004878059 2.342821532
[34,] -0.062502839 0.004878059
[35,] 2.002187349 -0.062502839
[36,] -2.037999737 2.002187349
[37,] 0.919350592 -2.037999737
[38,] 1.789795532 0.919350592
[39,] -1.982653982 1.789795532
[40,] -0.408627336 -1.982653982
[41,] 2.239765661 -0.408627336
[42,] 0.371542236 2.239765661
[43,] -0.978750297 0.371542236
[44,] -2.231952710 -0.978750297
[45,] -2.278237937 -2.231952710
[46,] 0.463654497 -2.278237937
[47,] 0.314713975 0.463654497
[48,] 2.970676941 0.314713975
[49,] -1.504270474 2.970676941
[50,] 0.929187113 -1.504270474
[51,] 0.569810615 0.929187113
[52,] -0.851024365 0.569810615
[53,] -1.002480468 -0.851024365
[54,] -1.522570617 -1.002480468
[55,] 0.703491487 -1.522570617
[56,] 1.743759382 0.703491487
[57,] -0.092921298 1.743759382
[58,] -3.068429602 -0.092921298
[59,] -1.584943578 -3.068429602
[60,] -2.907745262 -1.584943578
[61,] -1.782061205 -2.907745262
[62,] -3.762533635 -1.782061205
[63,] 0.997202490 -3.762533635
[64,] 1.452801014 0.997202490
[65,] -5.217809596 1.452801014
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 2.696524946 0.605239741
2 -3.082701383 2.696524946
3 -2.260731004 -3.082701383
4 4.250599239 -2.260731004
5 3.876065344 4.250599239
6 2.863531941 3.876065344
7 -0.812651650 2.863531941
8 0.229608315 -0.812651650
9 0.691964972 0.229608315
10 1.807609010 0.691964972
11 3.982840384 1.807609010
12 -3.384204490 3.982840384
13 2.593689840 -3.384204490
14 2.293634517 2.593689840
15 0.788704290 2.293634517
16 0.109943608 0.788704290
17 0.949351047 0.109943608
18 -1.084125721 0.949351047
19 2.421361235 -1.084125721
20 2.344291117 2.421361235
21 -2.536853945 2.344291117
22 -0.470960281 -2.536853945
23 -1.280586598 -0.470960281
24 1.542319979 -1.280586598
25 -6.829327114 1.542319979
26 0.785281645 -6.829327114
27 0.791172229 0.785281645
28 0.710787838 0.791172229
29 -2.455392820 0.710787838
30 0.712902826 -2.455392820
31 0.611987406 0.712902826
32 2.342821532 0.611987406
33 0.004878059 2.342821532
34 -0.062502839 0.004878059
35 2.002187349 -0.062502839
36 -2.037999737 2.002187349
37 0.919350592 -2.037999737
38 1.789795532 0.919350592
39 -1.982653982 1.789795532
40 -0.408627336 -1.982653982
41 2.239765661 -0.408627336
42 0.371542236 2.239765661
43 -0.978750297 0.371542236
44 -2.231952710 -0.978750297
45 -2.278237937 -2.231952710
46 0.463654497 -2.278237937
47 0.314713975 0.463654497
48 2.970676941 0.314713975
49 -1.504270474 2.970676941
50 0.929187113 -1.504270474
51 0.569810615 0.929187113
52 -0.851024365 0.569810615
53 -1.002480468 -0.851024365
54 -1.522570617 -1.002480468
55 0.703491487 -1.522570617
56 1.743759382 0.703491487
57 -0.092921298 1.743759382
58 -3.068429602 -0.092921298
59 -1.584943578 -3.068429602
60 -2.907745262 -1.584943578
61 -1.782061205 -2.907745262
62 -3.762533635 -1.782061205
63 0.997202490 -3.762533635
64 1.452801014 0.997202490
65 -5.217809596 1.452801014
> 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/fisher/rcomp/tmp/7xst71355582229.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/fisher/rcomp/tmp/8egsm1355582229.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/fisher/rcomp/tmp/9a9b11355582229.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/fisher/rcomp/tmp/10xn8k1355582229.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
> load(file="/var/fisher/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/fisher/rcomp/tmp/11knzw1355582229.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/fisher/rcomp/tmp/12oypv1355582229.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/fisher/rcomp/tmp/13q2xn1355582229.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/fisher/rcomp/tmp/14516l1355582229.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/fisher/rcomp/tmp/158zlt1355582229.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/fisher/rcomp/tmp/16jhkr1355582229.tab")
+ }
>
> try(system("convert tmp/1lo8y1355582229.ps tmp/1lo8y1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/2mlru1355582229.ps tmp/2mlru1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/3uzvz1355582229.ps tmp/3uzvz1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/43nov1355582229.ps tmp/43nov1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/5x9un1355582229.ps tmp/5x9un1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/6p98c1355582229.ps tmp/6p98c1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/7xst71355582229.ps tmp/7xst71355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/8egsm1355582229.ps tmp/8egsm1355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/9a9b11355582229.ps tmp/9a9b11355582229.png",intern=TRUE))
character(0)
> try(system("convert tmp/10xn8k1355582229.ps tmp/10xn8k1355582229.png",intern=TRUE))
character(0)
>
>
> proc.time()
user system elapsed
6.198 1.666 7.896