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(3258.1,0,3140.1,0,3627.4,0,3279.4,0,3204.0,0,3515.6,0,3146.6,0,2271.7,0,3627.9,0,3553.4,0,3018.3,0,3355.4,0,3242.0,0,3311.1,0,4125.2,0,3423.0,0,3120.3,0,3863.0,0,3240.8,0,2837.4,0,3945.0,0,3684.1,0,3659.6,0,3769.6,0,3592.7,0,3754.0,0,4507.8,0,3853.2,0,3817.2,0,3958.4,0,3428.9,1,3125.7,1,3977.0,1,3983.3,1,4299.6,1,4306.9,1,4259.5,1,3986.0,1,4755.6,1,3925.6,1,4206.5,1,4323.4,1,3816.1,1,3410.7,1,4227.4,1,4296.9,1,4351.7,1,3800.0,1,4277.0,1,4100.2,1,4672.5,1,4189.9,1,4231.9,1,4654.9,1,4298.5,1,3635.9,1,4505.1,1,4910.1,1,4908.7,1,4101.4,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 3258.1 0
2 3140.1 0
3 3627.4 0
4 3279.4 0
5 3204.0 0
6 3515.6 0
7 3146.6 0
8 2271.7 0
9 3627.9 0
10 3553.4 0
11 3018.3 0
12 3355.4 0
13 3242.0 0
14 3311.1 0
15 4125.2 0
16 3423.0 0
17 3120.3 0
18 3863.0 0
19 3240.8 0
20 2837.4 0
21 3945.0 0
22 3684.1 0
23 3659.6 0
24 3769.6 0
25 3592.7 0
26 3754.0 0
27 4507.8 0
28 3853.2 0
29 3817.2 0
30 3958.4 0
31 3428.9 1
32 3125.7 1
33 3977.0 1
34 3983.3 1
35 4299.6 1
36 4306.9 1
37 4259.5 1
38 3986.0 1
39 4755.6 1
40 3925.6 1
41 4206.5 1
42 4323.4 1
43 3816.1 1
44 3410.7 1
45 4227.4 1
46 4296.9 1
47 4351.7 1
48 3800.0 1
49 4277.0 1
50 4100.2 1
51 4672.5 1
52 4189.9 1
53 4231.9 1
54 4654.9 1
55 4298.5 1
56 3635.9 1
57 4505.1 1
58 4910.1 1
59 4908.7 1
60 4101.4 1
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) x
3490.1 675.5
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-1218.38 -241.99 62.58 211.50 1017.72
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3490.08 77.71 44.913 < 2e-16 ***
x 675.49 109.89 6.147 7.8e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 425.6 on 58 degrees of freedom
Multiple R-squared: 0.3945, Adjusted R-squared: 0.384
F-statistic: 37.78 on 1 and 58 DF, p-value: 7.8e-08
> postscript(file="/var/www/html/rcomp/tmp/11los1227448234.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/28i2k1227448234.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/3d4tw1227448234.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/4p0431227448234.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/556571227448234.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
-231.97667 -349.97667 137.32333 -210.67667 -286.07667 25.52333
7 8 9 10 11 12
-343.47667 -1218.37667 137.82333 63.32333 -471.77667 -134.67667
13 14 15 16 17 18
-248.07667 -178.97667 635.12333 -67.07667 -369.77667 372.92333
19 20 21 22 23 24
-249.27667 -652.67667 454.92333 194.02333 169.52333 279.52333
25 26 27 28 29 30
102.62333 263.92333 1017.72333 363.12333 327.12333 468.32333
31 32 33 34 35 36
-736.66333 -1039.86333 -188.56333 -182.26333 134.03667 141.33667
37 38 39 40 41 42
93.93667 -179.56333 590.03667 -239.96333 40.93667 157.83667
43 44 45 46 47 48
-349.46333 -754.86333 61.83667 131.33667 186.13667 -365.56333
49 50 51 52 53 54
111.43667 -65.36333 506.93667 24.33667 66.33667 489.33667
55 56 57 58 59 60
132.93667 -529.66333 339.53667 744.53667 743.13667 -64.16333
> postscript(file="/var/www/html/rcomp/tmp/6fmwo1227448234.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 -231.97667 NA
1 -349.97667 -231.97667
2 137.32333 -349.97667
3 -210.67667 137.32333
4 -286.07667 -210.67667
5 25.52333 -286.07667
6 -343.47667 25.52333
7 -1218.37667 -343.47667
8 137.82333 -1218.37667
9 63.32333 137.82333
10 -471.77667 63.32333
11 -134.67667 -471.77667
12 -248.07667 -134.67667
13 -178.97667 -248.07667
14 635.12333 -178.97667
15 -67.07667 635.12333
16 -369.77667 -67.07667
17 372.92333 -369.77667
18 -249.27667 372.92333
19 -652.67667 -249.27667
20 454.92333 -652.67667
21 194.02333 454.92333
22 169.52333 194.02333
23 279.52333 169.52333
24 102.62333 279.52333
25 263.92333 102.62333
26 1017.72333 263.92333
27 363.12333 1017.72333
28 327.12333 363.12333
29 468.32333 327.12333
30 -736.66333 468.32333
31 -1039.86333 -736.66333
32 -188.56333 -1039.86333
33 -182.26333 -188.56333
34 134.03667 -182.26333
35 141.33667 134.03667
36 93.93667 141.33667
37 -179.56333 93.93667
38 590.03667 -179.56333
39 -239.96333 590.03667
40 40.93667 -239.96333
41 157.83667 40.93667
42 -349.46333 157.83667
43 -754.86333 -349.46333
44 61.83667 -754.86333
45 131.33667 61.83667
46 186.13667 131.33667
47 -365.56333 186.13667
48 111.43667 -365.56333
49 -65.36333 111.43667
50 506.93667 -65.36333
51 24.33667 506.93667
52 66.33667 24.33667
53 489.33667 66.33667
54 132.93667 489.33667
55 -529.66333 132.93667
56 339.53667 -529.66333
57 744.53667 339.53667
58 743.13667 744.53667
59 -64.16333 743.13667
60 NA -64.16333
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] -349.97667 -231.97667
[2,] 137.32333 -349.97667
[3,] -210.67667 137.32333
[4,] -286.07667 -210.67667
[5,] 25.52333 -286.07667
[6,] -343.47667 25.52333
[7,] -1218.37667 -343.47667
[8,] 137.82333 -1218.37667
[9,] 63.32333 137.82333
[10,] -471.77667 63.32333
[11,] -134.67667 -471.77667
[12,] -248.07667 -134.67667
[13,] -178.97667 -248.07667
[14,] 635.12333 -178.97667
[15,] -67.07667 635.12333
[16,] -369.77667 -67.07667
[17,] 372.92333 -369.77667
[18,] -249.27667 372.92333
[19,] -652.67667 -249.27667
[20,] 454.92333 -652.67667
[21,] 194.02333 454.92333
[22,] 169.52333 194.02333
[23,] 279.52333 169.52333
[24,] 102.62333 279.52333
[25,] 263.92333 102.62333
[26,] 1017.72333 263.92333
[27,] 363.12333 1017.72333
[28,] 327.12333 363.12333
[29,] 468.32333 327.12333
[30,] -736.66333 468.32333
[31,] -1039.86333 -736.66333
[32,] -188.56333 -1039.86333
[33,] -182.26333 -188.56333
[34,] 134.03667 -182.26333
[35,] 141.33667 134.03667
[36,] 93.93667 141.33667
[37,] -179.56333 93.93667
[38,] 590.03667 -179.56333
[39,] -239.96333 590.03667
[40,] 40.93667 -239.96333
[41,] 157.83667 40.93667
[42,] -349.46333 157.83667
[43,] -754.86333 -349.46333
[44,] 61.83667 -754.86333
[45,] 131.33667 61.83667
[46,] 186.13667 131.33667
[47,] -365.56333 186.13667
[48,] 111.43667 -365.56333
[49,] -65.36333 111.43667
[50,] 506.93667 -65.36333
[51,] 24.33667 506.93667
[52,] 66.33667 24.33667
[53,] 489.33667 66.33667
[54,] 132.93667 489.33667
[55,] -529.66333 132.93667
[56,] 339.53667 -529.66333
[57,] 744.53667 339.53667
[58,] 743.13667 744.53667
[59,] -64.16333 743.13667
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 -349.97667 -231.97667
2 137.32333 -349.97667
3 -210.67667 137.32333
4 -286.07667 -210.67667
5 25.52333 -286.07667
6 -343.47667 25.52333
7 -1218.37667 -343.47667
8 137.82333 -1218.37667
9 63.32333 137.82333
10 -471.77667 63.32333
11 -134.67667 -471.77667
12 -248.07667 -134.67667
13 -178.97667 -248.07667
14 635.12333 -178.97667
15 -67.07667 635.12333
16 -369.77667 -67.07667
17 372.92333 -369.77667
18 -249.27667 372.92333
19 -652.67667 -249.27667
20 454.92333 -652.67667
21 194.02333 454.92333
22 169.52333 194.02333
23 279.52333 169.52333
24 102.62333 279.52333
25 263.92333 102.62333
26 1017.72333 263.92333
27 363.12333 1017.72333
28 327.12333 363.12333
29 468.32333 327.12333
30 -736.66333 468.32333
31 -1039.86333 -736.66333
32 -188.56333 -1039.86333
33 -182.26333 -188.56333
34 134.03667 -182.26333
35 141.33667 134.03667
36 93.93667 141.33667
37 -179.56333 93.93667
38 590.03667 -179.56333
39 -239.96333 590.03667
40 40.93667 -239.96333
41 157.83667 40.93667
42 -349.46333 157.83667
43 -754.86333 -349.46333
44 61.83667 -754.86333
45 131.33667 61.83667
46 186.13667 131.33667
47 -365.56333 186.13667
48 111.43667 -365.56333
49 -65.36333 111.43667
50 506.93667 -65.36333
51 24.33667 506.93667
52 66.33667 24.33667
53 489.33667 66.33667
54 132.93667 489.33667
55 -529.66333 132.93667
56 339.53667 -529.66333
57 744.53667 339.53667
58 743.13667 744.53667
59 -64.16333 743.13667
> 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/7ahv61227448234.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/8n87i1227448234.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/9r9ko1227448234.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')
hat values (leverages) are all = 0.03333333
and there are no factor predictors; no plot no. 5
> 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/10nouw1227448234.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/11eh8a1227448234.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/12fnni1227448234.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/13az4o1227448234.tab")
>
> system("convert tmp/11los1227448234.ps tmp/11los1227448234.png")
> system("convert tmp/28i2k1227448234.ps tmp/28i2k1227448234.png")
> system("convert tmp/3d4tw1227448234.ps tmp/3d4tw1227448234.png")
> system("convert tmp/4p0431227448234.ps tmp/4p0431227448234.png")
> system("convert tmp/556571227448234.ps tmp/556571227448234.png")
> system("convert tmp/6fmwo1227448234.ps tmp/6fmwo1227448234.png")
> system("convert tmp/7ahv61227448234.ps tmp/7ahv61227448234.png")
> system("convert tmp/8n87i1227448234.ps tmp/8n87i1227448234.png")
> system("convert tmp/9r9ko1227448234.ps tmp/9r9ko1227448234.png")
>
>
> proc.time()
user system elapsed
1.927 1.440 2.265