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(493.000,0,481.000,0,462.000,0,457.000,0,442.000,0,439.000,0,488.000,0,521.000,0,501.000,0,485.000,0,464.000,0,460.000,0,467.000,0,460.000,0,448.000,0,443.000,0,436.000,0,431.000,0,484.000,0,510.000,0,513.000,0,503.000,0,471.000,0,471.000,0,476.000,0,475.000,0,470.000,0,461.000,0,455.000,0,456.000,0,517.000,1,525.000,1,523.000,1,519.000,1,509.000,1,512.000,1,519.000,1,517.000,1,510.000,1,509.000,1,501.000,1,507.000,1,569.000,1,580.000,1,578.000,1,565.000,1,547.000,1,555.000,1,562.000,1,561.000,1,555.000,1,544.000,1,537.000,1,543.000,1,594.000,1,611.000,1,613.000,1,611.000,1,594.000,1,595.000,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 493 0 2 481 0 3 462 0 4 457 0 5 442 0 6 439 0 7 488 0 8 521 0 9 501 0 10 485 0 11 464 0 12 460 0 13 467 0 14 460 0 15 448 0 16 443 0 17 436 0 18 431 0 19 484 0 20 510 0 21 513 0 22 503 0 23 471 0 24 471 0 25 476 0 26 475 0 27 470 0 28 461 0 29 455 0 30 456 0 31 517 1 32 525 1 33 523 1 34 519 1 35 509 1 36 512 1 37 519 1 38 517 1 39 510 1 40 509 1 41 501 1 42 507 1 43 569 1 44 580 1 45 578 1 46 565 1 47 547 1 48 555 1 49 562 1 50 561 1 51 555 1 52 544 1 53 537 1 54 543 1 55 594 1 56 611 1 57 613 1 58 611 1 59 594 1 60 595 1 > k <- length(x[1,]) > df <- as.data.frame(x) > (mylm <- lm(df)) Call: lm(formula = df) Coefficients: (Intercept) x 470.77 78.63 > (mysum <- summary(mylm)) Call: lm(formula = df) Residuals: Min 1Q Median 3Q Max -48.400 -26.742 -3.083 17.825 63.600 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 470.767 5.488 85.78 < 2e-16 *** x 78.633 7.762 10.13 1.91e-14 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 30.06 on 58 degrees of freedom Multiple R-squared: 0.6389, Adjusted R-squared: 0.6327 F-statistic: 102.6 on 1 and 58 DF, p-value: 1.911e-14 > postscript(file="/var/www/html/rcomp/tmp/1gi551229082490.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/2mw171229082490.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/3qg701229082490.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/4euhr1229082490.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/5qh0f1229082490.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 22.2333333 10.2333333 -8.7666667 -13.7666667 -28.7666667 -31.7666667 7 8 9 10 11 12 17.2333333 50.2333333 30.2333333 14.2333333 -6.7666667 -10.7666667 13 14 15 16 17 18 -3.7666667 -10.7666667 -22.7666667 -27.7666667 -34.7666667 -39.7666667 19 20 21 22 23 24 13.2333333 39.2333333 42.2333333 32.2333333 0.2333333 0.2333333 25 26 27 28 29 30 5.2333333 4.2333333 -0.7666667 -9.7666667 -15.7666667 -14.7666667 31 32 33 34 35 36 -32.4000000 -24.4000000 -26.4000000 -30.4000000 -40.4000000 -37.4000000 37 38 39 40 41 42 -30.4000000 -32.4000000 -39.4000000 -40.4000000 -48.4000000 -42.4000000 43 44 45 46 47 48 19.6000000 30.6000000 28.6000000 15.6000000 -2.4000000 5.6000000 49 50 51 52 53 54 12.6000000 11.6000000 5.6000000 -5.4000000 -12.4000000 -6.4000000 55 56 57 58 59 60 44.6000000 61.6000000 63.6000000 61.6000000 44.6000000 45.6000000 > postscript(file="/var/www/html/rcomp/tmp/61yz81229082490.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 22.2333333 NA 1 10.2333333 22.2333333 2 -8.7666667 10.2333333 3 -13.7666667 -8.7666667 4 -28.7666667 -13.7666667 5 -31.7666667 -28.7666667 6 17.2333333 -31.7666667 7 50.2333333 17.2333333 8 30.2333333 50.2333333 9 14.2333333 30.2333333 10 -6.7666667 14.2333333 11 -10.7666667 -6.7666667 12 -3.7666667 -10.7666667 13 -10.7666667 -3.7666667 14 -22.7666667 -10.7666667 15 -27.7666667 -22.7666667 16 -34.7666667 -27.7666667 17 -39.7666667 -34.7666667 18 13.2333333 -39.7666667 19 39.2333333 13.2333333 20 42.2333333 39.2333333 21 32.2333333 42.2333333 22 0.2333333 32.2333333 23 0.2333333 0.2333333 24 5.2333333 0.2333333 25 4.2333333 5.2333333 26 -0.7666667 4.2333333 27 -9.7666667 -0.7666667 28 -15.7666667 -9.7666667 29 -14.7666667 -15.7666667 30 -32.4000000 -14.7666667 31 -24.4000000 -32.4000000 32 -26.4000000 -24.4000000 33 -30.4000000 -26.4000000 34 -40.4000000 -30.4000000 35 -37.4000000 -40.4000000 36 -30.4000000 -37.4000000 37 -32.4000000 -30.4000000 38 -39.4000000 -32.4000000 39 -40.4000000 -39.4000000 40 -48.4000000 -40.4000000 41 -42.4000000 -48.4000000 42 19.6000000 -42.4000000 43 30.6000000 19.6000000 44 28.6000000 30.6000000 45 15.6000000 28.6000000 46 -2.4000000 15.6000000 47 5.6000000 -2.4000000 48 12.6000000 5.6000000 49 11.6000000 12.6000000 50 5.6000000 11.6000000 51 -5.4000000 5.6000000 52 -12.4000000 -5.4000000 53 -6.4000000 -12.4000000 54 44.6000000 -6.4000000 55 61.6000000 44.6000000 56 63.6000000 61.6000000 57 61.6000000 63.6000000 58 44.6000000 61.6000000 59 45.6000000 44.6000000 60 NA 45.6000000 > dum1 <- dum[2:length(myerror),] > dum1 lag(myerror, k = 1) myerror [1,] 10.2333333 22.2333333 [2,] -8.7666667 10.2333333 [3,] -13.7666667 -8.7666667 [4,] -28.7666667 -13.7666667 [5,] -31.7666667 -28.7666667 [6,] 17.2333333 -31.7666667 [7,] 50.2333333 17.2333333 [8,] 30.2333333 50.2333333 [9,] 14.2333333 30.2333333 [10,] -6.7666667 14.2333333 [11,] -10.7666667 -6.7666667 [12,] -3.7666667 -10.7666667 [13,] -10.7666667 -3.7666667 [14,] -22.7666667 -10.7666667 [15,] -27.7666667 -22.7666667 [16,] -34.7666667 -27.7666667 [17,] -39.7666667 -34.7666667 [18,] 13.2333333 -39.7666667 [19,] 39.2333333 13.2333333 [20,] 42.2333333 39.2333333 [21,] 32.2333333 42.2333333 [22,] 0.2333333 32.2333333 [23,] 0.2333333 0.2333333 [24,] 5.2333333 0.2333333 [25,] 4.2333333 5.2333333 [26,] -0.7666667 4.2333333 [27,] -9.7666667 -0.7666667 [28,] -15.7666667 -9.7666667 [29,] -14.7666667 -15.7666667 [30,] -32.4000000 -14.7666667 [31,] -24.4000000 -32.4000000 [32,] -26.4000000 -24.4000000 [33,] -30.4000000 -26.4000000 [34,] -40.4000000 -30.4000000 [35,] -37.4000000 -40.4000000 [36,] -30.4000000 -37.4000000 [37,] -32.4000000 -30.4000000 [38,] -39.4000000 -32.4000000 [39,] -40.4000000 -39.4000000 [40,] -48.4000000 -40.4000000 [41,] -42.4000000 -48.4000000 [42,] 19.6000000 -42.4000000 [43,] 30.6000000 19.6000000 [44,] 28.6000000 30.6000000 [45,] 15.6000000 28.6000000 [46,] -2.4000000 15.6000000 [47,] 5.6000000 -2.4000000 [48,] 12.6000000 5.6000000 [49,] 11.6000000 12.6000000 [50,] 5.6000000 11.6000000 [51,] -5.4000000 5.6000000 [52,] -12.4000000 -5.4000000 [53,] -6.4000000 -12.4000000 [54,] 44.6000000 -6.4000000 [55,] 61.6000000 44.6000000 [56,] 63.6000000 61.6000000 [57,] 61.6000000 63.6000000 [58,] 44.6000000 61.6000000 [59,] 45.6000000 44.6000000 > z <- as.data.frame(dum1) > z lag(myerror, k = 1) myerror 1 10.2333333 22.2333333 2 -8.7666667 10.2333333 3 -13.7666667 -8.7666667 4 -28.7666667 -13.7666667 5 -31.7666667 -28.7666667 6 17.2333333 -31.7666667 7 50.2333333 17.2333333 8 30.2333333 50.2333333 9 14.2333333 30.2333333 10 -6.7666667 14.2333333 11 -10.7666667 -6.7666667 12 -3.7666667 -10.7666667 13 -10.7666667 -3.7666667 14 -22.7666667 -10.7666667 15 -27.7666667 -22.7666667 16 -34.7666667 -27.7666667 17 -39.7666667 -34.7666667 18 13.2333333 -39.7666667 19 39.2333333 13.2333333 20 42.2333333 39.2333333 21 32.2333333 42.2333333 22 0.2333333 32.2333333 23 0.2333333 0.2333333 24 5.2333333 0.2333333 25 4.2333333 5.2333333 26 -0.7666667 4.2333333 27 -9.7666667 -0.7666667 28 -15.7666667 -9.7666667 29 -14.7666667 -15.7666667 30 -32.4000000 -14.7666667 31 -24.4000000 -32.4000000 32 -26.4000000 -24.4000000 33 -30.4000000 -26.4000000 34 -40.4000000 -30.4000000 35 -37.4000000 -40.4000000 36 -30.4000000 -37.4000000 37 -32.4000000 -30.4000000 38 -39.4000000 -32.4000000 39 -40.4000000 -39.4000000 40 -48.4000000 -40.4000000 41 -42.4000000 -48.4000000 42 19.6000000 -42.4000000 43 30.6000000 19.6000000 44 28.6000000 30.6000000 45 15.6000000 28.6000000 46 -2.4000000 15.6000000 47 5.6000000 -2.4000000 48 12.6000000 5.6000000 49 11.6000000 12.6000000 50 5.6000000 11.6000000 51 -5.4000000 5.6000000 52 -12.4000000 -5.4000000 53 -6.4000000 -12.4000000 54 44.6000000 -6.4000000 55 61.6000000 44.6000000 56 63.6000000 61.6000000 57 61.6000000 63.6000000 58 44.6000000 61.6000000 59 45.6000000 44.6000000 > 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/7gxil1229082490.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/8w6pt1229082490.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/9u0w31229082490.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/105yaq1229082490.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/11hiyo1229082490.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/12je7h1229082490.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/13pols1229082490.tab") > > system("convert tmp/1gi551229082490.ps tmp/1gi551229082490.png") > system("convert tmp/2mw171229082490.ps tmp/2mw171229082490.png") > system("convert tmp/3qg701229082490.ps tmp/3qg701229082490.png") > system("convert tmp/4euhr1229082490.ps tmp/4euhr1229082490.png") > system("convert tmp/5qh0f1229082490.ps tmp/5qh0f1229082490.png") > system("convert tmp/61yz81229082490.ps tmp/61yz81229082490.png") > system("convert tmp/7gxil1229082490.ps tmp/7gxil1229082490.png") > system("convert tmp/8w6pt1229082490.ps tmp/8w6pt1229082490.png") > system("convert tmp/9u0w31229082490.ps tmp/9u0w31229082490.png") > > > proc.time() user system elapsed 1.897 1.394 2.361