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(115,112,109,101,107,99,120,133,128,135,160,144,168,112,170,110,150,144,124,156,160,133,177,186,190,133,154,179,166,177,160,150,177,159,147,161,168,120,170,180,123,167,150,123,144,154,178,181,100,132,120,146,160,120,158,148,190,138,189,170,156,177,165,181,147,163,169,173,133,156,179,126,163,156,136,183,189,170,167,189,178) > x <- c(20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100) > 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 -55.61 -16.36 0.35 17.94 46.00 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 122.6987 6.8534 17.903 < 2e-16 *** x 0.4840 0.1064 4.548 1.93e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 22.4 on 79 degrees of freedom Multiple R-squared: 0.2075, Adjusted R-squared: 0.1975 F-statistic: 20.68 on 1 and 79 DF, p-value: 1.929e-05 > postscript(file="/var/wessaorg/rcomp/tmp/1mlqu1321384188.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/2e2km1321384188.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 -1.538e-14 -6.650e-15 4.153e-16 7.481e-15 1.486e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.227e+02 2.580e-15 4.756e+16 <2e-16 *** x 4.840e-01 4.006e-17 1.208e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.431e-15 on 79 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 1.46e+32 on 1 and 79 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/3rie01321384188.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 -55.61 -16.36 0.35 17.94 46.00 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.315e-16 6.853e+00 0 1 x 6.612e-18 1.064e-01 0 1 Residual standard error: 22.4 on 79 degrees of freedom Multiple R-squared: 1.869e-34, Adjusted R-squared: -0.01266 F-statistic: 1.476e-32 on 1 and 79 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/49p3c1321384188.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 -19.361 -9.681 0.000 9.681 19.361 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.517e+02 1.273e+00 119.2 <2e-16 *** m$residuals -3.102e-18 5.757e-02 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 11.46 on 79 degrees of freedom Multiple R-squared: 2.803e-30, Adjusted R-squared: -0.01266 F-statistic: 2.214e-28 on 1 and 79 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/5mwio1321384188.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 -59.054 -17.419 0.888 16.781 40.498 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.2280 2.4906 0.092 0.927 Residuals 0.1242 0.1120 1.109 0.271 Residual standard error: 22.28 on 78 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.01553, Adjusted R-squared: 0.002908 F-statistic: 1.23 on 1 and 78 DF, p-value: 0.2707 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6g4s01321384188.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/7knze1321384188.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/89puv1321384188.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/9akpp1321384188.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/10nace1321384188.tab") > > try(system("convert tmp/1mlqu1321384188.ps tmp/1mlqu1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/2e2km1321384188.ps tmp/2e2km1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/3rie01321384188.ps tmp/3rie01321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/49p3c1321384188.ps tmp/49p3c1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/5mwio1321384188.ps tmp/5mwio1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/6g4s01321384188.ps tmp/6g4s01321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/7knze1321384188.ps tmp/7knze1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/89puv1321384188.ps tmp/89puv1321384188.png",intern=TRUE)) character(0) > try(system("convert tmp/9akpp1321384188.ps tmp/9akpp1321384188.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.580 0.416 3.007