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(41.1,0,58,0,63,0,53.8,0,54.7,0,55.5,0,56.1,0,69.6,0,69.4,0,57.2,0,68,0,53.3,0,47.9,0,60.8,0,61.7,0,57.8,0,51.4,0,50.5,0,48.1,0,58.7,0,54,0,56.1,0,60.4,0,51.2,0,50.7,0,56.4,0,53.3,0,52.6,0,47.7,0,49.5,0,48.5,0,55.3,0,49.8,0,57.4,0,64.6,0,53,0,41.5,0,55.9,0,58.4,0,53.5,0,50.6,0,58.5,1,49.1,1,61.1,1,52.3,1,58.4,1,65.5,1,61.7,1,45.1,1,52.1,1,59.3,1,57.9,1,45,1,64.9,1,63.8,1,69.4,1,71.1,1,62.9,1,73.5,1,62.6,1),dim=c(2,60),dimnames=list(c('Tabakproductie','rookverbod'),1:60))
> y <- array(NA,dim=c(2,60),dimnames=list(c('Tabakproductie','rookverbod'),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
Tabakproductie rookverbod
1 41.1 0
2 58.0 0
3 63.0 0
4 53.8 0
5 54.7 0
6 55.5 0
7 56.1 0
8 69.6 0
9 69.4 0
10 57.2 0
11 68.0 0
12 53.3 0
13 47.9 0
14 60.8 0
15 61.7 0
16 57.8 0
17 51.4 0
18 50.5 0
19 48.1 0
20 58.7 0
21 54.0 0
22 56.1 0
23 60.4 0
24 51.2 0
25 50.7 0
26 56.4 0
27 53.3 0
28 52.6 0
29 47.7 0
30 49.5 0
31 48.5 0
32 55.3 0
33 49.8 0
34 57.4 0
35 64.6 0
36 53.0 0
37 41.5 0
38 55.9 0
39 58.4 0
40 53.5 0
41 50.6 0
42 58.5 1
43 49.1 1
44 61.1 1
45 52.3 1
46 58.4 1
47 65.5 1
48 61.7 1
49 45.1 1
50 52.1 1
51 59.3 1
52 57.9 1
53 45.0 1
54 64.9 1
55 63.8 1
56 69.4 1
57 71.1 1
58 62.9 1
59 73.5 1
60 62.6 1
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) rookverbod
55.049 4.646
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-14.69474 -4.37378 -0.04878 3.42622 14.55122
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 55.049 1.089 50.54 <2e-16 ***
rookverbod 4.646 1.935 2.40 0.0196 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 6.974 on 58 degrees of freedom
Multiple R-squared: 0.09037, Adjusted R-squared: 0.07469
F-statistic: 5.762 on 1 and 58 DF, p-value: 0.01960
> postscript(file="/var/www/html/freestat/rcomp/tmp/1vx2p1227556235.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/freestat/rcomp/tmp/2gesv1227556235.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/freestat/rcomp/tmp/3o3151227556235.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/freestat/rcomp/tmp/46cb21227556235.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/freestat/rcomp/tmp/56f6k1227556235.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
-13.9487805 2.9512195 7.9512195 -1.2487805 -0.3487805 0.4512195
7 8 9 10 11 12
1.0512195 14.5512195 14.3512195 2.1512195 12.9512195 -1.7487805
13 14 15 16 17 18
-7.1487805 5.7512195 6.6512195 2.7512195 -3.6487805 -4.5487805
19 20 21 22 23 24
-6.9487805 3.6512195 -1.0487805 1.0512195 5.3512195 -3.8487805
25 26 27 28 29 30
-4.3487805 1.3512195 -1.7487805 -2.4487805 -7.3487805 -5.5487805
31 32 33 34 35 36
-6.5487805 0.2512195 -5.2487805 2.3512195 9.5512195 -2.0487805
37 38 39 40 41 42
-13.5487805 0.8512195 3.3512195 -1.5487805 -4.4487805 -1.1947368
43 44 45 46 47 48
-10.5947368 1.4052632 -7.3947368 -1.2947368 5.8052632 2.0052632
49 50 51 52 53 54
-14.5947368 -7.5947368 -0.3947368 -1.7947368 -14.6947368 5.2052632
55 56 57 58 59 60
4.1052632 9.7052632 11.4052632 3.2052632 13.8052632 2.9052632
> postscript(file="/var/www/html/freestat/rcomp/tmp/67hcd1227556235.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 -13.9487805 NA
1 2.9512195 -13.9487805
2 7.9512195 2.9512195
3 -1.2487805 7.9512195
4 -0.3487805 -1.2487805
5 0.4512195 -0.3487805
6 1.0512195 0.4512195
7 14.5512195 1.0512195
8 14.3512195 14.5512195
9 2.1512195 14.3512195
10 12.9512195 2.1512195
11 -1.7487805 12.9512195
12 -7.1487805 -1.7487805
13 5.7512195 -7.1487805
14 6.6512195 5.7512195
15 2.7512195 6.6512195
16 -3.6487805 2.7512195
17 -4.5487805 -3.6487805
18 -6.9487805 -4.5487805
19 3.6512195 -6.9487805
20 -1.0487805 3.6512195
21 1.0512195 -1.0487805
22 5.3512195 1.0512195
23 -3.8487805 5.3512195
24 -4.3487805 -3.8487805
25 1.3512195 -4.3487805
26 -1.7487805 1.3512195
27 -2.4487805 -1.7487805
28 -7.3487805 -2.4487805
29 -5.5487805 -7.3487805
30 -6.5487805 -5.5487805
31 0.2512195 -6.5487805
32 -5.2487805 0.2512195
33 2.3512195 -5.2487805
34 9.5512195 2.3512195
35 -2.0487805 9.5512195
36 -13.5487805 -2.0487805
37 0.8512195 -13.5487805
38 3.3512195 0.8512195
39 -1.5487805 3.3512195
40 -4.4487805 -1.5487805
41 -1.1947368 -4.4487805
42 -10.5947368 -1.1947368
43 1.4052632 -10.5947368
44 -7.3947368 1.4052632
45 -1.2947368 -7.3947368
46 5.8052632 -1.2947368
47 2.0052632 5.8052632
48 -14.5947368 2.0052632
49 -7.5947368 -14.5947368
50 -0.3947368 -7.5947368
51 -1.7947368 -0.3947368
52 -14.6947368 -1.7947368
53 5.2052632 -14.6947368
54 4.1052632 5.2052632
55 9.7052632 4.1052632
56 11.4052632 9.7052632
57 3.2052632 11.4052632
58 13.8052632 3.2052632
59 2.9052632 13.8052632
60 NA 2.9052632
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] 2.9512195 -13.9487805
[2,] 7.9512195 2.9512195
[3,] -1.2487805 7.9512195
[4,] -0.3487805 -1.2487805
[5,] 0.4512195 -0.3487805
[6,] 1.0512195 0.4512195
[7,] 14.5512195 1.0512195
[8,] 14.3512195 14.5512195
[9,] 2.1512195 14.3512195
[10,] 12.9512195 2.1512195
[11,] -1.7487805 12.9512195
[12,] -7.1487805 -1.7487805
[13,] 5.7512195 -7.1487805
[14,] 6.6512195 5.7512195
[15,] 2.7512195 6.6512195
[16,] -3.6487805 2.7512195
[17,] -4.5487805 -3.6487805
[18,] -6.9487805 -4.5487805
[19,] 3.6512195 -6.9487805
[20,] -1.0487805 3.6512195
[21,] 1.0512195 -1.0487805
[22,] 5.3512195 1.0512195
[23,] -3.8487805 5.3512195
[24,] -4.3487805 -3.8487805
[25,] 1.3512195 -4.3487805
[26,] -1.7487805 1.3512195
[27,] -2.4487805 -1.7487805
[28,] -7.3487805 -2.4487805
[29,] -5.5487805 -7.3487805
[30,] -6.5487805 -5.5487805
[31,] 0.2512195 -6.5487805
[32,] -5.2487805 0.2512195
[33,] 2.3512195 -5.2487805
[34,] 9.5512195 2.3512195
[35,] -2.0487805 9.5512195
[36,] -13.5487805 -2.0487805
[37,] 0.8512195 -13.5487805
[38,] 3.3512195 0.8512195
[39,] -1.5487805 3.3512195
[40,] -4.4487805 -1.5487805
[41,] -1.1947368 -4.4487805
[42,] -10.5947368 -1.1947368
[43,] 1.4052632 -10.5947368
[44,] -7.3947368 1.4052632
[45,] -1.2947368 -7.3947368
[46,] 5.8052632 -1.2947368
[47,] 2.0052632 5.8052632
[48,] -14.5947368 2.0052632
[49,] -7.5947368 -14.5947368
[50,] -0.3947368 -7.5947368
[51,] -1.7947368 -0.3947368
[52,] -14.6947368 -1.7947368
[53,] 5.2052632 -14.6947368
[54,] 4.1052632 5.2052632
[55,] 9.7052632 4.1052632
[56,] 11.4052632 9.7052632
[57,] 3.2052632 11.4052632
[58,] 13.8052632 3.2052632
[59,] 2.9052632 13.8052632
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 2.9512195 -13.9487805
2 7.9512195 2.9512195
3 -1.2487805 7.9512195
4 -0.3487805 -1.2487805
5 0.4512195 -0.3487805
6 1.0512195 0.4512195
7 14.5512195 1.0512195
8 14.3512195 14.5512195
9 2.1512195 14.3512195
10 12.9512195 2.1512195
11 -1.7487805 12.9512195
12 -7.1487805 -1.7487805
13 5.7512195 -7.1487805
14 6.6512195 5.7512195
15 2.7512195 6.6512195
16 -3.6487805 2.7512195
17 -4.5487805 -3.6487805
18 -6.9487805 -4.5487805
19 3.6512195 -6.9487805
20 -1.0487805 3.6512195
21 1.0512195 -1.0487805
22 5.3512195 1.0512195
23 -3.8487805 5.3512195
24 -4.3487805 -3.8487805
25 1.3512195 -4.3487805
26 -1.7487805 1.3512195
27 -2.4487805 -1.7487805
28 -7.3487805 -2.4487805
29 -5.5487805 -7.3487805
30 -6.5487805 -5.5487805
31 0.2512195 -6.5487805
32 -5.2487805 0.2512195
33 2.3512195 -5.2487805
34 9.5512195 2.3512195
35 -2.0487805 9.5512195
36 -13.5487805 -2.0487805
37 0.8512195 -13.5487805
38 3.3512195 0.8512195
39 -1.5487805 3.3512195
40 -4.4487805 -1.5487805
41 -1.1947368 -4.4487805
42 -10.5947368 -1.1947368
43 1.4052632 -10.5947368
44 -7.3947368 1.4052632
45 -1.2947368 -7.3947368
46 5.8052632 -1.2947368
47 2.0052632 5.8052632
48 -14.5947368 2.0052632
49 -7.5947368 -14.5947368
50 -0.3947368 -7.5947368
51 -1.7947368 -0.3947368
52 -14.6947368 -1.7947368
53 5.2052632 -14.6947368
54 4.1052632 5.2052632
55 9.7052632 4.1052632
56 11.4052632 9.7052632
57 3.2052632 11.4052632
58 13.8052632 3.2052632
59 2.9052632 13.8052632
> 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/freestat/rcomp/tmp/7bjuw1227556235.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/freestat/rcomp/tmp/83vzc1227556235.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/freestat/rcomp/tmp/9saxe1227556235.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/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
> load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/104vno1227556235.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/freestat/rcomp/tmp/11guyk1227556235.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/freestat/rcomp/tmp/125oqn1227556236.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/freestat/rcomp/tmp/13mxj71227556236.tab")
>
> system("convert tmp/1vx2p1227556235.ps tmp/1vx2p1227556235.png")
> system("convert tmp/2gesv1227556235.ps tmp/2gesv1227556235.png")
> system("convert tmp/3o3151227556235.ps tmp/3o3151227556235.png")
> system("convert tmp/46cb21227556235.ps tmp/46cb21227556235.png")
> system("convert tmp/56f6k1227556235.ps tmp/56f6k1227556235.png")
> system("convert tmp/67hcd1227556235.ps tmp/67hcd1227556235.png")
> system("convert tmp/7bjuw1227556235.ps tmp/7bjuw1227556235.png")
> system("convert tmp/83vzc1227556235.ps tmp/83vzc1227556235.png")
> system("convert tmp/9saxe1227556235.ps tmp/9saxe1227556235.png")
>
>
> proc.time()
user system elapsed
3.027 2.298 3.904