R version 2.6.0 (2007-10-03)
Copyright (C) 2007 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(99.9,0,98.2,0,104.5,0,100.8,0,101.5,0,103.9,0,99.6,0,98.4,0,112.7,0,118.4,0,108.1,0,105.4,0,114.6,0,106.9,0,115.9,1,109.8,1,101.8,1,114.2,2,110.8,2,108.4,2,127.5,2,128.6,2,116.6,2,127.4,2,105,2,108.3,2,125,2,111.6,2,106.5,2,130.3,2,115,2,116.1,2,134,2,126.5,2,125.8,2,136.4,2,114.9,2,110.9,2,125.5,2,116.8,2,116.8,2,125.5,2,104.2,2,115.1,2,132.8,2,123.3,2,124.8,2,122,2,117.4,2,117.9,2,137.4,2,114.6,2,124.7,2,129.6,2,109.4,2,120.9,2,134.9,2,136.3,2,133.2,2,127.2,2),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 99.9 0
2 98.2 0
3 104.5 0
4 100.8 0
5 101.5 0
6 103.9 0
7 99.6 0
8 98.4 0
9 112.7 0
10 118.4 0
11 108.1 0
12 105.4 0
13 114.6 0
14 106.9 0
15 115.9 1
16 109.8 1
17 101.8 1
18 114.2 2
19 110.8 2
20 108.4 2
21 127.5 2
22 128.6 2
23 116.6 2
24 127.4 2
25 105.0 2
26 108.3 2
27 125.0 2
28 111.6 2
29 106.5 2
30 130.3 2
31 115.0 2
32 116.1 2
33 134.0 2
34 126.5 2
35 125.8 2
36 136.4 2
37 114.9 2
38 110.9 2
39 125.5 2
40 116.8 2
41 116.8 2
42 125.5 2
43 104.2 2
44 115.1 2
45 132.8 2
46 123.3 2
47 124.8 2
48 122.0 2
49 117.4 2
50 117.9 2
51 137.4 2
52 114.6 2
53 124.7 2
54 129.6 2
55 109.4 2
56 120.9 2
57 134.9 2
58 136.3 2
59 133.2 2
60 127.2 2
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) x
104.805 8.115
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-16.8342 -6.0592 -0.2196 6.2158 16.3658
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 104.805 2.251 46.550 < 2e-16 ***
x 8.115 1.318 6.155 7.55e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 8.643 on 58 degrees of freedom
Multiple R-Squared: 0.3951, Adjusted R-squared: 0.3847
F-statistic: 37.89 on 1 and 58 DF, p-value: 7.547e-08
> postscript(file="/var/www/html/rcomp/tmp/1ral91195311791.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/2wq4n1195311791.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/3r9s81195311791.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/4qhbn1195311791.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/5jn8h1195311791.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
-4.9050407 -6.6050407 -0.3050407 -4.0050407 -3.3050407 -0.9050407
7 8 9 10 11 12
-5.2050407 -6.4050407 7.8949593 13.5949593 3.2949593 0.5949593
13 14 15 16 17 18
9.7949593 2.0949593 2.9803800 -3.1196200 -11.1196200 -6.8341993
19 20 21 22 23 24
-10.2341993 -12.6341993 6.4658007 7.5658007 -4.4341993 6.3658007
25 26 27 28 29 30
-16.0341993 -12.7341993 3.9658007 -9.4341993 -14.5341993 9.2658007
31 32 33 34 35 36
-6.0341993 -4.9341993 12.9658007 5.4658007 4.7658007 15.3658007
37 38 39 40 41 42
-6.1341993 -10.1341993 4.4658007 -4.2341993 -4.2341993 4.4658007
43 44 45 46 47 48
-16.8341993 -5.9341993 11.7658007 2.2658007 3.7658007 0.9658007
49 50 51 52 53 54
-3.6341993 -3.1341993 16.3658007 -6.4341993 3.6658007 8.5658007
55 56 57 58 59 60
-11.6341993 -0.1341993 13.8658007 15.2658007 12.1658007 6.1658007
> postscript(file="/var/www/html/rcomp/tmp/6fk9m1195311791.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 -4.9050407 NA
1 -6.6050407 -4.9050407
2 -0.3050407 -6.6050407
3 -4.0050407 -0.3050407
4 -3.3050407 -4.0050407
5 -0.9050407 -3.3050407
6 -5.2050407 -0.9050407
7 -6.4050407 -5.2050407
8 7.8949593 -6.4050407
9 13.5949593 7.8949593
10 3.2949593 13.5949593
11 0.5949593 3.2949593
12 9.7949593 0.5949593
13 2.0949593 9.7949593
14 2.9803800 2.0949593
15 -3.1196200 2.9803800
16 -11.1196200 -3.1196200
17 -6.8341993 -11.1196200
18 -10.2341993 -6.8341993
19 -12.6341993 -10.2341993
20 6.4658007 -12.6341993
21 7.5658007 6.4658007
22 -4.4341993 7.5658007
23 6.3658007 -4.4341993
24 -16.0341993 6.3658007
25 -12.7341993 -16.0341993
26 3.9658007 -12.7341993
27 -9.4341993 3.9658007
28 -14.5341993 -9.4341993
29 9.2658007 -14.5341993
30 -6.0341993 9.2658007
31 -4.9341993 -6.0341993
32 12.9658007 -4.9341993
33 5.4658007 12.9658007
34 4.7658007 5.4658007
35 15.3658007 4.7658007
36 -6.1341993 15.3658007
37 -10.1341993 -6.1341993
38 4.4658007 -10.1341993
39 -4.2341993 4.4658007
40 -4.2341993 -4.2341993
41 4.4658007 -4.2341993
42 -16.8341993 4.4658007
43 -5.9341993 -16.8341993
44 11.7658007 -5.9341993
45 2.2658007 11.7658007
46 3.7658007 2.2658007
47 0.9658007 3.7658007
48 -3.6341993 0.9658007
49 -3.1341993 -3.6341993
50 16.3658007 -3.1341993
51 -6.4341993 16.3658007
52 3.6658007 -6.4341993
53 8.5658007 3.6658007
54 -11.6341993 8.5658007
55 -0.1341993 -11.6341993
56 13.8658007 -0.1341993
57 15.2658007 13.8658007
58 12.1658007 15.2658007
59 6.1658007 12.1658007
60 NA 6.1658007
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] -6.6050407 -4.9050407
[2,] -0.3050407 -6.6050407
[3,] -4.0050407 -0.3050407
[4,] -3.3050407 -4.0050407
[5,] -0.9050407 -3.3050407
[6,] -5.2050407 -0.9050407
[7,] -6.4050407 -5.2050407
[8,] 7.8949593 -6.4050407
[9,] 13.5949593 7.8949593
[10,] 3.2949593 13.5949593
[11,] 0.5949593 3.2949593
[12,] 9.7949593 0.5949593
[13,] 2.0949593 9.7949593
[14,] 2.9803800 2.0949593
[15,] -3.1196200 2.9803800
[16,] -11.1196200 -3.1196200
[17,] -6.8341993 -11.1196200
[18,] -10.2341993 -6.8341993
[19,] -12.6341993 -10.2341993
[20,] 6.4658007 -12.6341993
[21,] 7.5658007 6.4658007
[22,] -4.4341993 7.5658007
[23,] 6.3658007 -4.4341993
[24,] -16.0341993 6.3658007
[25,] -12.7341993 -16.0341993
[26,] 3.9658007 -12.7341993
[27,] -9.4341993 3.9658007
[28,] -14.5341993 -9.4341993
[29,] 9.2658007 -14.5341993
[30,] -6.0341993 9.2658007
[31,] -4.9341993 -6.0341993
[32,] 12.9658007 -4.9341993
[33,] 5.4658007 12.9658007
[34,] 4.7658007 5.4658007
[35,] 15.3658007 4.7658007
[36,] -6.1341993 15.3658007
[37,] -10.1341993 -6.1341993
[38,] 4.4658007 -10.1341993
[39,] -4.2341993 4.4658007
[40,] -4.2341993 -4.2341993
[41,] 4.4658007 -4.2341993
[42,] -16.8341993 4.4658007
[43,] -5.9341993 -16.8341993
[44,] 11.7658007 -5.9341993
[45,] 2.2658007 11.7658007
[46,] 3.7658007 2.2658007
[47,] 0.9658007 3.7658007
[48,] -3.6341993 0.9658007
[49,] -3.1341993 -3.6341993
[50,] 16.3658007 -3.1341993
[51,] -6.4341993 16.3658007
[52,] 3.6658007 -6.4341993
[53,] 8.5658007 3.6658007
[54,] -11.6341993 8.5658007
[55,] -0.1341993 -11.6341993
[56,] 13.8658007 -0.1341993
[57,] 15.2658007 13.8658007
[58,] 12.1658007 15.2658007
[59,] 6.1658007 12.1658007
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 -6.6050407 -4.9050407
2 -0.3050407 -6.6050407
3 -4.0050407 -0.3050407
4 -3.3050407 -4.0050407
5 -0.9050407 -3.3050407
6 -5.2050407 -0.9050407
7 -6.4050407 -5.2050407
8 7.8949593 -6.4050407
9 13.5949593 7.8949593
10 3.2949593 13.5949593
11 0.5949593 3.2949593
12 9.7949593 0.5949593
13 2.0949593 9.7949593
14 2.9803800 2.0949593
15 -3.1196200 2.9803800
16 -11.1196200 -3.1196200
17 -6.8341993 -11.1196200
18 -10.2341993 -6.8341993
19 -12.6341993 -10.2341993
20 6.4658007 -12.6341993
21 7.5658007 6.4658007
22 -4.4341993 7.5658007
23 6.3658007 -4.4341993
24 -16.0341993 6.3658007
25 -12.7341993 -16.0341993
26 3.9658007 -12.7341993
27 -9.4341993 3.9658007
28 -14.5341993 -9.4341993
29 9.2658007 -14.5341993
30 -6.0341993 9.2658007
31 -4.9341993 -6.0341993
32 12.9658007 -4.9341993
33 5.4658007 12.9658007
34 4.7658007 5.4658007
35 15.3658007 4.7658007
36 -6.1341993 15.3658007
37 -10.1341993 -6.1341993
38 4.4658007 -10.1341993
39 -4.2341993 4.4658007
40 -4.2341993 -4.2341993
41 4.4658007 -4.2341993
42 -16.8341993 4.4658007
43 -5.9341993 -16.8341993
44 11.7658007 -5.9341993
45 2.2658007 11.7658007
46 3.7658007 2.2658007
47 0.9658007 3.7658007
48 -3.6341993 0.9658007
49 -3.1341993 -3.6341993
50 16.3658007 -3.1341993
51 -6.4341993 16.3658007
52 3.6658007 -6.4341993
53 8.5658007 3.6658007
54 -11.6341993 8.5658007
55 -0.1341993 -11.6341993
56 13.8658007 -0.1341993
57 15.2658007 13.8658007
58 12.1658007 15.2658007
59 6.1658007 12.1658007
> 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/734e11195311791.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/8lc1b1195311791.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/9ug021195311791.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
> 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/10nehb1195311791.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/11p6zf1195311791.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/1290df1195311792.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/13b82d1195311792.tab")
>
> system("convert tmp/1ral91195311791.ps tmp/1ral91195311791.png")
> system("convert tmp/2wq4n1195311791.ps tmp/2wq4n1195311791.png")
> system("convert tmp/3r9s81195311791.ps tmp/3r9s81195311791.png")
> system("convert tmp/4qhbn1195311791.ps tmp/4qhbn1195311791.png")
> system("convert tmp/5jn8h1195311791.ps tmp/5jn8h1195311791.png")
> system("convert tmp/6fk9m1195311791.ps tmp/6fk9m1195311791.png")
> system("convert tmp/734e11195311791.ps tmp/734e11195311791.png")
> system("convert tmp/8lc1b1195311791.ps tmp/8lc1b1195311791.png")
> system("convert tmp/9ug021195311791.ps tmp/9ug021195311791.png")
>
>
> proc.time()
user system elapsed
2.280 1.452 2.747