R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-pc-linux-gnu (32-bit) 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.60,4.10,0.20,8.60,1.40,2.85,4.25,8.60,2.00,0.00,0.35,2.00,1.10,2.25,3.35,2.00,1.25,0.50,0.80,1.25,1.10,0.70,1.80,1.25,0.70,0.00,0.00,0.70,1.10,1.00,2.10,0.70,8.45,0.10,2.20,8.45,0.20,0.25,0.45,8.45,0.30,0.00,0.00,0.30,0.20,0.10,0.30,0.30,0.00,0.00,0.10,0.00,0.90,0.45,1.35,0.00,5.80,0.10,0.35,5.80,1.90,0.45,2.35,5.80,0.30,0.20,2.10,0.30,3.70,0.20,3.90,0.30,1.40,0.10,0.20,4.10,0.00,0.20,0.20,4.10,1.10,0.10,0.20,0.00,0.10,0.40,0.50,0.00,1.10,0.25,0.20,0.50,0.20,0.20,0.40,0.50,1.10,0.10,0.10,0.10,0.10,0.10,0.20,0.10,0.20,0.45,0.95,0.10,0.10,0.95,1.05,0.10,0.20,0.45,0.30,0.00,0.00,0.30,0.30,0.00,9.00,0.20,0.85,0.20,0.10,0.85,0.95,0.20,1.90,0.20,0.85,0.35,0.35,0.85,1.20,0.35,3.70,0.40,0.20,0.80,2.10,0.20,2.30,0.80,2.85,0,0.90,0.00,0.20,0.90,1.10,0.00,2.25,0,0.30,2.20,0.20,0.30,0.50,2.20,0.70,0,0,0,0,0,0,0,1.00,0,0,0,0,0,0,0),dim=c(8,22),dimnames=list(c('mOne','mTwo','mThree','k','p','s','orth','nsurg'),1:22)) > y <- array(NA,dim=c(8,22),dimnames=list(c('mOne','mTwo','mThree','k','p','s','orth','nsurg'),1:22)) > 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' > 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) > library(lmtest) Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from 'package:base': as.Date, as.Date.numeric > n25 <- 25 #minimum number of obs. for Goldfeld-Quandt test > 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 mOne mTwo mThree k p s orth nsurg 1 8.60 4.10 0.20 8.60 1.40 2.85 4.25 8.60 2 2.00 0.00 0.35 2.00 1.10 2.25 3.35 2.00 3 1.25 0.50 0.80 1.25 1.10 0.70 1.80 1.25 4 0.70 0.00 0.00 0.70 1.10 1.00 2.10 0.70 5 8.45 0.10 2.20 8.45 0.20 0.25 0.45 8.45 6 0.30 0.00 0.00 0.30 0.20 0.10 0.30 0.30 7 0.00 0.00 0.10 0.00 0.90 0.45 1.35 0.00 8 5.80 0.10 0.35 5.80 1.90 0.45 2.35 5.80 9 0.30 0.20 2.10 0.30 3.70 0.20 3.90 0.30 10 1.40 0.10 0.20 4.10 0.00 0.20 0.20 4.10 11 1.10 0.10 0.20 0.00 0.10 0.40 0.50 0.00 12 1.10 0.25 0.20 0.50 0.20 0.20 0.40 0.50 13 1.10 0.10 0.10 0.10 0.10 0.10 0.20 0.10 14 0.20 0.45 0.95 0.10 0.10 0.95 1.05 0.10 15 0.20 0.45 0.30 0.00 0.00 0.30 0.30 0.00 16 9.00 0.20 0.85 0.20 0.10 0.85 0.95 0.20 17 1.90 0.20 0.85 0.35 0.35 0.85 1.20 0.35 18 3.70 0.40 0.20 0.80 2.10 0.20 2.30 0.80 19 2.85 0.00 0.90 0.00 0.20 0.90 1.10 0.00 20 2.25 0.00 0.30 2.20 0.20 0.30 0.50 2.20 21 0.70 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 > k <- length(x[1,]) > df <- as.data.frame(x) > (mylm <- lm(df)) Call: lm(formula = df) Coefficients: (Intercept) mTwo mThree k p s 0.7893 0.3578 1.0325 0.6082 -0.4069 0.5043 orth nsurg NA NA > (mysum <- summary(mylm)) Call: lm(formula = df) Residuals: Min 1Q Median 3Q Max -2.2305 -0.9790 -0.2830 0.1522 6.7519 Coefficients: (2 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 0.7893 0.7662 1.030 0.3182 mTwo 0.3578 0.8669 0.413 0.6853 mThree 1.0325 0.8739 1.182 0.2547 k 0.6082 0.2267 2.682 0.0163 * p -0.4069 0.5563 -0.731 0.4751 s 0.5043 0.9205 0.548 0.5914 orth NA NA NA NA nsurg NA NA NA NA --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.161 on 16 degrees of freedom Multiple R-squared: 0.565, Adjusted R-squared: 0.429 F-statistic: 4.156 on 5 and 16 DF, p-value: 0.01305 > if (n > n25) { + kp3 <- k + 3 + nmkm3 <- n - k - 3 + gqarr <- array(NA, dim=c(nmkm3-kp3+1,3)) + numgqtests <- 0 + numsignificant1 <- 0 + numsignificant5 <- 0 + numsignificant10 <- 0 + for (mypoint in kp3:nmkm3) { + j <- 0 + numgqtests <- numgqtests + 1 + for (myalt in c('greater', 'two.sided', 'less')) { + j <- j + 1 + gqarr[mypoint-kp3+1,j] <- gqtest(mylm, point=mypoint, alternative=myalt)$p.value + } + if (gqarr[mypoint-kp3+1,2] < 0.01) numsignificant1 <- numsignificant1 + 1 + if (gqarr[mypoint-kp3+1,2] < 0.05) numsignificant5 <- numsignificant5 + 1 + if (gqarr[mypoint-kp3+1,2] < 0.10) numsignificant10 <- numsignificant10 + 1 + } + gqarr + } > postscript(file="/var/wessaorg/rcomp/tmp/1381l1357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/2ll211357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/3ssrx1357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/46zrz1357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/571ko1357361038.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(mysum$resid, main='Residual Normal Q-Q Plot') > qqline(mysum$resid) > grid() > dev.off() null device 1 > (myerror <- as.ts(mysum$resid)) Time Series: Start = 1 End = 22 Frequency = 1 1 2 3 4 5 6 0.03902813 -1.05420045 -1.20994567 -0.57178792 0.16919324 -0.64086060 7 8 9 10 11 12 -0.75331834 1.63202206 -1.50702776 -2.22616921 -0.09265509 -0.30888568 13 14 15 16 17 18 0.10106007 -2.23045658 -1.21139710 6.75185063 -0.33765714 2.82808703 19 20 21 22 0.75890068 -0.25708419 -0.08934805 0.21065195 > postscript(file="/var/wessaorg/rcomp/tmp/66dkc1357361038.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > dum <- cbind(lag(myerror,k=1),myerror) > dum Time Series: Start = 0 End = 22 Frequency = 1 lag(myerror, k = 1) myerror 0 0.03902813 NA 1 -1.05420045 0.03902813 2 -1.20994567 -1.05420045 3 -0.57178792 -1.20994567 4 0.16919324 -0.57178792 5 -0.64086060 0.16919324 6 -0.75331834 -0.64086060 7 1.63202206 -0.75331834 8 -1.50702776 1.63202206 9 -2.22616921 -1.50702776 10 -0.09265509 -2.22616921 11 -0.30888568 -0.09265509 12 0.10106007 -0.30888568 13 -2.23045658 0.10106007 14 -1.21139710 -2.23045658 15 6.75185063 -1.21139710 16 -0.33765714 6.75185063 17 2.82808703 -0.33765714 18 0.75890068 2.82808703 19 -0.25708419 0.75890068 20 -0.08934805 -0.25708419 21 0.21065195 -0.08934805 22 NA 0.21065195 > dum1 <- dum[2:length(myerror),] > dum1 lag(myerror, k = 1) myerror [1,] -1.05420045 0.03902813 [2,] -1.20994567 -1.05420045 [3,] -0.57178792 -1.20994567 [4,] 0.16919324 -0.57178792 [5,] -0.64086060 0.16919324 [6,] -0.75331834 -0.64086060 [7,] 1.63202206 -0.75331834 [8,] -1.50702776 1.63202206 [9,] -2.22616921 -1.50702776 [10,] -0.09265509 -2.22616921 [11,] -0.30888568 -0.09265509 [12,] 0.10106007 -0.30888568 [13,] -2.23045658 0.10106007 [14,] -1.21139710 -2.23045658 [15,] 6.75185063 -1.21139710 [16,] -0.33765714 6.75185063 [17,] 2.82808703 -0.33765714 [18,] 0.75890068 2.82808703 [19,] -0.25708419 0.75890068 [20,] -0.08934805 -0.25708419 [21,] 0.21065195 -0.08934805 > z <- as.data.frame(dum1) > z lag(myerror, k = 1) myerror 1 -1.05420045 0.03902813 2 -1.20994567 -1.05420045 3 -0.57178792 -1.20994567 4 0.16919324 -0.57178792 5 -0.64086060 0.16919324 6 -0.75331834 -0.64086060 7 1.63202206 -0.75331834 8 -1.50702776 1.63202206 9 -2.22616921 -1.50702776 10 -0.09265509 -2.22616921 11 -0.30888568 -0.09265509 12 0.10106007 -0.30888568 13 -2.23045658 0.10106007 14 -1.21139710 -2.23045658 15 6.75185063 -1.21139710 16 -0.33765714 6.75185063 17 2.82808703 -0.33765714 18 0.75890068 2.82808703 19 -0.25708419 0.75890068 20 -0.08934805 -0.25708419 21 0.21065195 -0.08934805 > 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/wessaorg/rcomp/tmp/7nt5d1357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/8ezfr1357361038.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/9g6ve1357361038.ps",horizontal=F,onefile=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') Warning messages: 1: In sqrt(crit * p * (1 - hh)/hh) : NaNs produced 2: In sqrt(crit * p * (1 - hh)/hh) : NaNs produced > par(opar) > dev.off() null device 1 > if (n > n25) { + postscript(file="/var/wessaorg/rcomp/tmp/10rvtr1357361038.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) + plot(kp3:nmkm3,gqarr[,2], main='Goldfeld-Quandt test',ylab='2-sided p-value',xlab='breakpoint') + grid() + dev.off() + } > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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='') + } + } Error: subscript out of bounds Execution halted