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(57.8,52.5,58.2,61.1,65.7,62.3,63.3,62.6,61.9,63.9,64.2,64.8,55.1,56.2,63.7,62.6,58.4,55.5,66.6,54.7,58.9,51.3,51,48.9,52.6,51.2,59.6,63,61.4,59.3,58.6,63.6,66.9,68.9,64.2,63.1,63.3,60.1,59.2,55.3,56.6,58.9,60.3,60.1,60.8,60.7,61.8,69.5,62.2,60.7,63.4,69.7,64.2,63.8,64.1,63.2,62.2,65.4,61.2,60.8,59.1,55.9) > x <- c(18.4,17.6,19,20.5,24.3,21.2,22.1,21.5,20.8,22.5,23.7,23.8,14.1,16.3,22.2,21.1,19.2,17.3,20.8,22.6,20.2,18.6,17,13.3,19.7,18.6,21.7,24.3,18.9,16.8,18.1,21.7,26.7,23.4,25.3,22.9,24.6,20.5,19.1,17.3,20.1,21.1,21.1,20,21.3,21.1,21.8,22.2,19.4,19.7,23.1,27.4,23.4,24.2,20.9,24.2,20.9,24.2,21.2,18.3,16.6,17.9) > 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 -8.1784 -1.0848 0.1367 1.3131 7.1238 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 34.5068 2.7420 12.585 < 2e-16 *** x 1.2554 0.1308 9.596 9.94e-14 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.892 on 60 degrees of freedom Multiple R-squared: 0.6055, Adjusted R-squared: 0.5989 F-statistic: 92.09 on 1 and 60 DF, p-value: 9.937e-14 > postscript(file="/var/wessaorg/rcomp/tmp/1cuzn1321288112.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/21zzd1321288112.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.030e-14 -1.591e-15 2.086e-16 2.078e-15 7.783e-15 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.451e+01 2.927e-15 1.179e+16 <2e-16 *** x 1.255e+00 1.396e-16 8.990e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.087e-15 on 60 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 8.082e+31 on 1 and 60 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/38q3k1321288112.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 -8.1784 -1.0848 0.1367 1.3131 7.1238 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.584e-16 2.742e+00 0 1 x 3.667e-17 1.308e-01 0 1 Residual standard error: 2.892 on 60 degrees of freedom Multiple R-squared: 4.385e-33, Adjusted R-squared: -0.01667 F-statistic: 2.631e-31 on 1 and 60 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/4etcf1321288112.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 -9.3789 -2.3174 0.2875 2.2647 8.3220 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 6.058e+01 4.550e-01 133.2 <2e-16 *** m$residuals -1.194e-16 1.599e-01 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.582 on 60 degrees of freedom Multiple R-squared: 2.229e-30, Adjusted R-squared: -0.01667 F-statistic: 1.338e-28 on 1 and 60 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/5bq6n1321288112.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 -9.6974 -1.0998 0.3989 1.0114 7.1504 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.007695 0.361009 -0.021 0.9831 Residuals 0.255253 0.126030 2.025 0.0474 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.82 on 59 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.06501, Adjusted R-squared: 0.04916 F-statistic: 4.102 on 1 and 59 DF, p-value: 0.04736 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6j0gt1321288112.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/7cls01321288112.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/8cn2p1321288112.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/9h1dj1321288112.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/101cw91321288112.tab") > > try(system("convert tmp/1cuzn1321288112.ps tmp/1cuzn1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/21zzd1321288112.ps tmp/21zzd1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/38q3k1321288112.ps tmp/38q3k1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/4etcf1321288112.ps tmp/4etcf1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/5bq6n1321288112.ps tmp/5bq6n1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/6j0gt1321288112.ps tmp/6j0gt1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/7cls01321288112.ps tmp/7cls01321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/8cn2p1321288112.ps tmp/8cn2p1321288112.png",intern=TRUE)) character(0) > try(system("convert tmp/9h1dj1321288112.ps tmp/9h1dj1321288112.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.506 0.464 2.979