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(1.324,1.310,1.310,1.310,1.310,1.338,1.338,1.338,1.358,1.358,1.358,1.358,1.351,1.351,1.351,1.351,1.351,1.372,1.372,1.372,1.372,1.386,1.386,1.386,1.386,1.414,1.414,1.414,1.414,1.443,1.443,1.443,1.443,1.443,1.443,1.443,1.443,1.443,1.448,1.448,1.448,1.463,1.463,1.463,1.456,1.456,1.456,1.456,1.456,1.440,1.440,1.440,1.440,1.429,1.429,1.429,1.419,1.419,1.435,1.435,1.435,1.435,1.435,1.465,1.465,1.438,1.438,1.394,1.394,1.394,1.423,1.423,1.423,1.460,1.460,1.460,1.460,1.472,1.472,1.472,1.451,1.451,1.451,1.400,1.421,1.421,1.421,1.421,1.421,1.421,1.450,1.450,1.450,1.450,1.463,1.463,1.463,1.463,1.463,1.463,1.463,1.463,1.459,1.459,1.459,1.459,1.480,1.480,1.480,1.480,1.498,1.498,1.498,1.498,1.498,1.498,1.498,1.498,1.498,1.511,1.511) > x <- c(1.544,1.544,1.524,1.524,1.524,1.524,1.558,1.558,1.558,1.558,1.558,1.558,1.536,1.536,1.536,1.536,1.536,1.536,1.536,1.536,1.536,1.536,1.559,1.559,1.559,1.591,1.591,1.591,1.591,1.591,1.624,1.624,1.587,1.587,1.587,1.572,1.572,1.572,1.636,1.636,1.636,1.660,1.660,1.660,1.660,1.660,1.660,1.682,1.682,1.682,1.682,1.682,1.658,1.658,1.658,1.616,1.616,1.639,1.639,1.639,1.639,1.606,1.606,1.606,1.606,1.606,1.606,1.569,1.569,1.569,1.571,1.596,1.596,1.596,1.643,1.643,1.643,1.643,1.643,1.643,1.643,1.599,1.599,1.599,1.599,1.586,1.586,1.586,1.586,1.586,1.618,1.618,1.657,1.657,1.657,1.657,1.657,1.645,1.645,1.645,1.585,1.585,1.593,1.593,1.593,1.593,1.627,1.627,1.627,1.627,1.627,1.590,1.590,1.590,1.590,1.590,1.590,1.590,1.607,1.607,1.607) > 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 -0.074798 -0.022740 -0.006572 0.023398 0.077403 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1832 0.1225 1.496 0.137 x 0.7782 0.0764 10.187 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.03513 on 119 degrees of freedom Multiple R-squared: 0.4658, Adjusted R-squared: 0.4613 F-statistic: 103.8 on 1 and 119 DF, p-value: < 2.2e-16 > postscript(file="/var/wessaorg/rcomp/tmp/1xmyp1321358364.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/2b0ag1321358364.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 -2.542e-16 -3.782e-17 -9.059e-18 2.896e-17 1.334e-16 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.832e-01 2.254e-16 8.127e+14 <2e-16 *** x 7.782e-01 1.406e-16 5.534e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 6.466e-17 on 119 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 3.063e+31 on 1 and 119 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/3wush1321358364.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 -0.074798 -0.022740 -0.006572 0.023398 0.077403 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.833e-18 1.225e-01 0 1 x 4.391e-18 7.640e-02 0 1 Residual standard error: 0.03513 on 119 degrees of freedom Multiple R-squared: 1.617e-34, Adjusted R-squared: -0.008403 F-statistic: 1.924e-32 on 1 and 119 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/4fjv31321358364.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 -0.061089 -0.023733 -0.005055 0.028409 0.061874 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.430e+00 2.982e-03 479.6 <2e-16 *** m$residuals -1.186e-17 8.560e-02 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.0328 on 119 degrees of freedom Multiple R-squared: 3.118e-29, Adjusted R-squared: -0.008403 F-statistic: 3.711e-27 on 1 and 119 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/5a28p1321358364.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 -0.050057 -0.004277 -0.001254 0.005644 0.045566 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.001094 0.001348 0.811 0.419 Residuals 0.912951 0.039348 23.202 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.01477 on 118 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.8202, Adjusted R-squared: 0.8187 F-statistic: 538.3 on 1 and 118 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6wbij1321358364.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/76qpm1321358364.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/8vuos1321358364.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/9gnir1321358364.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/10ns7k1321358364.tab") > > try(system("convert tmp/1xmyp1321358364.ps tmp/1xmyp1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/2b0ag1321358364.ps tmp/2b0ag1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/3wush1321358364.ps tmp/3wush1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/4fjv31321358364.ps tmp/4fjv31321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/5a28p1321358364.ps tmp/5a28p1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/6wbij1321358364.ps tmp/6wbij1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/76qpm1321358364.ps tmp/76qpm1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/8vuos1321358364.ps tmp/8vuos1321358364.png",intern=TRUE)) character(0) > try(system("convert tmp/9gnir1321358364.ps tmp/9gnir1321358364.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.481 0.450 2.977