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(2293,2309,2299,2349,2374,2440,2485,2685,2803,2947,3066,3212,3116,3190,3193,3393,3316,3221,3246,3182,3150,3249,3192,3265,3142,3282,3326,3291,3343,3376,3307,3391,3389,3327,3258,3278,3269,3192,3413,3193,3122,3276,3122,3026,3015,3079,3035,3011,3045,3098,3018,3037,3057,3048,3014,2860,3014,3003,3015,2931) > x <- c(2591,2664,2723,2811,2809,2914,2952,3182,3152,3491,3683,3735,3808,3801,3815,3933,3827,3903,3870,3853,3849,3917,4050,4130,4111,4074,3993,4276,4322,4506,4402,4340,4279,4192,4200,3905,3878,3804,3912,3796,3875,3822,3739,3772,3740,3733,3714,3652,3591,3641,3487,3357,3312,3311,3240,3322,3431,3301,3318,3284) > 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 -197.014 -89.665 2.675 72.975 210.952 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 861.80870 124.30533 6.933 3.8e-09 *** x 0.59915 0.03363 17.814 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 117.6 on 58 degrees of freedom Multiple R-squared: 0.8455, Adjusted R-squared: 0.8428 F-statistic: 317.3 on 1 and 58 DF, p-value: < 2.2e-16 > postscript(file="/var/wessaorg/rcomp/tmp/1v8ki1321202760.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/22b8c1321202760.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 -8.821e-13 -1.376e-13 8.610e-15 1.598e-13 2.818e-13 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 8.618e+02 2.029e-13 4.248e+15 <2e-16 *** x 5.991e-01 5.489e-17 1.092e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.919e-13 on 58 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 1.192e+32 on 1 and 58 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/3f02u1321202760.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 -197.014 -89.665 2.675 72.975 210.952 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -6.843e-15 1.243e+02 0 1 x 1.993e-18 3.363e-02 0 1 Residual standard error: 117.6 on 58 degrees of freedom Multiple R-squared: 5.225e-33, Adjusted R-squared: -0.01724 F-statistic: 3.031e-31 on 1 and 58 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/4567n1321202760.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 -645.43 -208.05 69.35 146.79 501.94 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.060e+03 3.551e+01 86.17 <2e-16 *** m$residuals 3.346e-16 3.071e-01 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 275 on 58 degrees of freedom Multiple R-squared: 6.551e-30, Adjusted R-squared: -0.01724 F-statistic: 3.8e-28 on 1 and 58 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/5va011321202760.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 -185.327 -67.386 -6.378 56.438 169.026 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.23723 11.08846 0.292 0.771 Residuals 0.68703 0.09573 7.177 1.61e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 85.16 on 57 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.4747, Adjusted R-squared: 0.4655 F-statistic: 51.51 on 1 and 57 DF, p-value: 1.615e-09 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6kpnn1321202760.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/7dkid1321202760.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/8bj161321202760.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/9smpu1321202760.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/10xx6c1321202760.tab") > > try(system("convert tmp/1v8ki1321202760.ps tmp/1v8ki1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/22b8c1321202760.ps tmp/22b8c1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/3f02u1321202760.ps tmp/3f02u1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/4567n1321202760.ps tmp/4567n1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/5va011321202760.ps tmp/5va011321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/6kpnn1321202760.ps tmp/6kpnn1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/7dkid1321202760.ps tmp/7dkid1321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/8bj161321202760.ps tmp/8bj161321202760.png",intern=TRUE)) character(0) > try(system("convert tmp/9smpu1321202760.ps tmp/9smpu1321202760.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.545 0.445 3.047