R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(2755.61,2770.81,2755.03,2715.66,2703.37,2679.26,2665.97,2692.41,2707.09,2712.67,2689.37,2692.02,2701.50,2680.17,2683.23,2675.65,2666.24,2652.11,2646.32,2565.48,2522.96,2557.71,2567.18,2627.42,2610.20,2630.60,2655.77,2656.77,2658.67,2669.31,2684.35,2662.17,2689.84,2707.42,2698.21,2711.69,2712.26,2722.23,2721.23,2694.84,2719.18,2695.00,2711.46,2675.30,2692.45,2725.31,2727.67,2748.22,2750.77,2766.56,2768.34,2768.25,2749.77,2701.27,2693.74,2702.27,2694.68,2732.67,2719.31) > x <- c(56.89,57.95,57.75,57.50,57.52,56.70,56.20,56.00,56.05,56.70,56.44,56.45,56.32,56.56,57.15,57.40,59.74,59.65,59.13,57.57,56.26,56.71,56.69,56.98,56.18,56.50,57.65,57.82,57.61,57.87,57.41,57.45,57.38,57.84,58.54,58.47,59.29,59.25,59.11,59.03,59.86,59.34,59.97,58.50,59.09,59.61,58.99,59.54,59.79,59.26,58.46,58.44,58.08,56.80,56.79,57.12,57.26,57.05,57.24) > 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 -140.991 -21.757 7.909 28.670 81.063 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1717.727 312.107 5.504 9.2e-07 *** x 16.819 5.398 3.116 0.00287 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 48.28 on 57 degrees of freedom Multiple R-squared: 0.1455, Adjusted R-squared: 0.1306 F-statistic: 9.709 on 1 and 57 DF, p-value: 0.00287 > postscript(file="/var/wessaorg/rcomp/tmp/1wy5j1321310924.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/wessaorg/rcomp/tmp/2or8z1321310924.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.232e-13 -1.105e-13 -2.446e-14 7.814e-14 7.728e-13 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.718e+03 1.023e-12 1.68e+15 <2e-16 *** x 1.682e+01 1.769e-14 9.51e+14 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.582e-13 on 57 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 9.044e+29 on 1 and 57 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/wessaorg/rcomp/tmp/3ci241321310924.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 -140.991 -21.757 7.909 28.670 81.063 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.317e-14 3.121e+02 0 1 x 1.699e-16 5.398e+00 0 1 Residual standard error: 48.28 on 57 degrees of freedom Multiple R-squared: 5.164e-33, Adjusted R-squared: -0.01754 F-statistic: 2.943e-31 on 1 and 57 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/wessaorg/rcomp/tmp/4h73g1321310924.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 -30.473 -17.102 -4.068 20.151 36.297 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.690e+03 2.594e+00 1037 <2e-16 *** m$residuals 7.770e-16 5.467e-02 0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 19.92 on 57 degrees of freedom Multiple R-squared: 3.656e-28, Adjusted R-squared: -0.01754 F-statistic: 2.084e-26 on 1 and 57 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/wessaorg/rcomp/tmp/5a4x91321310924.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 -60.905 -10.336 1.379 11.341 44.954 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.79959 2.58078 -0.31 0.758 Residuals 0.89223 0.05424 16.45 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 19.65 on 56 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.8286, Adjusted R-squared: 0.8255 F-statistic: 270.6 on 1 and 56 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6la9h1321310924.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/wessaorg/rcomp/tmp/71c941321310924.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/wessaorg/rcomp/tmp/85fg21321310924.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/wessaorg/rcomp/tmp/9eml21321310924.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/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,'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/wessaorg/rcomp/tmp/10dt1q1321310925.tab") > > try(system("convert tmp/1wy5j1321310924.ps tmp/1wy5j1321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/2or8z1321310924.ps tmp/2or8z1321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/3ci241321310924.ps tmp/3ci241321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/4h73g1321310924.ps tmp/4h73g1321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/5a4x91321310924.ps tmp/5a4x91321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/6la9h1321310924.ps tmp/6la9h1321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/71c941321310924.ps tmp/71c941321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/85fg21321310924.ps tmp/85fg21321310924.png",intern=TRUE)) character(0) > try(system("convert tmp/9eml21321310924.ps tmp/9eml21321310924.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.549 0.445 3.023