R version 2.8.0 (2008-10-20)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
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(58972,1,59249,1,63955,1,53785,1,52760,1,44795,1,37348,0,32370,0,32717,0,40974,0,33591,0,21124,0,58608,0,46865,0,51378,0,46235,0,47206,0,45382,0,41227,0,33795,0,31295,0,42625,0,33625,0,21538,0,56421,0,53152,0,53536,0,52408,0,41454,0,38271,0,35306,0,26414,0,31917,0,38030,0,27534,0,18387,0,50556,0,43901,0,48572,1,43899,1,37532,1,40357,1,35489,1,29027,1,34485,1,42598,1,30306,1,26451,1,47460,1,50104,1,61465,1,53726,1,39477,1,43895,1,31481,1,29896,1,33842,1,39120,1,33702,1,25094,1),dim=c(2,60),dimnames=list(c('y','x'),1:60))
> y <- array(NA,dim=c(2,60),dimnames=list(c('y','x'),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 = '1'
> #'GNU S' R Code compiled by R2WASP v. 1.0.44 ()
> #Author: Prof. Dr. P. Wessa
> #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/
> #Source of accompanying publication: Office for Research, Development, and Education
> #Technical description: Write here your technical program description (don't use hard returns!)
> library(lattice)
> 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 x
1 58972 1
2 59249 1
3 63955 1
4 53785 1
5 52760 1
6 44795 1
7 37348 0
8 32370 0
9 32717 0
10 40974 0
11 33591 0
12 21124 0
13 58608 0
14 46865 0
15 51378 0
16 46235 0
17 47206 0
18 45382 0
19 41227 0
20 33795 0
21 31295 0
22 42625 0
23 33625 0
24 21538 0
25 56421 0
26 53152 0
27 53536 0
28 52408 0
29 41454 0
30 38271 0
31 35306 0
32 26414 0
33 31917 0
34 38030 0
35 27534 0
36 18387 0
37 50556 0
38 43901 0
39 48572 1
40 43899 1
41 37532 1
42 40357 1
43 35489 1
44 29027 1
45 34485 1
46 42598 1
47 30306 1
48 26451 1
49 47460 1
50 50104 1
51 61465 1
52 53726 1
53 39477 1
54 43895 1
55 31481 1
56 29896 1
57 33842 1
58 39120 1
59 33702 1
60 25094 1
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) x
39537 3016
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-21150.2 -7732.2 -610.8 7580.2 21401.6
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 39537 1916 20.638 <2e-16 ***
x 3016 2804 1.076 0.287
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 10840 on 58 degrees of freedom
Multiple R-squared: 0.01955, Adjusted R-squared: 0.002649
F-statistic: 1.157 on 1 and 58 DF, p-value: 0.2866
> postscript(file="/var/www/html/rcomp/tmp/1lcf71229083453.ps",horizontal=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/www/html/rcomp/tmp/23ii91229083453.ps",horizontal=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/www/html/rcomp/tmp/3bg9y1229083453.ps",horizontal=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/www/html/rcomp/tmp/49h4w1229083453.ps",horizontal=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/www/html/rcomp/tmp/51ysu1229083453.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> qqnorm(mysum$resid, main='Residual Normal Q-Q Plot')
> 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
16418.64286 16695.64286 21401.64286 11231.64286 10206.64286 2241.64286
7 8 9 10 11 12
-2189.18750 -7167.18750 -6820.18750 1436.81250 -5946.18750 -18413.18750
13 14 15 16 17 18
19070.81250 7327.81250 11840.81250 6697.81250 7668.81250 5844.81250
19 20 21 22 23 24
1689.81250 -5742.18750 -8242.18750 3087.81250 -5912.18750 -17999.18750
25 26 27 28 29 30
16883.81250 13614.81250 13998.81250 12870.81250 1916.81250 -1266.18750
31 32 33 34 35 36
-4231.18750 -13123.18750 -7620.18750 -1507.18750 -12003.18750 -21150.18750
37 38 39 40 41 42
11018.81250 4363.81250 6018.64286 1345.64286 -5021.35714 -2196.35714
43 44 45 46 47 48
-7064.35714 -13526.35714 -8068.35714 44.64286 -12247.35714 -16102.35714
49 50 51 52 53 54
4906.64286 7550.64286 18911.64286 11172.64286 -3076.35714 1341.64286
55 56 57 58 59 60
-11072.35714 -12657.35714 -8711.35714 -3433.35714 -8851.35714 -17459.35714
> postscript(file="/var/www/html/rcomp/tmp/67nhq1229083453.ps",horizontal=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 16418.64286 NA
1 16695.64286 16418.64286
2 21401.64286 16695.64286
3 11231.64286 21401.64286
4 10206.64286 11231.64286
5 2241.64286 10206.64286
6 -2189.18750 2241.64286
7 -7167.18750 -2189.18750
8 -6820.18750 -7167.18750
9 1436.81250 -6820.18750
10 -5946.18750 1436.81250
11 -18413.18750 -5946.18750
12 19070.81250 -18413.18750
13 7327.81250 19070.81250
14 11840.81250 7327.81250
15 6697.81250 11840.81250
16 7668.81250 6697.81250
17 5844.81250 7668.81250
18 1689.81250 5844.81250
19 -5742.18750 1689.81250
20 -8242.18750 -5742.18750
21 3087.81250 -8242.18750
22 -5912.18750 3087.81250
23 -17999.18750 -5912.18750
24 16883.81250 -17999.18750
25 13614.81250 16883.81250
26 13998.81250 13614.81250
27 12870.81250 13998.81250
28 1916.81250 12870.81250
29 -1266.18750 1916.81250
30 -4231.18750 -1266.18750
31 -13123.18750 -4231.18750
32 -7620.18750 -13123.18750
33 -1507.18750 -7620.18750
34 -12003.18750 -1507.18750
35 -21150.18750 -12003.18750
36 11018.81250 -21150.18750
37 4363.81250 11018.81250
38 6018.64286 4363.81250
39 1345.64286 6018.64286
40 -5021.35714 1345.64286
41 -2196.35714 -5021.35714
42 -7064.35714 -2196.35714
43 -13526.35714 -7064.35714
44 -8068.35714 -13526.35714
45 44.64286 -8068.35714
46 -12247.35714 44.64286
47 -16102.35714 -12247.35714
48 4906.64286 -16102.35714
49 7550.64286 4906.64286
50 18911.64286 7550.64286
51 11172.64286 18911.64286
52 -3076.35714 11172.64286
53 1341.64286 -3076.35714
54 -11072.35714 1341.64286
55 -12657.35714 -11072.35714
56 -8711.35714 -12657.35714
57 -3433.35714 -8711.35714
58 -8851.35714 -3433.35714
59 -17459.35714 -8851.35714
60 NA -17459.35714
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] 16695.64286 16418.64286
[2,] 21401.64286 16695.64286
[3,] 11231.64286 21401.64286
[4,] 10206.64286 11231.64286
[5,] 2241.64286 10206.64286
[6,] -2189.18750 2241.64286
[7,] -7167.18750 -2189.18750
[8,] -6820.18750 -7167.18750
[9,] 1436.81250 -6820.18750
[10,] -5946.18750 1436.81250
[11,] -18413.18750 -5946.18750
[12,] 19070.81250 -18413.18750
[13,] 7327.81250 19070.81250
[14,] 11840.81250 7327.81250
[15,] 6697.81250 11840.81250
[16,] 7668.81250 6697.81250
[17,] 5844.81250 7668.81250
[18,] 1689.81250 5844.81250
[19,] -5742.18750 1689.81250
[20,] -8242.18750 -5742.18750
[21,] 3087.81250 -8242.18750
[22,] -5912.18750 3087.81250
[23,] -17999.18750 -5912.18750
[24,] 16883.81250 -17999.18750
[25,] 13614.81250 16883.81250
[26,] 13998.81250 13614.81250
[27,] 12870.81250 13998.81250
[28,] 1916.81250 12870.81250
[29,] -1266.18750 1916.81250
[30,] -4231.18750 -1266.18750
[31,] -13123.18750 -4231.18750
[32,] -7620.18750 -13123.18750
[33,] -1507.18750 -7620.18750
[34,] -12003.18750 -1507.18750
[35,] -21150.18750 -12003.18750
[36,] 11018.81250 -21150.18750
[37,] 4363.81250 11018.81250
[38,] 6018.64286 4363.81250
[39,] 1345.64286 6018.64286
[40,] -5021.35714 1345.64286
[41,] -2196.35714 -5021.35714
[42,] -7064.35714 -2196.35714
[43,] -13526.35714 -7064.35714
[44,] -8068.35714 -13526.35714
[45,] 44.64286 -8068.35714
[46,] -12247.35714 44.64286
[47,] -16102.35714 -12247.35714
[48,] 4906.64286 -16102.35714
[49,] 7550.64286 4906.64286
[50,] 18911.64286 7550.64286
[51,] 11172.64286 18911.64286
[52,] -3076.35714 11172.64286
[53,] 1341.64286 -3076.35714
[54,] -11072.35714 1341.64286
[55,] -12657.35714 -11072.35714
[56,] -8711.35714 -12657.35714
[57,] -3433.35714 -8711.35714
[58,] -8851.35714 -3433.35714
[59,] -17459.35714 -8851.35714
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 16695.64286 16418.64286
2 21401.64286 16695.64286
3 11231.64286 21401.64286
4 10206.64286 11231.64286
5 2241.64286 10206.64286
6 -2189.18750 2241.64286
7 -7167.18750 -2189.18750
8 -6820.18750 -7167.18750
9 1436.81250 -6820.18750
10 -5946.18750 1436.81250
11 -18413.18750 -5946.18750
12 19070.81250 -18413.18750
13 7327.81250 19070.81250
14 11840.81250 7327.81250
15 6697.81250 11840.81250
16 7668.81250 6697.81250
17 5844.81250 7668.81250
18 1689.81250 5844.81250
19 -5742.18750 1689.81250
20 -8242.18750 -5742.18750
21 3087.81250 -8242.18750
22 -5912.18750 3087.81250
23 -17999.18750 -5912.18750
24 16883.81250 -17999.18750
25 13614.81250 16883.81250
26 13998.81250 13614.81250
27 12870.81250 13998.81250
28 1916.81250 12870.81250
29 -1266.18750 1916.81250
30 -4231.18750 -1266.18750
31 -13123.18750 -4231.18750
32 -7620.18750 -13123.18750
33 -1507.18750 -7620.18750
34 -12003.18750 -1507.18750
35 -21150.18750 -12003.18750
36 11018.81250 -21150.18750
37 4363.81250 11018.81250
38 6018.64286 4363.81250
39 1345.64286 6018.64286
40 -5021.35714 1345.64286
41 -2196.35714 -5021.35714
42 -7064.35714 -2196.35714
43 -13526.35714 -7064.35714
44 -8068.35714 -13526.35714
45 44.64286 -8068.35714
46 -12247.35714 44.64286
47 -16102.35714 -12247.35714
48 4906.64286 -16102.35714
49 7550.64286 4906.64286
50 18911.64286 7550.64286
51 11172.64286 18911.64286
52 -3076.35714 11172.64286
53 1341.64286 -3076.35714
54 -11072.35714 1341.64286
55 -12657.35714 -11072.35714
56 -8711.35714 -12657.35714
57 -3433.35714 -8711.35714
58 -8851.35714 -3433.35714
59 -17459.35714 -8851.35714
> 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/www/html/rcomp/tmp/7n2oo1229083453.ps",horizontal=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/www/html/rcomp/tmp/8ndlp1229083453.ps",horizontal=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/www/html/rcomp/tmp/99kaw1229083453.ps",horizontal=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
>
> #Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
> load(file="/var/www/html/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/www/html/rcomp/tmp/10bvrs1229083453.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/www/html/rcomp/tmp/11jq4x1229083453.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/www/html/rcomp/tmp/121dxm1229083453.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/www/html/rcomp/tmp/13zzej1229083453.tab")
>
> system("convert tmp/1lcf71229083453.ps tmp/1lcf71229083453.png")
> system("convert tmp/23ii91229083453.ps tmp/23ii91229083453.png")
> system("convert tmp/3bg9y1229083453.ps tmp/3bg9y1229083453.png")
> system("convert tmp/49h4w1229083453.ps tmp/49h4w1229083453.png")
> system("convert tmp/51ysu1229083453.ps tmp/51ysu1229083453.png")
> system("convert tmp/67nhq1229083453.ps tmp/67nhq1229083453.png")
> system("convert tmp/7n2oo1229083453.ps tmp/7n2oo1229083453.png")
> system("convert tmp/8ndlp1229083453.ps tmp/8ndlp1229083453.png")
> system("convert tmp/99kaw1229083453.ps tmp/99kaw1229083453.png")
>
>
> proc.time()
user system elapsed
1.937 1.416 2.426