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(25695,19967,14338,34117,9713,10024,39981,1271,30207,18035,21609,19836,9028,21750,10038,30276,34972,19954,28113,18830,37144,17916,16186,19195,29124,29813,20270,26105,9155,18113,40546,10096,32338,2871,36592,4914,30190,18153,12558,32894,24138,16628,26369,14171,8500,11940,7935,19456,21347,24095,26204,2694,20366,3597,5296,29463,35838,42590,38665,19442,25515,51318,11807,24130,34053,22641,18898,24539,21664,21577,16643,3007,18798,24648,20286,23999,26813,14718,16963,16673,14646,31772,9648,23096,7905,4527,37432,21082,30437,36288,12369,23774,8108,15049,36021,30391,30910,40656,35070,47250,36236,29601,10443,7409,18213,40856,36471,26077,24797,6816,25527,22139,238,24459,3913,9895,25902,338,12937,3988,23370,24015,3870,14648,1888,16768,33400,23770,34762,18793,48186,20140,8728,19060,26880,415,38902,17375,31360,15051,16785,15886,28548,2805,34012,19215,34177,32990,0,2065,0,0,0,0,17428,19912,0,0,556,2089,2658,1801,0,16541) > x <- c(124252 + ,98956 + ,98073 + ,106816 + ,41449 + ,76173 + ,177551 + ,22807 + ,126938 + ,61680 + ,72117 + ,79738 + ,57793 + ,91677 + ,64631 + ,106385 + ,161961 + ,112669 + ,114029 + ,124550 + ,105416 + ,72875 + ,81964 + ,104880 + ,76302 + ,96740 + ,93071 + ,78912 + ,35224 + ,90694 + ,125369 + ,80849 + ,104434 + ,65702 + ,108179 + ,63583 + ,95066 + ,62486 + ,31081 + ,94584 + ,87408 + ,68966 + ,88766 + ,57139 + ,90586 + ,109249 + ,33032 + ,96056 + ,146648 + ,80613 + ,87026 + ,5950 + ,131106 + ,32551 + ,31701 + ,91072 + ,159803 + ,143950 + ,112368 + ,82124 + ,144068 + ,162627 + ,55062 + ,95329 + ,105612 + ,62853 + ,125976 + ,79146 + ,108461 + ,99971 + ,77826 + ,22618 + ,84892 + ,92059 + ,77993 + ,104155 + ,109840 + ,238712 + ,67486 + ,68007 + ,48194 + ,134796 + ,38692 + ,93587 + ,56622 + ,15986 + ,113402 + ,97967 + ,74844 + ,136051 + ,50548 + ,112215 + ,59591 + ,59938 + ,137639 + ,143372 + ,138599 + ,174110 + ,135062 + ,175681 + ,130307 + ,139141 + ,44244 + ,43750 + ,48029 + ,95216 + ,92288 + ,94588 + ,197426 + ,151244 + ,139206 + ,106271 + ,1168 + ,71764 + ,25162 + ,45635 + ,101817 + ,855 + ,100174 + ,14116 + ,85008 + ,124254 + ,105793 + ,117129 + ,8773 + ,94747 + ,107549 + ,97392 + ,126893 + ,118850 + ,234853 + ,74783 + ,66089 + ,95684 + ,139537 + ,144253 + ,153824 + ,63995 + ,84891 + ,61263 + ,106221 + ,113587 + ,113864 + ,37238 + ,119906 + ,135096 + ,151611 + ,144645 + ,0 + ,6023 + ,0 + ,0 + ,0 + ,0 + ,77457 + ,62464 + ,0 + ,0 + ,1644 + ,6179 + ,3926 + ,42087 + ,0 + ,87656) > 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 -34587 -3133 -436 4125 19544 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.737e+03 1.283e+03 2.134 0.0344 * x 1.951e-01 1.296e-02 15.056 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 7850 on 162 degrees of freedom Multiple R-squared: 0.5832, Adjusted R-squared: 0.5806 F-statistic: 226.7 on 1 and 162 DF, p-value: < 2.2e-16 > postscript(file="/var/wessaorg/rcomp/tmp/1rtsw1323284653.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/2w3sb1323284653.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 -5.019e-12 -8.148e-13 -5.630e-14 8.485e-13 1.091e-11 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.737e+03 2.660e-13 1.029e+16 <2e-16 *** x 1.951e-01 2.687e-18 7.261e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.628e-12 on 162 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 5.273e+33 on 1 and 162 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/3et241323284653.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 -34587 -3133 -436 4125 19544 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.597e-14 1.283e+03 0 1 x 3.855e-19 1.296e-02 0 1 Residual standard error: 7850 on 162 degrees of freedom Multiple R-squared: 1.045e-34, Adjusted R-squared: -0.006173 F-statistic: 1.692e-32 on 1 and 162 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/4sgkw1323284653.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 -16963.8 -5287.9 861.8 5208.6 29604.9 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.970e+04 7.252e+02 27.17 <2e-16 *** m$residuals 1.438e-17 9.294e-02 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 9287 on 162 degrees of freedom Multiple R-squared: 1.942e-31, Adjusted R-squared: -0.006173 F-statistic: 3.146e-29 on 1 and 162 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/5kz0y1323284654.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 -34754 -3091 -534 4055 19169 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 6.63860 615.62747 0.011 0.991 Residuals 0.06041 0.07870 0.768 0.444 Residual standard error: 7860 on 161 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.003645, Adjusted R-squared: -0.002543 F-statistic: 0.5891 on 1 and 161 DF, p-value: 0.4439 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6qytn1323284654.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/7tgf41323284654.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/8oyqg1323284654.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/9sicp1323284654.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/10m4001323284654.tab") > > try(system("convert tmp/1rtsw1323284653.ps tmp/1rtsw1323284653.png",intern=TRUE)) character(0) > try(system("convert tmp/2w3sb1323284653.ps tmp/2w3sb1323284653.png",intern=TRUE)) character(0) > try(system("convert tmp/3et241323284653.ps tmp/3et241323284653.png",intern=TRUE)) character(0) > try(system("convert tmp/4sgkw1323284653.ps tmp/4sgkw1323284653.png",intern=TRUE)) character(0) > try(system("convert tmp/5kz0y1323284654.ps tmp/5kz0y1323284654.png",intern=TRUE)) character(0) > try(system("convert tmp/6qytn1323284654.ps tmp/6qytn1323284654.png",intern=TRUE)) character(0) > try(system("convert tmp/7tgf41323284654.ps tmp/7tgf41323284654.png",intern=TRUE)) character(0) > try(system("convert tmp/8oyqg1323284654.ps tmp/8oyqg1323284654.png",intern=TRUE)) character(0) > try(system("convert tmp/9sicp1323284654.ps tmp/9sicp1323284654.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.583 0.442 3.255