R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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. > y <- c(29975,29124,29704,29564,30550,29812,30611,30577,30637,30944,30852,31216,31113,32073,31447,32293,31807,31778,31707,32135,31929,32923,33181,33435,34721,35179,35605,35931,35093,35053,35092,35295,35981,35606,35815,36144,36391,35642,36896,36399,38385,38226,38609,38227,38254,38047,38437,37963,38231,38283,38839,38833,39431,40091,40289,39433,38677,38107,38485,38464) > x <- c(330123,334728,338414,338582,339904,341396,343496,344591,346099,347258,348503,348628,349913,352797,354539,353032,355576,355603,357889,359310,361253,364253,364872,364201,368830,368755,370117,372895,374215,375539,380550,382839,386678,389265,393978,397923,394691,394410,398981,399827,403635,402425,406939,404544,406309,407884,407151,414154,408459,407609,408503,409068,412860,415113,418053,415780,413562,414521,413948,413106) > par1 = '0' > par1 <- as.numeric(par1) > library(lattice) > z <- as.data.frame(cbind(x,y)) > m <- lm(y~x) > summary(m) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -1096.75 -416.39 -98.51 385.84 1785.77 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.023e+04 1.190e+03 -8.591 6.31e-12 *** x 1.190e-01 3.131e-03 38.005 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 663.6 on 58 degrees of freedom Multiple R-squared: 0.9614, Adjusted R-squared: 0.9607 F-statistic: 1444 on 1 and 58 DF, p-value: < 2.2e-16 > postscript(file="/var/www/rcomp/tmp/1yhaa1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(z,main='Scatterplot, lowess, and regression line') > lines(lowess(z),col='red') > abline(m) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/29qar1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > m2 <- lm(m$fitted.values ~ x) > summary(m2) Call: lm(formula = m$fitted.values ~ x) Residuals: Min 1Q Median 3Q Max -4.141e-12 -1.625e-12 -6.999e-13 6.921e-13 2.038e-11 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.023e+04 5.998e-12 -1.705e+15 <2e-16 *** x 1.190e-01 1.578e-17 7.542e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.344e-12 on 58 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 5.688e+31 on 1 and 58 DF, p-value: < 2.2e-16 > z2 <- as.data.frame(cbind(x,m$fitted.values)) > names(z2) <- list('x','Fitted') > plot(z2,main='Scatterplot, lowess, and regression line') > lines(lowess(z2),col='red') > abline(m2) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/3mfg81321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > m3 <- lm(m$residuals ~ x) > summary(m3) Call: lm(formula = m$residuals ~ x) Residuals: Min 1Q Median 3Q Max -1096.75 -416.39 -98.51 385.84 1785.77 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -8.797e-14 1.190e+03 0 1 x 1.750e-19 3.131e-03 0 1 Residual standard error: 663.6 on 58 degrees of freedom Multiple R-squared: 2.035e-33, Adjusted R-squared: -0.01724 F-statistic: 1.18e-31 on 1 and 58 DF, p-value: 1 > z3 <- as.data.frame(cbind(x,m$residuals)) > names(z3) <- list('x','Residuals') > plot(z3,main='Scatterplot, lowess, and regression line') > lines(lowess(z3),col='red') > abline(m3) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/45fp21321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > m4 <- lm(m$fitted.values ~ m$residuals) > summary(m4) Call: lm(formula = m$fitted.values ~ m$residuals) Residuals: Min 1Q Median 3Q Max -5832.5 -2971.8 -129.7 3315.1 4631.4 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.489e+04 4.275e+02 81.62 <2e-16 *** m$residuals 1.733e-15 6.553e-01 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3311 on 58 degrees of freedom Multiple R-squared: 2.247e-30, Adjusted R-squared: -0.01724 F-statistic: 1.303e-28 on 1 and 58 DF, p-value: 1 > z4 <- as.data.frame(cbind(m$residuals,m$fitted.values)) > names(z4) <- list('Residuals','Fitted') > plot(z4,main='Scatterplot, lowess, and regression line') > lines(lowess(z4),col='red') > abline(m4) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/5chzv1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > myr <- as.ts(m$residuals) > z5 <- as.data.frame(cbind(lag(myr,1),myr)) > names(z5) <- list('Lagged Residuals','Residuals') > plot(z5,main='Lag plot') > m5 <- lm(z5) > summary(m5) Call: lm(formula = z5) Residuals: Min 1Q Median 3Q Max -1203.38 -313.26 60.68 321.44 1173.47 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -20.3231 67.8757 -0.299 0.766 Residuals 0.6027 0.1036 5.817 2.86e-07 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 521.3 on 57 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.3725, Adjusted R-squared: 0.3615 F-statistic: 33.84 on 1 and 57 DF, p-value: 2.861e-07 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/6ik7n1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > hist(m$residuals,main='Residual Histogram',xlab='Residuals') > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/7jjua1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > if (par1 > 0) + { + densityplot(~m$residuals,col='black',main=paste('Density Plot bw = ',par1),bw=par1) + } else { + densityplot(~m$residuals,col='black',main='Density Plot') + } > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/893981321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > acf(m$residuals,main='Residual Autocorrelation Function') > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/9kjit1321373721.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(x) > qqline(x) > grid() > dev.off() null device 1 > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Simple Linear Regression',5,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Statistics',1,TRUE) > a<-table.element(a,'Estimate',1,TRUE) > a<-table.element(a,'S.D.',1,TRUE) > a<-table.element(a,'T-STAT (H0: coeff=0)',1,TRUE) > a<-table.element(a,'P-value (two-sided)',1,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'constant term',header=TRUE) > a<-table.element(a,m$coefficients[[1]]) > sd <- sqrt(vcov(m)[1,1]) > a<-table.element(a,sd) > tstat <- m$coefficients[[1]]/sd > a<-table.element(a,tstat) > pval <- 2*(1-pt(abs(tstat),length(x)-2)) > a<-table.element(a,pval) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'slope',header=TRUE) > a<-table.element(a,m$coefficients[[2]]) > sd <- sqrt(vcov(m)[2,2]) > a<-table.element(a,sd) > tstat <- m$coefficients[[2]]/sd > a<-table.element(a,tstat) > pval <- 2*(1-pt(abs(tstat),length(x)-2)) > a<-table.element(a,pval) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/10atlw1321373722.tab") > > try(system("convert tmp/1yhaa1321373721.ps tmp/1yhaa1321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/29qar1321373721.ps tmp/29qar1321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/3mfg81321373721.ps tmp/3mfg81321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/45fp21321373721.ps tmp/45fp21321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/5chzv1321373721.ps tmp/5chzv1321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/6ik7n1321373721.ps tmp/6ik7n1321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/7jjua1321373721.ps tmp/7jjua1321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/893981321373721.ps tmp/893981321373721.png",intern=TRUE)) character(0) > try(system("convert tmp/9kjit1321373721.ps tmp/9kjit1321373721.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.490 0.330 3.804