R version 2.11.1 (2010-05-31) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(26,23,25,23,19,29,25,21,22,25,24,18,22,15,22,28,20,12,24,20,21,20,21,23,28,24,24,24,23,23,29,24,18,25,21,26,22,22,22,23,30,23,17,23,23,25,24,24,23,21,24,24,28,16,20,29,27,22,28,16,25,24,28,24,23,30,24,21,25,25,22,23,26,23,25,21,25,24,29,22,27,26,22,24,27,24,24,29,22,21,24,24,23,20,27,26,25,21,21,19,21,21,16,22,29,15,17,15,21,21,19,24,20,17,23,24,14,19,24,13,22,16,19,25,25,23,24,26,26,25,18,21,26,23,23,22,20,13,24,15,14,22,10,24,22,24,19,20,13,20,22,24,29,12,20,21,24,22,20) > x <- c(14,11,6,12,8,10,10,11,16,11,13,12,8,12,11,4,9,8,8,14,15,16,9,14,11,8,9,9,9,9,10,16,11,8,9,16,11,16,12,12,14,9,10,9,10,12,14,14,10,14,16,9,10,6,8,13,10,8,7,15,9,10,12,13,10,11,8,9,13,11,8,9,9,15,9,10,14,12,12,11,14,6,12,8,14,11,10,14,12,10,14,5,11,10,9,10,16,13,9,10,10,7,9,8,14,14,8,9,14,14,8,8,8,7,6,8,6,11,14,11,11,11,14,8,20,11,8,11,10,14,11,9,9,8,10,13,13,12,8,13,14,12,14,15,13,16,9,9,9,8,7,16,11,9,11,9,14,13,16) > par1 = '0' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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 -12.6359 -1.6846 0.6563 2.0589 7.6563 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 21.27261 1.24834 17.041 <2e-16 *** x 0.09738 0.11101 0.877 0.382 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.908 on 157 degrees of freedom Multiple R-squared: 0.004877, Adjusted R-squared: -0.001461 F-statistic: 0.7694 on 1 and 157 DF, p-value: 0.3817 > postscript(file="/var/www/rcomp/tmp/1lsgt1289739589.ps",horizontal=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/2lsgt1289739589.ps",horizontal=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 -2.055e-15 -9.393e-16 6.257e-17 7.186e-16 1.913e-14 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.127e+01 5.750e-16 3.700e+16 <2e-16 *** x 9.738e-02 5.113e-17 1.904e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.8e-15 on 157 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 3.627e+30 on 1 and 157 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/3e2ge1289739589.ps",horizontal=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 -12.6359 -1.6846 0.6563 2.0589 7.6563 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 9.977e-18 1.248e+00 7.99e-18 1 x 1.769e-18 1.110e-01 1.59e-17 1 Residual standard error: 3.908 on 157 degrees of freedom Multiple R-squared: 6.808e-34, Adjusted R-squared: -0.006369 F-statistic: 1.069e-31 on 1 and 157 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/47twh1289739589.ps",horizontal=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 -0.67122 -0.18434 0.01041 0.20516 0.88680 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.233e+01 2.170e-02 1029 <2e-16 *** m$residuals 1.960e-17 5.587e-03 3.51e-15 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.2736 on 157 degrees of freedom Multiple R-squared: 5.908e-29, Adjusted R-squared: -0.006369 F-statistic: 9.276e-27 on 1 and 157 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/5z2e21289739589.ps",horizontal=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 -12.5709 -1.4888 0.5531 2.1344 7.6076 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.02300 0.30974 -0.074 0.941 Residuals 0.09507 0.07965 1.194 0.234 Residual standard error: 3.893 on 156 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.009051, Adjusted R-squared: 0.002699 F-statistic: 1.425 on 1 and 156 DF, p-value: 0.2344 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/6z2e21289739589.ps",horizontal=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/7abd51289739589.ps",horizontal=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/8abd51289739589.ps",horizontal=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/9abd51289739589.ps",horizontal=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/1063bv1289739589.tab") > > try(system("convert tmp/1lsgt1289739589.ps tmp/1lsgt1289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/2lsgt1289739589.ps tmp/2lsgt1289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/3e2ge1289739589.ps tmp/3e2ge1289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/47twh1289739589.ps tmp/47twh1289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/5z2e21289739589.ps tmp/5z2e21289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/6z2e21289739589.ps tmp/6z2e21289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/7abd51289739589.ps tmp/7abd51289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/8abd51289739589.ps tmp/8abd51289739589.png",intern=TRUE)) character(0) > try(system("convert tmp/9abd51289739589.ps tmp/9abd51289739589.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.88 1.20 4.09