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(322.4,321.7,320.5,312.8,309.7,315.6,309.7,304.6,302.5,301.5,298.8,291.3,293.6,294.6,285.9,297.6,301.1,293.8,297.7,292.9,292.1,287.2,288.2,283.8,299.9,292.4,293.3,300.8,293.7,293.1,294.4,292.1,291.9,282.5,277.9,287.5,289.2,285.6,293.2,290.8,283.1,275,287.8,287.8,287.4,284,277.8,277.6,304.9,294,300.9,324,332.9,341.6,333.4,348.2,344.7,344.7,329.3,323.5,323.2,317.4,330.1,329.2,334.9,315.8,315.4,319.6,317.3,313.8,315.8,311.3) > x <- c(65.3,58.96,59.17,62.37,66.28,55.62,55.23,55.85,56.75,50.89,53.88,52.95,55.08,53.61,58.78,61.85,55.91,53.32,46.41,44.57,50,50,53.36,46.23,50.45,49.07,45.85,48.45,49.96,46.53,50.51,47.58,48.05,46.84,47.67,49.16,55.54,55.82,58.22,56.19,57.77,63.19,54.76,55.74,62.54,61.39,69.6,79.23,80,93.68,107.63,100.18,97.3,90.45,80.64,80.58,75.82,85.59,89.35,89.42,104.73,95.32,89.27,90.44,86.97,79.98,81.22,87.35,83.64,82.22,94.4,102.18) > 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 -35.150 -7.112 0.121 7.432 34.554 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 260.11335 6.34238 41.012 < 2e-16 *** x 0.66435 0.09221 7.205 5.28e-10 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 14.04 on 70 degrees of freedom Multiple R-squared: 0.4258, Adjusted R-squared: 0.4176 F-statistic: 51.91 on 1 and 70 DF, p-value: 5.28e-10 > postscript(file="/var/wessaorg/rcomp/tmp/144qc1321548351.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/2j11e1321548351.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.877e-14 -1.407e-14 1.147e-15 1.342e-14 2.535e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.601e+02 7.178e-15 3.624e+16 <2e-16 *** x 6.643e-01 1.044e-16 6.366e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.589e-14 on 70 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 4.053e+31 on 1 and 70 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/3ahif1321548351.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 -35.150 -7.112 0.121 7.432 34.554 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.033e-16 6.342e+00 0 1 x -1.654e-17 9.221e-02 0 1 Residual standard error: 14.04 on 70 degrees of freedom Multiple R-squared: 1.526e-33, Adjusted R-squared: -0.01429 F-statistic: 1.068e-31 on 1 and 70 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/499lf1321548351.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 -14.503 -9.278 -5.249 10.011 27.391 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.042e+02 1.425e+00 213.5 <2e-16 *** m$residuals -5.298e-17 1.029e-01 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 12.09 on 70 degrees of freedom Multiple R-squared: 2.842e-30, Adjusted R-squared: -0.01429 F-statistic: 1.989e-28 on 1 and 70 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/5jvnq1321548351.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 -21.3749 -5.1852 -0.8306 4.2027 21.7528 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.44978 1.03095 -0.436 0.664 Residuals 0.78037 0.07471 10.445 7.51e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.686 on 69 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.6126, Adjusted R-squared: 0.607 F-statistic: 109.1 on 1 and 69 DF, p-value: 7.507e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6avuu1321548351.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/799cg1321548351.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/8boqg1321548351.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/9tgtc1321548351.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/10hurs1321548351.tab") > > try(system("convert tmp/144qc1321548351.ps tmp/144qc1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/2j11e1321548351.ps tmp/2j11e1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/3ahif1321548351.ps tmp/3ahif1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/499lf1321548351.ps tmp/499lf1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/5jvnq1321548351.ps tmp/5jvnq1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/6avuu1321548351.ps tmp/6avuu1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/799cg1321548351.ps tmp/799cg1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/8boqg1321548351.ps tmp/8boqg1321548351.png",intern=TRUE)) character(0) > try(system("convert tmp/9tgtc1321548351.ps tmp/9tgtc1321548351.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.471 0.422 2.899