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(108.4,117,103.8,100.8,110.6,104.0,112.6,107.3,98.9,109.8,104.9,102.2,123.9,124.9,112.7,121.9,100.6,104.3,120.4,107.5,102.9,125.6,107.5,108.8,128.4,121.1,119.5,128.7,108.7,105.5,119.8,111.3,110.6,120.1,97.5,107.7,127.3,117.2,119.8,116.2,111.0,112.4,130.6,109.1,118.8,123.9,101.6,112.8,128.0,129.6,125.8,119.5,115.7,113.6,129.7,112.0,116.8,127.0,112.9,113.3,121.7) > x <- c(99.8,96.8,87.0,96.3,107.1,115.2,106.1,89.5,91.3,97.6,100.7,104.6,94.7,101.8,102.5,105.3,110.3,109.8,117.3,118.8,131.3,125.9,133.1,147.0,145.8,164.4,149.8,137.7,151.7,156.8,180.0,180.4,170.4,191.6,199.5,218.2,217.5,205.0,194.0,199.3,219.3,211.1,215.2,240.2,242.2,240.7,255.4,253.0,218.2,203.7,205.6,215.6,188.5,202.9,214.0,230.3,230.0,241.0,259.6,247.8,270.3) > 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 -18.6574 -6.1391 -0.9374 6.1629 15.7441 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 105.82246 3.46255 30.562 <2e-16 *** x 0.05180 0.01954 2.651 0.0103 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.536 on 59 degrees of freedom Multiple R-squared: 0.1064, Adjusted R-squared: 0.0913 F-statistic: 7.028 on 1 and 59 DF, p-value: 0.01028 > postscript(file="/var/wessaorg/rcomp/tmp/1ka0i1356004410.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/20u711356004410.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 -9.229e-14 -2.155e-15 2.519e-15 4.415e-15 1.030e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.058e+02 5.263e-15 2.011e+16 <2e-16 *** x 5.180e-02 2.970e-17 1.744e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.298e-14 on 59 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 3.042e+30 on 1 and 59 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/3z58i1356004410.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 -18.6574 -6.1391 -0.9374 6.1629 15.7441 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.095e-16 3.463e+00 0 1 x -6.204e-19 1.954e-02 0 1 Residual standard error: 8.536 on 59 degrees of freedom Multiple R-squared: 0, Adjusted R-squared: -0.01695 F-statistic: 0 on 1 and 59 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/4a5nb1356004410.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 -4.2034 -3.0222 0.1171 2.4587 5.2924 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.145e+02 3.772e-01 303.6 <2e-16 *** m$residuals 1.144e-17 4.493e-02 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.946 on 59 degrees of freedom Multiple R-squared: 3.943e-31, Adjusted R-squared: -0.01695 F-statistic: 2.326e-29 on 1 and 59 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/5xcax1356004410.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > myr <- as.ts(m$residuals) > m5 <- lm(myr ~ lag(myr,1)) > summary(m5) Call: lm(formula = myr ~ lag(myr, 1)) Residuals: Min 1Q Median 3Q Max -2.202e-15 -1.551e-16 4.140e-17 2.196e-16 9.239e-16 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.000e+00 6.105e-17 0.000e+00 1 lag(myr, 1) 1.000e+00 7.272e-18 1.375e+17 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 4.768e-16 on 59 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 1.891e+34 on 1 and 59 DF, p-value: < 2.2e-16 > z5 <- as.data.frame(cbind(lag(myr,1),myr)) > names(z5) <- list('Lagged Residuals','Residuals') > plot(z5,main='Lag plot') > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6wqw51356004410.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/78xbz1356004410.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > if (par1 > 0) + { + densityplot(~x,col='black',main=paste('Density Plot bw = ',par1),bw=par1) + } else { + densityplot(~x,col='black',main='Density Plot') + } > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/8t65b1356004410.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/9quv51356004410.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(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/10yahz1356004410.tab") > > try(system("convert tmp/1ka0i1356004410.ps tmp/1ka0i1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/20u711356004410.ps tmp/20u711356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/3z58i1356004410.ps tmp/3z58i1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/4a5nb1356004410.ps tmp/4a5nb1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/5xcax1356004410.ps tmp/5xcax1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/6wqw51356004410.ps tmp/6wqw51356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/78xbz1356004410.ps tmp/78xbz1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/8t65b1356004410.ps tmp/8t65b1356004410.png",intern=TRUE)) character(0) > try(system("convert tmp/9quv51356004410.ps tmp/9quv51356004410.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.801 0.833 5.637