R version 2.8.1 (2008-12-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(2.55,2.27,2.26,2.57,3.07,2.76,2.51,2.87,3.14,3.11,3.16,2.47,2.57,2.89,2.63,2.38,1.69,1.96,2.19,1.87,1.60,1.63,1.22,1.21,1.49,1.64,1.66,1.77,1.82,1.78,1.28,1.29,1.37,1.12,1.51,2.24,2.94,3.09,3.46,3.64,4.39,4.15,5.21,5.80,5.91,5.39,5.46,4.72,3.14,2.63,2.32,1.93,0.62,0.60,-0.37,-1.10,-1.68,-0.78) > x <- c(-0.5349,-0.5348,-0.5591,-0.5200,-0.5173,-0.5153,-0.5048,-0.4950,-0.4597,-0.4681,-0.4909,-0.4579,-0.4758,-0.4662,-0.4821,-0.4767,-0.4740,-0.5295,-0.5075,-0.5222,-0.5377,-0.5108,-0.5197,-0.5292,-0.5024,-0.5175,-0.5088,-0.5180,-0.5177,-0.5027,-0.5002,-0.4882,-0.4603,-0.4687,-0.5092,-0.4729,-0.4488,-0.5085,-0.5142,-0.5130,-0.4721,-0.5425,-0.5123,-0.4845,-0.4950,-0.5024,-0.5349,-0.5861,-0.6495,-0.6751,-0.7095,-0.6941,-0.6794,-0.6559,-0.6051,-0.5713,-0.5532,-0.5341) > 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 -3.88696 -0.85732 -0.05888 0.62181 3.37265 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.347 1.757 3.044 0.00355 ** x 5.677 3.319 1.710 0.09274 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.523 on 56 degrees of freedom Multiple R-squared: 0.04964, Adjusted R-squared: 0.03267 F-statistic: 2.925 on 1 and 56 DF, p-value: 0.09274 > postscript(file="/var/www/rcomp/tmp/1ykpc1256672572.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/2stdp1256672572.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.587e-15 -5.319e-17 1.924e-17 1.477e-16 4.388e-16 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.347e+00 4.466e-16 1.197e+16 <2e-16 *** x 5.677e+00 8.439e-16 6.727e+15 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.873e-16 on 56 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 4.526e+31 on 1 and 56 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/39rhp1256672572.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 -3.88696 -0.85732 -0.05888 0.62181 3.37265 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.851e-17 1.757e+00 2.19e-17 1 x 1.264e-16 3.319e+00 3.81e-17 1 Residual standard error: 1.523 on 56 degrees of freedom Multiple R-squared: 4.812e-34, Adjusted R-squared: -0.01786 F-statistic: 2.695e-32 on 1 and 56 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/42wuu1256672572.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 -1.04275 -0.05143 0.07474 0.20971 0.43721 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.362e+00 4.572e-02 51.67 <2e-16 *** m$residuals -5.344e-18 3.054e-02 -1.75e-16 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.3482 on 56 degrees of freedom Multiple R-squared: 4.997e-30, Adjusted R-squared: -0.01786 F-statistic: 2.798e-28 on 1 and 56 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/5apom1256672572.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 -1.32746 -0.24657 0.08175 0.27842 0.97627 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.05763 0.06567 -0.878 0.384 Residuals 0.98402 0.04519 21.774 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.4955 on 55 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.8961, Adjusted R-squared: 0.8942 F-statistic: 474.1 on 1 and 55 DF, p-value: < 2.2e-16 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/6zch71256672572.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/7jttj1256672572.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/81cpj1256672572.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/91ygk1256672572.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/10cn0c1256672572.tab") > > system("convert tmp/1ykpc1256672572.ps tmp/1ykpc1256672572.png") > system("convert tmp/2stdp1256672572.ps tmp/2stdp1256672572.png") > system("convert tmp/39rhp1256672572.ps tmp/39rhp1256672572.png") > system("convert tmp/42wuu1256672572.ps tmp/42wuu1256672572.png") > system("convert tmp/5apom1256672572.ps tmp/5apom1256672572.png") > system("convert tmp/6zch71256672572.ps tmp/6zch71256672572.png") > system("convert tmp/7jttj1256672572.ps tmp/7jttj1256672572.png") > system("convert tmp/81cpj1256672572.ps tmp/81cpj1256672572.png") > system("convert tmp/91ygk1256672572.ps tmp/91ygk1256672572.png") > > > proc.time() user system elapsed 2.010 1.850 3.624