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(98.6,0,98,0,106.8,0,96.7,0,100.2,0,107.7,0,92,0,98.4,0,107.4,0,117.7,0,105.7,0,97.5,0,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,0,109.8,0,101.8,0,114.2,0,110.8,0,108.4,0,127.5,1,128.6,1,116.6,1,127.4,1,105,1,108.3,1,125,1,111.6,1,106.5,1,130.3,1,115,1,116.1,1,134,1,126.5,1,125.8,1,136.4,1,114.9,1,110.9,1,125.5,1,116.8,1,116.8,1,125.5,1,104.2,1,115.1,1,132.8,1,123.3,1,124.8,1,122,1,117.4,1,117.9,1,137.4,1,114.6,1,124.7,1,129.6,1,109.4,1,120.9,1,134.9,1,136.3,1,133.2,1,127.2,1),dim=c(2,72),dimnames=list(c('y','x'),1:72)) > y <- array(NA,dim=c(2,72),dimnames=list(c('y','x'),1:72)) > 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 98.6 0 2 98.0 0 3 106.8 0 4 96.7 0 5 100.2 0 6 107.7 0 7 92.0 0 8 98.4 0 9 107.4 0 10 117.7 0 11 105.7 0 12 97.5 0 13 99.9 0 14 98.2 0 15 104.5 0 16 100.8 0 17 101.5 0 18 103.9 0 19 99.6 0 20 98.4 0 21 112.7 0 22 118.4 0 23 108.1 0 24 105.4 0 25 114.6 0 26 106.9 0 27 115.9 0 28 109.8 0 29 101.8 0 30 114.2 0 31 110.8 0 32 108.4 0 33 127.5 1 34 128.6 1 35 116.6 1 36 127.4 1 37 105.0 1 38 108.3 1 39 125.0 1 40 111.6 1 41 106.5 1 42 130.3 1 43 115.0 1 44 116.1 1 45 134.0 1 46 126.5 1 47 125.8 1 48 136.4 1 49 114.9 1 50 110.9 1 51 125.5 1 52 116.8 1 53 116.8 1 54 125.5 1 55 104.2 1 56 115.1 1 57 132.8 1 58 123.3 1 59 124.8 1 60 122.0 1 61 117.4 1 62 117.9 1 63 137.4 1 64 114.6 1 65 124.7 1 66 129.6 1 67 109.4 1 68 120.9 1 69 134.9 1 70 136.3 1 71 133.2 1 72 127.2 1 > k <- length(x[1,]) > df <- as.data.frame(x) > (mylm <- lm(df)) Call: lm(formula = df) Coefficients: (Intercept) x 105.02 16.90 > (mysum <- summary(mylm)) Call: lm(formula = df) Residuals: Min 1Q Median 3Q Max -17.7175 -6.4656 0.5344 5.5075 15.4825 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 105.016 1.457 72.061 < 2e-16 *** x 16.902 1.955 8.645 1.19e-12 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.244 on 70 degrees of freedom Multiple R-squared: 0.5163, Adjusted R-squared: 0.5094 F-statistic: 74.73 on 1 and 70 DF, p-value: 1.188e-12 > postscript(file="/var/www/html/rcomp/tmp/14g9x1227544760.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/2pqqa1227544760.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/3d3an1227544760.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/4mciw1227544760.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/5wwy81227544760.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 = 72 Frequency = 1 1 2 3 4 5 6 7 -6.415625 -7.015625 1.784375 -8.315625 -4.815625 2.684375 -13.015625 8 9 10 11 12 13 14 -6.615625 2.384375 12.684375 0.684375 -7.515625 -5.115625 -6.815625 15 16 17 18 19 20 21 -0.515625 -4.215625 -3.515625 -1.115625 -5.415625 -6.615625 7.684375 22 23 24 25 26 27 28 13.384375 3.084375 0.384375 9.584375 1.884375 10.884375 4.784375 29 30 31 32 33 34 35 -3.215625 9.184375 5.784375 3.384375 5.582500 6.682500 -5.317500 36 37 38 39 40 41 42 5.482500 -16.917500 -13.617500 3.082500 -10.317500 -15.417500 8.382500 43 44 45 46 47 48 49 -6.917500 -5.817500 12.082500 4.582500 3.882500 14.482500 -7.017500 50 51 52 53 54 55 56 -11.017500 3.582500 -5.117500 -5.117500 3.582500 -17.717500 -6.817500 57 58 59 60 61 62 63 10.882500 1.382500 2.882500 0.082500 -4.517500 -4.017500 15.482500 64 65 66 67 68 69 70 -7.317500 2.782500 7.682500 -12.517500 -1.017500 12.982500 14.382500 71 72 11.282500 5.282500 > postscript(file="/var/www/html/rcomp/tmp/6gcew1227544760.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 = 72 Frequency = 1 lag(myerror, k = 1) myerror 0 -6.415625 NA 1 -7.015625 -6.415625 2 1.784375 -7.015625 3 -8.315625 1.784375 4 -4.815625 -8.315625 5 2.684375 -4.815625 6 -13.015625 2.684375 7 -6.615625 -13.015625 8 2.384375 -6.615625 9 12.684375 2.384375 10 0.684375 12.684375 11 -7.515625 0.684375 12 -5.115625 -7.515625 13 -6.815625 -5.115625 14 -0.515625 -6.815625 15 -4.215625 -0.515625 16 -3.515625 -4.215625 17 -1.115625 -3.515625 18 -5.415625 -1.115625 19 -6.615625 -5.415625 20 7.684375 -6.615625 21 13.384375 7.684375 22 3.084375 13.384375 23 0.384375 3.084375 24 9.584375 0.384375 25 1.884375 9.584375 26 10.884375 1.884375 27 4.784375 10.884375 28 -3.215625 4.784375 29 9.184375 -3.215625 30 5.784375 9.184375 31 3.384375 5.784375 32 5.582500 3.384375 33 6.682500 5.582500 34 -5.317500 6.682500 35 5.482500 -5.317500 36 -16.917500 5.482500 37 -13.617500 -16.917500 38 3.082500 -13.617500 39 -10.317500 3.082500 40 -15.417500 -10.317500 41 8.382500 -15.417500 42 -6.917500 8.382500 43 -5.817500 -6.917500 44 12.082500 -5.817500 45 4.582500 12.082500 46 3.882500 4.582500 47 14.482500 3.882500 48 -7.017500 14.482500 49 -11.017500 -7.017500 50 3.582500 -11.017500 51 -5.117500 3.582500 52 -5.117500 -5.117500 53 3.582500 -5.117500 54 -17.717500 3.582500 55 -6.817500 -17.717500 56 10.882500 -6.817500 57 1.382500 10.882500 58 2.882500 1.382500 59 0.082500 2.882500 60 -4.517500 0.082500 61 -4.017500 -4.517500 62 15.482500 -4.017500 63 -7.317500 15.482500 64 2.782500 -7.317500 65 7.682500 2.782500 66 -12.517500 7.682500 67 -1.017500 -12.517500 68 12.982500 -1.017500 69 14.382500 12.982500 70 11.282500 14.382500 71 5.282500 11.282500 72 NA 5.282500 > dum1 <- dum[2:length(myerror),] > dum1 lag(myerror, k = 1) myerror [1,] -7.015625 -6.415625 [2,] 1.784375 -7.015625 [3,] -8.315625 1.784375 [4,] -4.815625 -8.315625 [5,] 2.684375 -4.815625 [6,] -13.015625 2.684375 [7,] -6.615625 -13.015625 [8,] 2.384375 -6.615625 [9,] 12.684375 2.384375 [10,] 0.684375 12.684375 [11,] -7.515625 0.684375 [12,] -5.115625 -7.515625 [13,] -6.815625 -5.115625 [14,] -0.515625 -6.815625 [15,] -4.215625 -0.515625 [16,] -3.515625 -4.215625 [17,] -1.115625 -3.515625 [18,] -5.415625 -1.115625 [19,] -6.615625 -5.415625 [20,] 7.684375 -6.615625 [21,] 13.384375 7.684375 [22,] 3.084375 13.384375 [23,] 0.384375 3.084375 [24,] 9.584375 0.384375 [25,] 1.884375 9.584375 [26,] 10.884375 1.884375 [27,] 4.784375 10.884375 [28,] -3.215625 4.784375 [29,] 9.184375 -3.215625 [30,] 5.784375 9.184375 [31,] 3.384375 5.784375 [32,] 5.582500 3.384375 [33,] 6.682500 5.582500 [34,] -5.317500 6.682500 [35,] 5.482500 -5.317500 [36,] -16.917500 5.482500 [37,] -13.617500 -16.917500 [38,] 3.082500 -13.617500 [39,] -10.317500 3.082500 [40,] -15.417500 -10.317500 [41,] 8.382500 -15.417500 [42,] -6.917500 8.382500 [43,] -5.817500 -6.917500 [44,] 12.082500 -5.817500 [45,] 4.582500 12.082500 [46,] 3.882500 4.582500 [47,] 14.482500 3.882500 [48,] -7.017500 14.482500 [49,] -11.017500 -7.017500 [50,] 3.582500 -11.017500 [51,] -5.117500 3.582500 [52,] -5.117500 -5.117500 [53,] 3.582500 -5.117500 [54,] -17.717500 3.582500 [55,] -6.817500 -17.717500 [56,] 10.882500 -6.817500 [57,] 1.382500 10.882500 [58,] 2.882500 1.382500 [59,] 0.082500 2.882500 [60,] -4.517500 0.082500 [61,] -4.017500 -4.517500 [62,] 15.482500 -4.017500 [63,] -7.317500 15.482500 [64,] 2.782500 -7.317500 [65,] 7.682500 2.782500 [66,] -12.517500 7.682500 [67,] -1.017500 -12.517500 [68,] 12.982500 -1.017500 [69,] 14.382500 12.982500 [70,] 11.282500 14.382500 [71,] 5.282500 11.282500 > z <- as.data.frame(dum1) > z lag(myerror, k = 1) myerror 1 -7.015625 -6.415625 2 1.784375 -7.015625 3 -8.315625 1.784375 4 -4.815625 -8.315625 5 2.684375 -4.815625 6 -13.015625 2.684375 7 -6.615625 -13.015625 8 2.384375 -6.615625 9 12.684375 2.384375 10 0.684375 12.684375 11 -7.515625 0.684375 12 -5.115625 -7.515625 13 -6.815625 -5.115625 14 -0.515625 -6.815625 15 -4.215625 -0.515625 16 -3.515625 -4.215625 17 -1.115625 -3.515625 18 -5.415625 -1.115625 19 -6.615625 -5.415625 20 7.684375 -6.615625 21 13.384375 7.684375 22 3.084375 13.384375 23 0.384375 3.084375 24 9.584375 0.384375 25 1.884375 9.584375 26 10.884375 1.884375 27 4.784375 10.884375 28 -3.215625 4.784375 29 9.184375 -3.215625 30 5.784375 9.184375 31 3.384375 5.784375 32 5.582500 3.384375 33 6.682500 5.582500 34 -5.317500 6.682500 35 5.482500 -5.317500 36 -16.917500 5.482500 37 -13.617500 -16.917500 38 3.082500 -13.617500 39 -10.317500 3.082500 40 -15.417500 -10.317500 41 8.382500 -15.417500 42 -6.917500 8.382500 43 -5.817500 -6.917500 44 12.082500 -5.817500 45 4.582500 12.082500 46 3.882500 4.582500 47 14.482500 3.882500 48 -7.017500 14.482500 49 -11.017500 -7.017500 50 3.582500 -11.017500 51 -5.117500 3.582500 52 -5.117500 -5.117500 53 3.582500 -5.117500 54 -17.717500 3.582500 55 -6.817500 -17.717500 56 10.882500 -6.817500 57 1.382500 10.882500 58 2.882500 1.382500 59 0.082500 2.882500 60 -4.517500 0.082500 61 -4.017500 -4.517500 62 15.482500 -4.017500 63 -7.317500 15.482500 64 2.782500 -7.317500 65 7.682500 2.782500 66 -12.517500 7.682500 67 -1.017500 -12.517500 68 12.982500 -1.017500 69 14.382500 12.982500 70 11.282500 14.382500 71 5.282500 11.282500 > 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/72c8d1227544760.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/8qw561227544760.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/950qn1227544760.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/10zqjl1227544760.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/112ukc1227544761.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/12mlys1227544761.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/13qi781227544761.tab") > > system("convert tmp/14g9x1227544760.ps tmp/14g9x1227544760.png") > system("convert tmp/2pqqa1227544760.ps tmp/2pqqa1227544760.png") > system("convert tmp/3d3an1227544760.ps tmp/3d3an1227544760.png") > system("convert tmp/4mciw1227544760.ps tmp/4mciw1227544760.png") > system("convert tmp/5wwy81227544760.ps tmp/5wwy81227544760.png") > system("convert tmp/6gcew1227544760.ps tmp/6gcew1227544760.png") > system("convert tmp/72c8d1227544760.ps tmp/72c8d1227544760.png") > system("convert tmp/8qw561227544760.ps tmp/8qw561227544760.png") > system("convert tmp/950qn1227544760.ps tmp/950qn1227544760.png") > > > proc.time() user system elapsed 1.943 1.415 2.449