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(39,144,45,138,47,145,65,162,46,142,67,170,42,124,67,158,56,154,64,162,56,150,59,140,34,110,42,128,48,130,45,135,17,114,20,116,19,124,36,136,50,142,39,120,21,120,44,160,53,158,63,144,29,130,25,125,69,175),dim=c(2,29),dimnames=list(c('leeftijd','bloeddruk'),1:29)) > y <- array(NA,dim=c(2,29),dimnames=list(c('leeftijd','bloeddruk'),1:29)) > 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 = '2' > par3 <- 'No Linear Trend' > par2 <- 'Do not include Seasonal Dummies' > par1 <- '2' > #'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 bloeddruk leeftijd 1 144 39 2 138 45 3 145 47 4 162 65 5 142 46 6 170 67 7 124 42 8 158 67 9 154 56 10 162 64 11 150 56 12 140 59 13 110 34 14 128 42 15 130 48 16 135 45 17 114 17 18 116 20 19 124 19 20 136 36 21 142 50 22 120 39 23 120 21 24 160 44 25 158 53 26 144 63 27 130 29 28 125 25 29 175 69 > k <- length(x[1,]) > df <- as.data.frame(x) > (mylm <- lm(df)) Call: lm(formula = df) Coefficients: (Intercept) leeftijd 97.0771 0.9493 > (mysum <- summary(mylm)) Call: lm(formula = df) Residuals: Min 1Q Median 3Q Max -19.354 -4.797 1.254 4.747 21.153 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 97.0771 5.5276 17.562 2.67e-16 *** leeftijd 0.9493 0.1161 8.174 8.88e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 9.563 on 27 degrees of freedom Multiple R-squared: 0.7122, Adjusted R-squared: 0.7015 F-statistic: 66.81 on 1 and 27 DF, p-value: 8.876e-09 > 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 + } [,1] [,2] [,3] [1,] 0.11674439 0.23348879 0.8832556 [2,] 0.08650142 0.17300284 0.9134986 [3,] 0.29454601 0.58909201 0.7054540 [4,] 0.23414384 0.46828768 0.7658562 [5,] 0.14590754 0.29181509 0.8540925 [6,] 0.08613568 0.17227136 0.9138643 [7,] 0.04686843 0.09373686 0.9531316 [8,] 0.11155866 0.22311733 0.8884413 [9,] 0.27502612 0.55005223 0.7249739 [10,] 0.23027095 0.46054189 0.7697291 [11,] 0.27987734 0.55975468 0.7201227 [12,] 0.21533548 0.43067096 0.7846645 [13,] 0.20364391 0.40728781 0.7963561 [14,] 0.15122776 0.30245551 0.8487722 [15,] 0.14539272 0.29078543 0.8546073 [16,] 0.09567053 0.19134105 0.9043295 [17,] 0.05854586 0.11709171 0.9414541 [18,] 0.15240363 0.30480727 0.8475964 [19,] 0.09484989 0.18969978 0.9051501 [20,] 0.24763566 0.49527132 0.7523643 > postscript(file="/var/fisher/rcomp/tmp/1d48o1354573546.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/2en2d1354573546.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/3kvsu1354573546.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/4q0011354573546.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/5s16t1354573546.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 = 29 Frequency = 1 1 2 3 4 5 6 9.89933678 -1.79659845 3.30475648 3.21695081 1.25407902 9.31830573 7 8 9 10 11 12 -12.94863083 -2.68169427 3.76085364 4.16627334 -0.23914636 -13.08711397 13 14 15 16 17 18 -19.35405054 -8.94863083 -12.64456606 -4.79659845 0.78443260 -0.06353501 19 20 21 22 23 24 8.88578752 4.74730439 -2.54321113 -14.10066322 2.98714245 21.15272409 25 26 27 28 29 10.60882126 -12.88440412 5.39256215 4.18985230 12.41966066 > postscript(file="/var/fisher/rcomp/tmp/6hktp1354573546.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 = 29 Frequency = 1 lag(myerror, k = 1) myerror 0 9.89933678 NA 1 -1.79659845 9.89933678 2 3.30475648 -1.79659845 3 3.21695081 3.30475648 4 1.25407902 3.21695081 5 9.31830573 1.25407902 6 -12.94863083 9.31830573 7 -2.68169427 -12.94863083 8 3.76085364 -2.68169427 9 4.16627334 3.76085364 10 -0.23914636 4.16627334 11 -13.08711397 -0.23914636 12 -19.35405054 -13.08711397 13 -8.94863083 -19.35405054 14 -12.64456606 -8.94863083 15 -4.79659845 -12.64456606 16 0.78443260 -4.79659845 17 -0.06353501 0.78443260 18 8.88578752 -0.06353501 19 4.74730439 8.88578752 20 -2.54321113 4.74730439 21 -14.10066322 -2.54321113 22 2.98714245 -14.10066322 23 21.15272409 2.98714245 24 10.60882126 21.15272409 25 -12.88440412 10.60882126 26 5.39256215 -12.88440412 27 4.18985230 5.39256215 28 12.41966066 4.18985230 29 NA 12.41966066 > dum1 <- dum[2:length(myerror),] > dum1 lag(myerror, k = 1) myerror [1,] -1.79659845 9.89933678 [2,] 3.30475648 -1.79659845 [3,] 3.21695081 3.30475648 [4,] 1.25407902 3.21695081 [5,] 9.31830573 1.25407902 [6,] -12.94863083 9.31830573 [7,] -2.68169427 -12.94863083 [8,] 3.76085364 -2.68169427 [9,] 4.16627334 3.76085364 [10,] -0.23914636 4.16627334 [11,] -13.08711397 -0.23914636 [12,] -19.35405054 -13.08711397 [13,] -8.94863083 -19.35405054 [14,] -12.64456606 -8.94863083 [15,] -4.79659845 -12.64456606 [16,] 0.78443260 -4.79659845 [17,] -0.06353501 0.78443260 [18,] 8.88578752 -0.06353501 [19,] 4.74730439 8.88578752 [20,] -2.54321113 4.74730439 [21,] -14.10066322 -2.54321113 [22,] 2.98714245 -14.10066322 [23,] 21.15272409 2.98714245 [24,] 10.60882126 21.15272409 [25,] -12.88440412 10.60882126 [26,] 5.39256215 -12.88440412 [27,] 4.18985230 5.39256215 [28,] 12.41966066 4.18985230 > z <- as.data.frame(dum1) > z lag(myerror, k = 1) myerror 1 -1.79659845 9.89933678 2 3.30475648 -1.79659845 3 3.21695081 3.30475648 4 1.25407902 3.21695081 5 9.31830573 1.25407902 6 -12.94863083 9.31830573 7 -2.68169427 -12.94863083 8 3.76085364 -2.68169427 9 4.16627334 3.76085364 10 -0.23914636 4.16627334 11 -13.08711397 -0.23914636 12 -19.35405054 -13.08711397 13 -8.94863083 -19.35405054 14 -12.64456606 -8.94863083 15 -4.79659845 -12.64456606 16 0.78443260 -4.79659845 17 -0.06353501 0.78443260 18 8.88578752 -0.06353501 19 4.74730439 8.88578752 20 -2.54321113 4.74730439 21 -14.10066322 -2.54321113 22 2.98714245 -14.10066322 23 21.15272409 2.98714245 24 10.60882126 21.15272409 25 -12.88440412 10.60882126 26 5.39256215 -12.88440412 27 4.18985230 5.39256215 28 12.41966066 4.18985230 > 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/7dd3i1354573546.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/8l65f1354573546.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/9u1081354573546.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') > par(opar) > dev.off() null device 1 > if (n > n25) { + postscript(file="/var/fisher/rcomp/tmp/10xrm81354573546.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() + } null device 1 > > #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='') + } + } > 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/fisher/rcomp/tmp/115pdc1354573546.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/fisher/rcomp/tmp/12udk61354573546.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/fisher/rcomp/tmp/1339qe1354573546.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/fisher/rcomp/tmp/14xqzc1354573546.tab") > if (n > n25) { + a<-table.start() + a<-table.row.start(a) + a<-table.element(a,'Goldfeld-Quandt test for Heteroskedasticity',4,TRUE) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'p-values',header=TRUE) + a<-table.element(a,'Alternative Hypothesis',3,header=TRUE) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'breakpoint index',header=TRUE) + a<-table.element(a,'greater',header=TRUE) + a<-table.element(a,'2-sided',header=TRUE) + a<-table.element(a,'less',header=TRUE) + a<-table.row.end(a) + for (mypoint in kp3:nmkm3) { + a<-table.row.start(a) + a<-table.element(a,mypoint,header=TRUE) + a<-table.element(a,gqarr[mypoint-kp3+1,1]) + a<-table.element(a,gqarr[mypoint-kp3+1,2]) + a<-table.element(a,gqarr[mypoint-kp3+1,3]) + a<-table.row.end(a) + } + a<-table.end(a) + table.save(a,file="/var/fisher/rcomp/tmp/15fofk1354573546.tab") + a<-table.start() + a<-table.row.start(a) + a<-table.element(a,'Meta Analysis of Goldfeld-Quandt test for Heteroskedasticity',4,TRUE) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'Description',header=TRUE) + a<-table.element(a,'# significant tests',header=TRUE) + a<-table.element(a,'% significant tests',header=TRUE) + a<-table.element(a,'OK/NOK',header=TRUE) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'1% type I error level',header=TRUE) + a<-table.element(a,numsignificant1) + a<-table.element(a,numsignificant1/numgqtests) + if (numsignificant1/numgqtests < 0.01) dum <- 'OK' else dum <- 'NOK' + a<-table.element(a,dum) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'5% type I error level',header=TRUE) + a<-table.element(a,numsignificant5) + a<-table.element(a,numsignificant5/numgqtests) + if (numsignificant5/numgqtests < 0.05) dum <- 'OK' else dum <- 'NOK' + a<-table.element(a,dum) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'10% type I error level',header=TRUE) + a<-table.element(a,numsignificant10) + a<-table.element(a,numsignificant10/numgqtests) + if (numsignificant10/numgqtests < 0.1) dum <- 'OK' else dum <- 'NOK' + a<-table.element(a,dum) + a<-table.row.end(a) + a<-table.end(a) + table.save(a,file="/var/fisher/rcomp/tmp/164j5m1354573546.tab") + } > > try(system("convert tmp/1d48o1354573546.ps tmp/1d48o1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/2en2d1354573546.ps tmp/2en2d1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/3kvsu1354573546.ps tmp/3kvsu1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/4q0011354573546.ps tmp/4q0011354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/5s16t1354573546.ps tmp/5s16t1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/6hktp1354573546.ps tmp/6hktp1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/7dd3i1354573546.ps tmp/7dd3i1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/8l65f1354573546.ps tmp/8l65f1354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/9u1081354573546.ps tmp/9u1081354573546.png",intern=TRUE)) character(0) > try(system("convert tmp/10xrm81354573546.ps tmp/10xrm81354573546.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.716 1.435 7.163