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(8.1,359,8.3,304.6,8.2,297.7,8.1,303.3,7.7,304.7,7.6,331.3,7.7,318.8,8.2,306.8,8.4,331.1,8.4,284.1,8.6,259.7,8.4,335.8,8.5,338.5,8.7,310.3,8.7,322.1,8.6,289.3,7.4,300.8,7.3,360.6,7.4,327.3,9,304.1,9.2,362,9.2,287.8,8.5,286.1,8.3,358.2,8.3,346,8.6,329.9,8.6,334.3,8.5,303.7,8.1,307.6,8.1,351.7,8,324.6,8.6,311.9,8.7,361.5,8.7,271.1,8.6,286.5,8.4,352.8,8.4,322.4,8.7,335,8.7,322.2,8.5,313.6,8.3,323.3,8.3,379.1,8.3,315.6,8.1,353.6,8.2,371.7,8.1,282.9,8.1,298.8,7.9,361.8,7.7,365.9,8.1,357.6,8,335.4,7.7,340.1,7.8,337.8,7.6,389.6,7.4,342.5,7.7,354.6,7.8,391.6,7.5,317.7,7.2,312.8,7,356.2),dim=c(2,60),dimnames=list(c('werkl','Iprod'),1:60))
> y <- array(NA,dim=c(2,60),dimnames=list(c('werkl','Iprod'),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 = '2'
> #'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
Iprod werkl
1 359.0 8.1
2 304.6 8.3
3 297.7 8.2
4 303.3 8.1
5 304.7 7.7
6 331.3 7.6
7 318.8 7.7
8 306.8 8.2
9 331.1 8.4
10 284.1 8.4
11 259.7 8.6
12 335.8 8.4
13 338.5 8.5
14 310.3 8.7
15 322.1 8.7
16 289.3 8.6
17 300.8 7.4
18 360.6 7.3
19 327.3 7.4
20 304.1 9.0
21 362.0 9.2
22 287.8 9.2
23 286.1 8.5
24 358.2 8.3
25 346.0 8.3
26 329.9 8.6
27 334.3 8.6
28 303.7 8.5
29 307.6 8.1
30 351.7 8.1
31 324.6 8.0
32 311.9 8.6
33 361.5 8.7
34 271.1 8.7
35 286.5 8.6
36 352.8 8.4
37 322.4 8.4
38 335.0 8.7
39 322.2 8.7
40 313.6 8.5
41 323.3 8.3
42 379.1 8.3
43 315.6 8.3
44 353.6 8.1
45 371.7 8.2
46 282.9 8.1
47 298.8 8.1
48 361.8 7.9
49 365.9 7.7
50 357.6 8.1
51 335.4 8.0
52 340.1 7.7
53 337.8 7.8
54 389.6 7.6
55 342.5 7.4
56 354.6 7.7
57 391.6 7.8
58 317.7 7.5
59 312.8 7.2
60 356.2 7.0
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) werkl
480.35 -18.69
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-59.9064 -20.7983 -0.2402 18.8253 57.0407
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 480.350 62.434 7.694 2e-10 ***
werkl -18.691 7.619 -2.453 0.0172 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 28.4 on 58 degrees of freedom
Multiple R-Squared: 0.094, Adjusted R-squared: 0.07838
F-statistic: 6.018 on 1 and 58 DF, p-value: 0.01719
> postscript(file="/var/www/html/rcomp/tmp/1oy5l1198243178.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/2nm5k1198243178.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/3peoy1198243178.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/423y51198243178.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/51lqm1198243178.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
30.0480426 -20.6137306 -29.3828440 -25.6519574 -31.7284111 -6.9975245
7 8 9 10 11 12
-17.6284111 -20.2828440 7.7553828 -39.2446172 -59.9063903 12.4553828
13 14 15 16 17 18
17.0244963 -7.4372769 4.3627231 -30.3063903 -41.2357513 16.6951353
19 20 21 22 23 24
-14.7357513 -8.0299367 53.6082902 -20.5917098 -35.3755037 32.9862694
25 26 27 28 29 30
20.7862694 10.2936097 14.6936097 -17.7755037 -21.3519574 22.7480426
31 32 33 34 35 36
-6.2210708 -7.7063903 43.7627231 -46.6372769 -33.1063903 29.4553828
37 38 39 40 41 42
-0.9446172 17.2627231 4.4627231 -7.8755037 -1.9137306 53.8862694
43 44 45 46 47 48
-9.6137306 24.6480426 44.6171560 -46.0519574 -30.1519574 29.1098158
49 50 51 52 53 54
29.4715889 28.6480426 4.5789292 3.6715889 3.2407024 51.3024755
55 56 57 58 59 60
0.4642487 18.1715889 57.0407024 -22.4666379 -32.9739781 6.6877950
> postscript(file="/var/www/html/rcomp/tmp/6xzr31198243178.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 30.0480426 NA
1 -20.6137306 30.0480426
2 -29.3828440 -20.6137306
3 -25.6519574 -29.3828440
4 -31.7284111 -25.6519574
5 -6.9975245 -31.7284111
6 -17.6284111 -6.9975245
7 -20.2828440 -17.6284111
8 7.7553828 -20.2828440
9 -39.2446172 7.7553828
10 -59.9063903 -39.2446172
11 12.4553828 -59.9063903
12 17.0244963 12.4553828
13 -7.4372769 17.0244963
14 4.3627231 -7.4372769
15 -30.3063903 4.3627231
16 -41.2357513 -30.3063903
17 16.6951353 -41.2357513
18 -14.7357513 16.6951353
19 -8.0299367 -14.7357513
20 53.6082902 -8.0299367
21 -20.5917098 53.6082902
22 -35.3755037 -20.5917098
23 32.9862694 -35.3755037
24 20.7862694 32.9862694
25 10.2936097 20.7862694
26 14.6936097 10.2936097
27 -17.7755037 14.6936097
28 -21.3519574 -17.7755037
29 22.7480426 -21.3519574
30 -6.2210708 22.7480426
31 -7.7063903 -6.2210708
32 43.7627231 -7.7063903
33 -46.6372769 43.7627231
34 -33.1063903 -46.6372769
35 29.4553828 -33.1063903
36 -0.9446172 29.4553828
37 17.2627231 -0.9446172
38 4.4627231 17.2627231
39 -7.8755037 4.4627231
40 -1.9137306 -7.8755037
41 53.8862694 -1.9137306
42 -9.6137306 53.8862694
43 24.6480426 -9.6137306
44 44.6171560 24.6480426
45 -46.0519574 44.6171560
46 -30.1519574 -46.0519574
47 29.1098158 -30.1519574
48 29.4715889 29.1098158
49 28.6480426 29.4715889
50 4.5789292 28.6480426
51 3.6715889 4.5789292
52 3.2407024 3.6715889
53 51.3024755 3.2407024
54 0.4642487 51.3024755
55 18.1715889 0.4642487
56 57.0407024 18.1715889
57 -22.4666379 57.0407024
58 -32.9739781 -22.4666379
59 6.6877950 -32.9739781
60 NA 6.6877950
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] -20.6137306 30.0480426
[2,] -29.3828440 -20.6137306
[3,] -25.6519574 -29.3828440
[4,] -31.7284111 -25.6519574
[5,] -6.9975245 -31.7284111
[6,] -17.6284111 -6.9975245
[7,] -20.2828440 -17.6284111
[8,] 7.7553828 -20.2828440
[9,] -39.2446172 7.7553828
[10,] -59.9063903 -39.2446172
[11,] 12.4553828 -59.9063903
[12,] 17.0244963 12.4553828
[13,] -7.4372769 17.0244963
[14,] 4.3627231 -7.4372769
[15,] -30.3063903 4.3627231
[16,] -41.2357513 -30.3063903
[17,] 16.6951353 -41.2357513
[18,] -14.7357513 16.6951353
[19,] -8.0299367 -14.7357513
[20,] 53.6082902 -8.0299367
[21,] -20.5917098 53.6082902
[22,] -35.3755037 -20.5917098
[23,] 32.9862694 -35.3755037
[24,] 20.7862694 32.9862694
[25,] 10.2936097 20.7862694
[26,] 14.6936097 10.2936097
[27,] -17.7755037 14.6936097
[28,] -21.3519574 -17.7755037
[29,] 22.7480426 -21.3519574
[30,] -6.2210708 22.7480426
[31,] -7.7063903 -6.2210708
[32,] 43.7627231 -7.7063903
[33,] -46.6372769 43.7627231
[34,] -33.1063903 -46.6372769
[35,] 29.4553828 -33.1063903
[36,] -0.9446172 29.4553828
[37,] 17.2627231 -0.9446172
[38,] 4.4627231 17.2627231
[39,] -7.8755037 4.4627231
[40,] -1.9137306 -7.8755037
[41,] 53.8862694 -1.9137306
[42,] -9.6137306 53.8862694
[43,] 24.6480426 -9.6137306
[44,] 44.6171560 24.6480426
[45,] -46.0519574 44.6171560
[46,] -30.1519574 -46.0519574
[47,] 29.1098158 -30.1519574
[48,] 29.4715889 29.1098158
[49,] 28.6480426 29.4715889
[50,] 4.5789292 28.6480426
[51,] 3.6715889 4.5789292
[52,] 3.2407024 3.6715889
[53,] 51.3024755 3.2407024
[54,] 0.4642487 51.3024755
[55,] 18.1715889 0.4642487
[56,] 57.0407024 18.1715889
[57,] -22.4666379 57.0407024
[58,] -32.9739781 -22.4666379
[59,] 6.6877950 -32.9739781
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 -20.6137306 30.0480426
2 -29.3828440 -20.6137306
3 -25.6519574 -29.3828440
4 -31.7284111 -25.6519574
5 -6.9975245 -31.7284111
6 -17.6284111 -6.9975245
7 -20.2828440 -17.6284111
8 7.7553828 -20.2828440
9 -39.2446172 7.7553828
10 -59.9063903 -39.2446172
11 12.4553828 -59.9063903
12 17.0244963 12.4553828
13 -7.4372769 17.0244963
14 4.3627231 -7.4372769
15 -30.3063903 4.3627231
16 -41.2357513 -30.3063903
17 16.6951353 -41.2357513
18 -14.7357513 16.6951353
19 -8.0299367 -14.7357513
20 53.6082902 -8.0299367
21 -20.5917098 53.6082902
22 -35.3755037 -20.5917098
23 32.9862694 -35.3755037
24 20.7862694 32.9862694
25 10.2936097 20.7862694
26 14.6936097 10.2936097
27 -17.7755037 14.6936097
28 -21.3519574 -17.7755037
29 22.7480426 -21.3519574
30 -6.2210708 22.7480426
31 -7.7063903 -6.2210708
32 43.7627231 -7.7063903
33 -46.6372769 43.7627231
34 -33.1063903 -46.6372769
35 29.4553828 -33.1063903
36 -0.9446172 29.4553828
37 17.2627231 -0.9446172
38 4.4627231 17.2627231
39 -7.8755037 4.4627231
40 -1.9137306 -7.8755037
41 53.8862694 -1.9137306
42 -9.6137306 53.8862694
43 24.6480426 -9.6137306
44 44.6171560 24.6480426
45 -46.0519574 44.6171560
46 -30.1519574 -46.0519574
47 29.1098158 -30.1519574
48 29.4715889 29.1098158
49 28.6480426 29.4715889
50 4.5789292 28.6480426
51 3.6715889 4.5789292
52 3.2407024 3.6715889
53 51.3024755 3.2407024
54 0.4642487 51.3024755
55 18.1715889 0.4642487
56 57.0407024 18.1715889
57 -22.4666379 57.0407024
58 -32.9739781 -22.4666379
59 6.6877950 -32.9739781
> 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/7797k1198243178.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/80ese1198243178.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/9wa9b1198243178.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/10yna51198243178.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/11yb0n1198243178.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/12qyfh1198243179.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/13qfqz1198243179.tab")
>
> system("convert tmp/1oy5l1198243178.ps tmp/1oy5l1198243178.png")
> system("convert tmp/2nm5k1198243178.ps tmp/2nm5k1198243178.png")
> system("convert tmp/3peoy1198243178.ps tmp/3peoy1198243178.png")
> system("convert tmp/423y51198243178.ps tmp/423y51198243178.png")
> system("convert tmp/51lqm1198243178.ps tmp/51lqm1198243178.png")
> system("convert tmp/6xzr31198243178.ps tmp/6xzr31198243178.png")
> system("convert tmp/7797k1198243178.ps tmp/7797k1198243178.png")
> system("convert tmp/80ese1198243178.ps tmp/80ese1198243178.png")
> system("convert tmp/9wa9b1198243178.ps tmp/9wa9b1198243178.png")
>
>
> proc.time()
user system elapsed
2.223 1.445 3.117