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(127800,127700,128500,129400,128800,128800,131300,131100,131500,132900,133500,133400,134828,136488,135943,138717,139223,139869,140507,140259,139220,144033,144683,147354,148813,152657,155912,155271,161382,162106,164825,162810,163398,164844,165910,165774,164881,164861,165501,164334,162229,162748,163915,160890,159779,161106,160659,160007,158917,159052,159507,159107,159925,161327,159957,156997,159316,159793,161383,161828,162887,164071,163810,166708,168481,169913,169602,170559,170943) > x <- c(138900,136400,133900,130400,133200,132500,130400,132000,131400,133300,129700,129500,134257,133802,134542,132423,135853,135676,137311,139515,138554,139560,136171,137454,142388,143616,140197,148011,152637,152341,159219,161478,163350,166044,160925,163439,165411,160522,159302,151933,156735,156254,158051,157038,154626,153093,147274,150847,157165,157384,152655,154088,156583,156608,159543,162916,167167,172470,167473,164832,174144,177945,180962,179105,185076,183863,189329,191268,190450) > 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 -15262.2 -5194.0 357.4 5694.4 12020.0 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.446e+04 7.478e+03 5.945 1.1e-07 *** x 7.099e-01 4.870e-02 14.578 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 6820 on 67 degrees of freedom Multiple R-squared: 0.7603, Adjusted R-squared: 0.7567 F-statistic: 212.5 on 1 and 67 DF, p-value: < 2.2e-16 > postscript(file="/var/wessaorg/rcomp/tmp/1vdjq1321379289.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/2m7il1321379289.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.670e-11 -5.078e-12 -4.810e-13 8.478e-12 1.476e-11 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.446e+04 1.608e-11 2.765e+15 <2e-16 *** x 7.099e-01 1.047e-16 6.780e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.466e-11 on 67 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 4.597e+31 on 1 and 67 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/3c6r61321379289.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 -15262.2 -5194.0 357.4 5694.4 12020.0 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -2.342e-12 7.478e+03 0 1 x 1.598e-17 4.870e-02 0 1 Residual standard error: 6820 on 67 degrees of freedom Multiple R-squared: 2.399e-33, Adjusted R-squared: -0.01493 F-statistic: 1.607e-31 on 1 and 67 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/4mv861321379289.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 -16429.7 -11531.6 318.3 7291.4 27417.7 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.528e+05 1.462e+03 104.5 <2e-16 *** m$residuals 4.960e-16 2.176e-01 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 12150 on 67 degrees of freedom Multiple R-squared: 3.427e-31, Adjusted R-squared: -0.01493 F-statistic: 2.296e-29 on 1 and 67 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/5ufpm1321379289.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 -5619.8 -1915.1 -362.2 2105.3 6329.7 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 111.88995 345.30512 0.324 0.747 Residuals 0.87841 0.05164 17.011 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2847 on 66 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.8143, Adjusted R-squared: 0.8115 F-statistic: 289.4 on 1 and 66 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6cni11321379289.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/7w9rd1321379289.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/89o841321379289.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/91rvo1321379289.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/10zdab1321379289.tab") > > try(system("convert tmp/1vdjq1321379289.ps tmp/1vdjq1321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/2m7il1321379289.ps tmp/2m7il1321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/3c6r61321379289.ps tmp/3c6r61321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/4mv861321379289.ps tmp/4mv861321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/5ufpm1321379289.ps tmp/5ufpm1321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/6cni11321379289.ps tmp/6cni11321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/7w9rd1321379289.ps tmp/7w9rd1321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/89o841321379289.ps tmp/89o841321379289.png",intern=TRUE)) character(0) > try(system("convert tmp/91rvo1321379289.ps tmp/91rvo1321379289.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.523 0.415 3.141