R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-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(149 + ,139 + ,148 + ,158 + ,128 + ,224 + ,159 + ,105 + ,159 + ,167 + ,165 + ,159 + ,119 + ,176 + ,54 + ,91 + ,163 + ,124 + ,137 + ,121 + ,153 + ,148 + ,221 + ,188 + ,149 + ,244 + ,148 + ,92 + ,150 + ,153 + ,94 + ,156 + ,132 + ,161 + ,105 + ,97 + ,151 + ,131 + ,166 + ,157 + ,111 + ,145 + ,162 + ,163 + ,59 + ,187 + ,109 + ,90 + ,105 + ,83 + ,116 + ,42 + ,148 + ,155 + ,125 + ,116 + ,128 + ,138 + ,49 + ,96 + ,164 + ,162 + ,99 + ,202 + ,186 + ,66 + ,183 + ,214 + ,188 + ,104 + ,177 + ,126 + ,76 + ,99 + ,139 + ,162 + ,108 + ,159 + ,74 + ,110 + ,96 + ,116 + ,87 + ,97 + ,127 + ,106 + ,80 + ,74 + ,91 + ,133 + ,74 + ,114 + ,140 + ,95 + ,98 + ,121 + ,126 + ,98 + ,95 + ,110 + ,70 + ,102 + ,86 + ,130 + ,96 + ,102 + ,100 + ,94 + ,52 + ,98 + ,118 + ,99 + ,48 + ,50 + ,150 + ,154 + ,109 + ,68 + ,194 + ,158 + ,159 + ,67 + ,147 + ,39 + ,100 + ,111 + ,138 + ,101 + ,131 + ,101 + ,114 + ,165 + ,114 + ,111 + ,75 + ,82 + ,121 + ,32 + ,150 + ,117 + ,71 + ,165 + ,154 + ,126 + ,149 + ,145 + ,120 + ,109 + ,132 + ,172 + ,169 + ,114 + ,156 + ,172 + ,68 + ,89 + ,167 + ,113 + ,115 + ,78 + ,118 + ,87 + ,173 + ,2 + ,162 + ,49 + ,122 + ,96 + ,100 + ,82 + ,100 + ,115 + ,141 + ,165 + ,165 + ,110 + ,118 + ,158 + ,146 + ,49 + ,90 + ,121 + ,155 + ,104 + ,147 + ,110 + ,108 + ,113 + ,115 + ,61 + ,60 + ,109 + ,68 + ,111 + ,77 + ,73 + ,151 + ,89 + ,78 + ,110 + ,220 + ,65 + ,141 + ,117 + ,122 + ,63 + ,44 + ,52 + ,131 + ,101 + ,42 + ,152 + ,107 + ,77 + ,154 + ,103 + ,96 + ,175 + ,57 + ,112 + ,143 + ,49 + ,110 + ,131 + ,167 + ,56 + ,137 + ,86 + ,121 + ,149 + ,168 + ,140 + ,88 + ,168 + ,94 + ,51 + ,48 + ,145 + ,66 + ,85 + ,109 + ,63 + ,102 + ,162 + ,86 + ,114 + ,164 + ,119 + ,126 + ,132 + ,142 + ,83 + ,94 + ,81 + ,166 + ,110 + ,64 + ,93 + ,104 + ,105 + ,49 + ,88 + ,95 + ,102 + ,99 + ,63 + ,76 + ,109 + ,117 + ,57 + ,120 + ,73 + ,91 + ,108 + ,105 + ,117 + ,119 + ,31) > x <- c(68,39,32,62,33,52,62,77,76,41,48,63,30,78,19,31,66,35,42,45,21,25,44,69,54,74,80,42,61,41,46,39,34,51,42,31,39,20,49,53,31,39,54,49,34,46,55,42,50,13,37,25,30,28,45,35,28,41,6,45,73,17,40,64,37,25,65,100,28,35,56,29,43,59,50,59,27,61,28,51,35,29,48,25,44,64,32,20,28,34,31,26,58,23,21,21,33,16,20,37,35,33,27,41,40,35,28,32,22,44,27,17,12,45,37,37,108,10,68,72,143,9,55,17,37,27,37,58,66,21,19,78,35,48,27,43,30,25,69,72,23,13,61,43,51,67,36,44,45,34,36,72,39,43,25,56,80,40,73,34,72,42,61,23,74,16,66,9,41,57,48,51,53,29,29,55,54,43,51,20,79,39,61,55,30,55,22,37,2,38,27,56,25,39,33,43,57,43,23,44,54,28,36,39,16,23,40,24,78,57,37,27,61,27,69,34,44,34,39,51,34,31,13,12,51,24,19,30,81,42,22,85,27,25,22,19,14,45,45,28,51,41,31,74,19,51,73,24,61,23,14,54,51,62,36,59,24,26,54,39,16,36,31,31,42,39,25,31,38,31,17,22,55,62,51,30,49,16) > par1 = '0' > ylab = 'y' > xlab = 'x' > par1 <- '0' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa P., (2012), Linear Regression Graphical Model Validation (v1.0.7) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_linear_regression.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > # > 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 -97.211 -26.853 -3.505 23.500 102.201 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 77.7575 5.1304 15.156 < 2e-16 *** x 0.9327 0.1125 8.289 5.03e-15 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 35.71 on 276 degrees of freedom Multiple R-squared: 0.1993, Adjusted R-squared: 0.1964 F-statistic: 68.71 on 1 and 276 DF, p-value: 5.026e-15 > postscript(file="/var/wessaorg/rcomp/tmp/1gg6a1418459922.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/2gvwv1418459922.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.690e-14 -1.165e-14 -5.660e-15 -4.700e-16 1.655e-12 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 7.776e+01 1.470e-14 5.291e+15 <2e-16 *** x 9.327e-01 3.223e-16 2.894e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.023e-13 on 276 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 8.373e+30 on 1 and 276 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/3spz51418459922.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 -97.211 -26.853 -3.505 23.500 102.201 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.029e-14 5.130e+00 0 1 x 1.455e-16 1.125e-01 0 1 Residual standard error: 35.71 on 276 degrees of freedom Multiple R-squared: 4.609e-32, Adjusted R-squared: -0.003623 F-statistic: 1.272e-29 on 1 and 276 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/43co41418459922.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 -36.780 -12.528 -2.268 11.490 94.738 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.164e+02 1.069e+00 108.9 <2e-16 *** m$residuals 5.614e-17 3.003e-02 0.0 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 17.82 on 276 degrees of freedom Multiple R-squared: 2.642e-29, Adjusted R-squared: -0.003623 F-statistic: 7.293e-27 on 1 and 276 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/5rr9w1418459922.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 -100.69 -26.12 -2.09 23.93 97.93 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.04873 2.14021 -0.023 0.982 Residuals 0.09213 0.06037 1.526 0.128 Residual standard error: 35.62 on 275 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.008397, Adjusted R-squared: 0.004792 F-statistic: 2.329 on 1 and 275 DF, p-value: 0.1281 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/6wyf81418459922.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/7r8ga1418459922.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/8mla51418459922.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/9mhdu1418459922.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/10iur41418459922.tab") > > try(system("convert tmp/1gg6a1418459922.ps tmp/1gg6a1418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/2gvwv1418459922.ps tmp/2gvwv1418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/3spz51418459922.ps tmp/3spz51418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/43co41418459922.ps tmp/43co41418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/5rr9w1418459922.ps tmp/5rr9w1418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/6wyf81418459922.ps tmp/6wyf81418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/7r8ga1418459922.ps tmp/7r8ga1418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/8mla51418459922.ps tmp/8mla51418459922.png",intern=TRUE)) character(0) > try(system("convert tmp/9mhdu1418459922.ps tmp/9mhdu1418459922.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.218 0.489 3.757