R version 2.7.0 (2008-04-22) Copyright (C) 2008 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(103,102.4,102,101.8,101.6,101.4,101.3,101.4,101.7,102.4,103.1,103.8,104.4,105,105.7,106.4,107.1,107.9,108.8,109.6,110.3,110.8,111.2,111.7,112.3,112.8,113.1,113.1,113.1,113.2,113.1,112.8,112.5,112.3,112.5,112.9,113.5,114.1,114.6,114.9,115.4,115.7,116.1,116.5,117.1,117.5,117.7,117.7,117.7,117.6,117.5,117.6,117.9,118.2,118.5,118.7,118.8,118.9,119,119) > x <- c(101.1,100.7,100,100,100.8,101.9,102.7,103.1,103.5,103.9,104.4,105.2,106,107,108.2,109,109.1,109.3,110.1,110.7,110.8,110.7,110.9,111.3,111.6,111.8,112.1,112.3,112.5,113,113.6,114.4,114.9,115.2,116,117,118,119.4,121.1,123.1,125,126.3,127.4,129,131,133.3,135.9,138.4,140.3,141.7,143.1,144.5,146,147.7,149,149.7,150.2,150.5,150.7,150.9) > 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 -4.65201 -2.41009 0.06572 2.38057 4.14965 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 72.85003 2.70386 26.94 <2e-16 *** x 0.32204 0.02234 14.42 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.801 on 58 degrees of freedom Multiple R-squared: 0.7818, Adjusted R-squared: 0.778 F-statistic: 207.8 on 1 and 58 DF, p-value: < 2.2e-16 > postscript(file="/var/www/html/rcomp/tmp/17tb61229957432.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/html/rcomp/tmp/26r6q1229957432.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 -7.057e-15 -3.540e-15 6.266e-16 3.096e-15 8.468e-15 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 7.285e+01 4.122e-15 1.767e+16 <2e-16 *** x 3.220e-01 3.406e-17 9.456e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 4.269e-15 on 58 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 8.942e+31 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/www/html/rcomp/tmp/3epmx1229957432.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 -4.65201 -2.41009 0.06572 2.38057 4.14965 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 9.428e-16 2.704e+00 3.49e-16 1 x -6.324e-18 2.234e-02 -2.83e-16 1 Residual standard error: 2.801 on 58 degrees of freedom Multiple R-squared: 2.422e-33, Adjusted R-squared: -0.01724 F-statistic: 1.405e-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/www/html/rcomp/tmp/4k0ag1229957432.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 -6.425 -3.591 -2.142 3.744 9.967 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.115e+02 6.844e-01 162.9 <2e-16 *** m$residuals -3.944e-16 2.485e-01 -1.59e-15 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 5.301 on 58 degrees of freedom Multiple R-squared: 1.177e-29, Adjusted R-squared: -0.01724 F-statistic: 6.827e-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/www/html/rcomp/tmp/509x21229957432.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 -0.79435 -0.26851 -0.02462 0.30771 0.72726 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.000233 0.051259 -0.005 0.996 Residuals 0.990317 0.018583 53.291 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.3937 on 57 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.9803, Adjusted R-squared: 0.98 F-statistic: 2840 on 1 and 57 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/6zxu81229957432.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/html/rcomp/tmp/7he881229957432.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/html/rcomp/tmp/8yvfn1229957432.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/html/rcomp/tmp/9bl111229957432.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/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/html/rcomp/tmp/10kor81229957432.tab") > > system("convert tmp/17tb61229957432.ps tmp/17tb61229957432.png") > system("convert tmp/26r6q1229957432.ps tmp/26r6q1229957432.png") > system("convert tmp/3epmx1229957432.ps tmp/3epmx1229957432.png") > system("convert tmp/4k0ag1229957432.ps tmp/4k0ag1229957432.png") > system("convert tmp/509x21229957432.ps tmp/509x21229957432.png") > system("convert tmp/6zxu81229957432.ps tmp/6zxu81229957432.png") > system("convert tmp/7he881229957432.ps tmp/7he881229957432.png") > system("convert tmp/8yvfn1229957432.ps tmp/8yvfn1229957432.png") > system("convert tmp/9bl111229957432.ps tmp/9bl111229957432.png") > > > proc.time() user system elapsed 3.836 2.414 4.156