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(330,331.6,351.2,389.4,410.9,442.8,462.8,466.9,461.7,439.2,430.3,416.1,402.5,397.3,403.3,395.9,387.8,378.6,377.1,370.4,362,350.3,348.2,344.6,343.5,342.8,347.6,346.6,349.5,342.1,342,342.8,339.3,348.2,333.7,334.7,354,367.7,363.3,358.4,353.1,343.1,344.6,344.4,333.9,331.7,324.3,321.2,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(99.26,94.45,113.44,157.33,147.38,171.89,171.95,132.71,126.02,121.18,115.45,110.48,117.85,117.63,124.65,109.59,111.27,99.78,98.21,99.2,97.97,89.55,87.91,93.34,94.42,93.2,90.29,91.46,89.98,88.35,88.41,82.44,79.89,75.69,75.66,84.5,96.73,87.48,82.39,83.48,79.31,78.16,72.77,72.45,68.46,67.62,68.76,70.07,68.55,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) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = '' > par9 = '' > par8 = '' > par7 = '' > par6 = '' > par5 = '' > par4 = '' > par3 = '' > par2 = '' > 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 -49.944 -12.481 1.961 11.030 66.213 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 218.96672 5.99939 36.50 <2e-16 *** x 1.40073 0.07174 19.52 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 20.83 on 118 degrees of freedom Multiple R-squared: 0.7636, Adjusted R-squared: 0.7616 F-statistic: 381.2 on 1 and 118 DF, p-value: < 2.2e-16 > postscript(file="/var/wessaorg/rcomp/tmp/1p3mu1321541934.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/2q16j1321541934.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 -3.473e-14 -1.428e-14 1.294e-15 1.235e-14 6.936e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.190e+02 5.277e-15 4.15e+16 <2e-16 *** x 1.401e+00 6.310e-17 2.22e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.832e-14 on 118 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 4.928e+32 on 1 and 118 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/322xp1321541934.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 -49.944 -12.481 1.961 11.030 66.213 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.305e-16 5.999e+00 0 1 x 4.337e-18 7.174e-02 0 1 Residual standard error: 20.83 on 118 degrees of freedom Multiple R-squared: 2.216e-33, Adjusted R-squared: -0.008475 F-statistic: 2.615e-31 on 1 and 118 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/4532g1321541934.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 -48.667 -32.877 0.401 19.766 129.758 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.301e+02 3.418e+00 96.56 <2e-16 *** m$residuals -3.943e-17 1.655e-01 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 37.44 on 118 degrees of freedom Multiple R-squared: 4.394e-30, Adjusted R-squared: -0.008475 F-statistic: 5.185e-28 on 1 and 118 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/5021h1321541934.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 -30.759 -6.001 -0.255 5.284 59.612 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.04321 1.07820 -0.04 0.968 Residuals 0.83078 0.05280 15.73 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 11.76 on 117 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.6791, Adjusted R-squared: 0.6763 F-statistic: 247.5 on 1 and 117 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/66yne1321541934.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/72r021321541934.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/85xwv1321541934.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/90ipq1321541934.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/10kwam1321541934.tab") > > try(system("convert tmp/1p3mu1321541934.ps tmp/1p3mu1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/2q16j1321541934.ps tmp/2q16j1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/322xp1321541934.ps tmp/322xp1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/4532g1321541934.ps tmp/4532g1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/5021h1321541934.ps tmp/5021h1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/66yne1321541934.ps tmp/66yne1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/72r021321541934.ps tmp/72r021321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/85xwv1321541934.ps tmp/85xwv1321541934.png",intern=TRUE)) character(0) > try(system("convert tmp/90ipq1321541934.ps tmp/90ipq1321541934.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.524 0.426 2.963