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(2,1,5,2,10,0,0,6,2,0,5,3,9,0,0,7,2,0,5,3,9,0,0,6,2,0,5,3,9,0,1,7,2,1,5,2,9,0,0,7,2,1,5,3,9,0,1,7,2,0,5,3,9,0,0,7),dim=c(8,7),dimnames=list(c('Weeks','UseLimit','T40','T20','Used','CorrectAnalysis','Useful','Outcome'),1:7)) > y <- array(NA,dim=c(8,7),dimnames=list(c('Weeks','UseLimit','T40','T20','Used','CorrectAnalysis','Useful','Outcome'),1:7)) > 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 = '8' > 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 Outcome Weeks UseLimit T40 T20 Used CorrectAnalysis Useful 1 6 2 1 5 2 10 0 0 2 7 2 0 5 3 9 0 0 3 6 2 0 5 3 9 0 0 4 7 2 0 5 3 9 0 1 5 7 2 1 5 2 9 0 0 6 7 2 1 5 3 9 0 1 7 7 2 0 5 3 9 0 0 > k <- length(x[1,]) > df <- as.data.frame(x) > (mylm <- lm(df)) Call: lm(formula = df) Coefficients: (Intercept) Weeks UseLimit T40 1.667e+01 NA -1.074e-16 NA T20 Used CorrectAnalysis Useful -3.333e-01 -1.000e+00 NA 3.333e-01 > (mysum <- summary(mylm)) Call: lm(formula = df) Residuals: 1 2 3 4 5 6 7 4.582e-17 3.333e-01 -6.667e-01 -1.106e-16 -9.053e-17 6.213e-17 3.333e-01 Coefficients: (3 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 1.667e+01 9.025e+00 1.847 0.206 Weeks NA NA NA NA UseLimit -1.074e-16 8.165e-01 0.000 1.000 T40 NA NA NA NA T20 -3.333e-01 1.054e+00 -0.316 0.782 Used -1.000e+00 8.165e-01 -1.225 0.345 CorrectAnalysis NA NA NA NA Useful 3.333e-01 6.667e-01 0.500 0.667 Residual standard error: 0.5774 on 2 degrees of freedom Multiple R-squared: 0.5333, Adjusted R-squared: -0.4 F-statistic: 0.5714 on 4 and 2 DF, p-value: 0.7156 > 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/fisher/rcomp/tmp/1jxhd1356133219.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/fisher/rcomp/tmp/2dlt41356133219.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/fisher/rcomp/tmp/3ccga1356133219.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/fisher/rcomp/tmp/4hbur1356133219.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/fisher/rcomp/tmp/5r8na1356133219.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 = 7 Frequency = 1 1 2 3 4 5 4.582109e-17 3.333333e-01 -6.666667e-01 -1.106377e-16 -9.052572e-17 6 7 6.212995e-17 3.333333e-01 > postscript(file="/var/fisher/rcomp/tmp/6sg9k1356133219.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 = 7 Frequency = 1 lag(myerror, k = 1) myerror 0 4.582109e-17 NA 1 3.333333e-01 4.582109e-17 2 -6.666667e-01 3.333333e-01 3 -1.106377e-16 -6.666667e-01 4 -9.052572e-17 -1.106377e-16 5 6.212995e-17 -9.052572e-17 6 3.333333e-01 6.212995e-17 7 NA 3.333333e-01 > dum1 <- dum[2:length(myerror),] > dum1 lag(myerror, k = 1) myerror [1,] 3.333333e-01 4.582109e-17 [2,] -6.666667e-01 3.333333e-01 [3,] -1.106377e-16 -6.666667e-01 [4,] -9.052572e-17 -1.106377e-16 [5,] 6.212995e-17 -9.052572e-17 [6,] 3.333333e-01 6.212995e-17 > z <- as.data.frame(dum1) > z lag(myerror, k = 1) myerror 1 3.333333e-01 4.582109e-17 2 -6.666667e-01 3.333333e-01 3 -1.106377e-16 -6.666667e-01 4 -9.052572e-17 -1.106377e-16 5 6.212995e-17 -9.052572e-17 6 3.333333e-01 6.212995e-17 > 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/fisher/rcomp/tmp/7ari71356133219.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/fisher/rcomp/tmp/8wcdm1356133219.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/fisher/rcomp/tmp/9kbxi1356133219.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: Not plotting observations with leverage one: 1, 4, 5, 6 2: Not plotting observations with leverage one: 1, 4, 5, 6 > par(opar) > dev.off() null device 1 > if (n > n25) { + postscript(file="/var/fisher/rcomp/tmp/104z5p1356133219.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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