R version 2.12.1 (2010-12-16) Copyright (C) 2010 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(41,39,30,31,34,35,39,34,36,37,38,36,38,39,33,32,36,38,39,32,32,31,39,37,39,41,36,33,33,34,31,27,37,34,34,32,29,36,29,35,37,34,38,35,38,37,38,33,36,38,32,32,32,34,32,37,39,29,37,35,30,38,34,31,34,35,36,30,39,35,38,31,34,38,34,39,37,34,28,37,33,37,35,37,32,33,38,33,29,33,31,36,35,32,29,39,37,35,37,32,38,37,36,32,33,40,38,41,36,43,30,31,32,32,37,37,33,34,33,38,33,31,38,37,33,31,39,44,33,35,32,28,40,27,37,32,28,34,30,35,31,32,30,30,31,40,32,36,32,35,38,42,34,35,35,33,36,32,33,34,32,34) > x <- c(14,18,11,12,16,18,14,14,15,15,17,19,10,16,18,14,14,17,14,16,18,11,14,12,17,9,16,14,15,11,16,13,17,15,14,16,9,15,17,13,15,16,16,12,12,11,15,15,17,13,16,14,11,12,12,15,16,15,12,12,8,13,11,14,15,10,11,12,15,15,14,16,15,15,13,12,17,13,15,13,15,16,15,16,15,14,15,14,13,7,17,13,15,14,13,16,12,14,17,15,17,12,16,11,15,9,16,15,10,10,15,11,13,14,18,16,14,14,14,14,12,14,15,15,15,13,17,17,19,15,13,9,15,15,15,16,11,14,11,15,13,15,16,14,15,16,16,11,12,9,16,13,16,12,9,13,13,14,19,13,12,13) > 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 -7.8219 -2.6158 -0.0857 2.7221 9.2083 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 31.731 1.608 19.739 <2e-16 *** x 0.206 0.113 1.824 0.0701 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.351 on 160 degrees of freedom Multiple R-squared: 0.02036, Adjusted R-squared: 0.01424 F-statistic: 3.326 on 1 and 160 DF, p-value: 0.07007 > postscript(file="/var/www/rcomp/tmp/14wy41321372543.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/www/rcomp/tmp/2frl51321372543.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 -4.481e-15 -2.228e-15 -5.253e-16 1.237e-15 3.075e-15 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.173e+01 9.843e-16 3.224e+16 <2e-16 *** x 2.060e-01 6.918e-17 2.978e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.052e-15 on 160 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 8.87e+30 on 1 and 160 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/www/rcomp/tmp/3ddgg1321372543.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 -7.8219 -2.6158 -0.0857 2.7221 9.2083 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.129e-16 1.608e+00 0 1 x 5.768e-18 1.130e-01 0 1 Residual standard error: 3.351 on 160 degrees of freedom Multiple R-squared: 8.08e-35, Adjusted R-squared: -0.00625 F-statistic: 1.293e-32 on 1 and 160 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/www/rcomp/tmp/411kk1321372543.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 -1.44983 -0.21366 -0.00763 0.40443 1.02251 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.462e+01 3.796e-02 912.2 <2e-16 *** m$residuals 5.381e-17 1.140e-02 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.4831 on 160 degrees of freedom Multiple R-squared: 3.907e-28, Adjusted R-squared: -0.00625 F-statistic: 6.251e-26 on 1 and 160 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/www/rcomp/tmp/5rvy81321372543.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 -7.9401 -2.5265 -0.0675 2.7022 9.1807 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.03973 0.26176 -0.152 0.880 Residuals 0.03050 0.07836 0.389 0.698 Residual standard error: 3.321 on 159 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.0009519, Adjusted R-squared: -0.005331 F-statistic: 0.1515 on 1 and 159 DF, p-value: 0.6976 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/6a8yf1321372543.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/www/rcomp/tmp/7fc811321372543.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/www/rcomp/tmp/88hjd1321372543.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/www/rcomp/tmp/9eihu1321372543.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/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/www/rcomp/tmp/10a3zn1321372543.tab") > > try(system("convert tmp/14wy41321372543.ps tmp/14wy41321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/2frl51321372543.ps tmp/2frl51321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/3ddgg1321372543.ps tmp/3ddgg1321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/411kk1321372543.ps tmp/411kk1321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/5rvy81321372543.ps tmp/5rvy81321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/6a8yf1321372543.ps tmp/6a8yf1321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/7fc811321372543.ps tmp/7fc811321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/88hjd1321372543.ps tmp/88hjd1321372543.png",intern=TRUE)) character(0) > try(system("convert tmp/9eihu1321372543.ps tmp/9eihu1321372543.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.384 0.532 4.941