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(122.0,104.1,102.9,105.1,151.5,155.0,99.2,91.7,144.3,118.9,196.5,96.4,121.8,101.4,102.5,98.1,162.9,102.1,108.7,74.4,72.7,100.6,108.7,126.8,130.9,125.2,93.9,116.5,140.4,77.8,82.7,92.6,91.5,101.7,96.7,118.7,123.1,121.0,129.6,133.9,147.7,28.2,16.9,26.1,27.7,42.6,104.5,151.7,72.6,67.3,113.4,99.9,112.8,121.2,97.9,109.9,135.7,137.1,126.6,121.4) > x <- c(122.0,126.0,127.4,123.5,137.4,153.2,107.4,84.6,98.0,100.2,104.4,93.9,122.0,126.0,127.4,123.5,137.4,153.2,93.8,99.3,95.0,95.6,107.7,106.7,117.4,118.9,118.0,95.2,95.8,107.8,106.7,117.3,119.0,118.3,105.9,116.3,131.9,93.7,99.3,95.0,95.6,107.7,106.8,117.3,118.9,117.9,116.4,123.0,138.7,98.8,108.5,103.9,310.1,420.9,90.8,96.1,86.8,84.0,127.3,135.8) > 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 -89.182 -10.188 -1.936 18.761 90.537 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 100.76902 11.58715 8.697 4.21e-12 *** x 0.04975 0.08904 0.559 0.578 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 33.96 on 58 degrees of freedom Multiple R-squared: 0.005354, Adjusted R-squared: -0.0118 F-statistic: 0.3122 on 1 and 58 DF, p-value: 0.5785 > postscript(file="/var/wessaorg/rcomp/tmp/13l941321390836.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/2oi5l1321390836.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 -1.209e-14 -3.224e-15 -1.684e-15 3.047e-15 2.553e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.008e+02 2.435e-15 4.139e+16 <2e-16 *** x 4.975e-02 1.871e-17 2.659e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 7.137e-15 on 58 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 7.07e+30 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/wessaorg/rcomp/tmp/3gvlu1321390836.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 -89.182 -10.188 -1.936 18.761 90.537 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -4.590e-16 1.159e+01 0 1 x 1.959e-18 8.904e-02 0 1 Residual standard error: 33.96 on 58 degrees of freedom Multiple R-squared: 9.266e-35, Adjusted R-squared: -0.01724 F-statistic: 5.374e-33 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/wessaorg/rcomp/tmp/450yn1321390836.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 -1.8137 -1.0874 -0.4008 0.1514 14.9469 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.068e+02 3.217e-01 331.9 <2e-16 *** m$residuals -9.180e-18 9.633e-03 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.492 on 58 degrees of freedom Multiple R-squared: 1.262e-28, Adjusted R-squared: -0.01724 F-statistic: 7.319e-27 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/wessaorg/rcomp/tmp/5k28k1321390836.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 -96.631 -11.367 1.162 17.479 84.812 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.1518 3.9824 -0.038 0.969720 Residuals 0.4471 0.1184 3.775 0.000384 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 30.59 on 57 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.2, Adjusted R-squared: 0.186 F-statistic: 14.25 on 1 and 57 DF, p-value: 0.0003838 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/61nuh1321390836.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/77qb91321390836.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/8td9x1321390836.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/9yi1n1321390836.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/10179h1321390836.tab") > > try(system("convert tmp/13l941321390836.ps tmp/13l941321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/2oi5l1321390836.ps tmp/2oi5l1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/3gvlu1321390836.ps tmp/3gvlu1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/450yn1321390836.ps tmp/450yn1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/5k28k1321390836.ps tmp/5k28k1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/61nuh1321390836.ps tmp/61nuh1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/77qb91321390836.ps tmp/77qb91321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/8td9x1321390836.ps tmp/8td9x1321390836.png",intern=TRUE)) character(0) > try(system("convert tmp/9yi1n1321390836.ps tmp/9yi1n1321390836.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.612 0.493 3.244