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. > y <- c(4290.89,4443.91,4502.64,4356.98,4591.27,4696.96,4621.4,4562.84,4202.52,4296.49,4435.23,4105.18,4116.68,3844.49,3720.98,3674.4,3857.62,3801.06,3504.37,3032.6,3047.03,2962.34,2197.82,2014.45,1862.83,1905.41,1810.99,1670.07,1864.44,2052.02,2029.6,2070.83,2293.41,2443.27,2513.17,2466.92,2502.66,2539.91,2482.6,2626.15,2656.32,2446.66,2467.38,2462.32,2504.58,2579.39,2649.24,2636.87,2613.94,2634.01,2711.94,2646.43,2717.79,2701.54,2572.98,2488.92,2204.91,2123.99,2149.1,2036.71) > x <- c(-1,1,-1,2,2,1,-1,-2,-2,-1,-8,-4,-6,-3,-3,-7,-9,-11,-13,-11,-9,-17,-22,-25,-20,-24,-24,-22,-19,-18,-17,-11,-11,-12,-10,-15,-15,-15,-13,-8,-13,-9,-7,-4,-4,-2,0,-2,-3,1,-2,-1,1,-3,-4,-9,-9,-7,-14,-12) > 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 -1082.51 -660.01 -52.03 686.11 1432.55 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3637.20 137.47 26.457 < 2e-16 *** x 79.32 12.29 6.455 2.4e-08 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 698 on 58 degrees of freedom Multiple R-squared: 0.4181, Adjusted R-squared: 0.408 F-statistic: 41.67 on 1 and 58 DF, p-value: 2.395e-08 > postscript(file="/var/fisher/rcomp/tmp/1777e1355651602.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/fisher/rcomp/tmp/276qx1355651602.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 -2.394e-13 -1.376e-13 -2.590e-15 1.218e-13 4.534e-13 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.637e+03 2.818e-14 1.291e+17 <2e-16 *** x 7.932e+01 2.519e-15 3.149e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.431e-13 on 58 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 9.915e+32 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/fisher/rcomp/tmp/3eivb1355651602.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 -1082.51 -660.01 -52.03 686.11 1432.55 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 6.726e-14 1.375e+02 0 1 x 3.985e-15 1.229e+01 0 1 Residual standard error: 698 on 58 degrees of freedom Multiple R-squared: 2.547e-33, Adjusted R-squared: -0.01724 F-statistic: 1.477e-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/fisher/rcomp/tmp/4i7q81355651603.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 -1312.67 -360.88 35.69 511.58 828.84 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.967e+03 7.638e+01 38.85 <2e-16 *** m$residuals 2.985e-17 1.113e-01 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 591.6 on 58 degrees of freedom Multiple R-squared: 1.019e-30, Adjusted R-squared: -0.01724 F-statistic: 5.909e-29 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/fisher/rcomp/tmp/5w1uz1355651603.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 -520.7 -237.6 -18.8 220.8 788.1 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -22.34954 38.68342 -0.578 0.566 Residuals 0.90275 0.05632 16.029 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 297.1 on 57 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.8184, Adjusted R-squared: 0.8152 F-statistic: 256.9 on 1 and 57 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/fisher/rcomp/tmp/6ikt31355651603.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/fisher/rcomp/tmp/7sug51355651603.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/fisher/rcomp/tmp/80gao1355651603.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/fisher/rcomp/tmp/9y2wm1355651603.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/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,'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/fisher/rcomp/tmp/105snf1355651603.tab") > > try(system("convert tmp/1777e1355651602.ps tmp/1777e1355651602.png",intern=TRUE)) character(0) > try(system("convert tmp/276qx1355651602.ps tmp/276qx1355651602.png",intern=TRUE)) character(0) > try(system("convert tmp/3eivb1355651602.ps tmp/3eivb1355651602.png",intern=TRUE)) character(0) > try(system("convert tmp/4i7q81355651603.ps tmp/4i7q81355651603.png",intern=TRUE)) character(0) > try(system("convert tmp/5w1uz1355651603.ps tmp/5w1uz1355651603.png",intern=TRUE)) character(0) > try(system("convert tmp/6ikt31355651603.ps tmp/6ikt31355651603.png",intern=TRUE)) character(0) > try(system("convert tmp/7sug51355651603.ps tmp/7sug51355651603.png",intern=TRUE)) character(0) > try(system("convert tmp/80gao1355651603.ps tmp/80gao1355651603.png",intern=TRUE)) character(0) > try(system("convert tmp/9y2wm1355651603.ps tmp/9y2wm1355651603.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.983 1.317 6.334