R version 2.12.0 (2010-10-15) Copyright (C) 2010 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(1235,1080,845,1522,1047,1979,1822,1253,1297,946,1713,1024,1147,1092,1152,1336,2131,1550,1884,2041,845,1483,1055,1545,729,1792,1175,1593,785,744,1356,1262,1250,1020,840,1515,1045,1972,1820,1248,1290,944,1713,1022,1143,1089,1149,1327,2128,1143,1880,2034,844,1879,1050,1541,724,1782,1170,1586,749,740,1352) > x <- c(13,12,7,9,6,11,12,10,9,9,15,11,8,6,13,10,14,8,11,10,6,9,14,8,6,9,15,8,7,7,5,7,12,11,6,9,5,11,11,9,8,8,14,11,7,5,12,10,13,7,10,9,5,9,13,7,5,8,14,7,7,6,4) > 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 -539.26 -362.67 -46.29 325.33 719.17 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 811.86 157.93 5.141 3.05e-06 *** x 55.89 16.45 3.398 0.00120 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 369.6 on 61 degrees of freedom Multiple R-squared: 0.1591, Adjusted R-squared: 0.1454 F-statistic: 11.54 on 1 and 61 DF, p-value: 0.001202 > postscript(file="/var/www/rcomp/tmp/1jaym1321792211.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/www/rcomp/tmp/254hw1321792211.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.059e-13 -5.159e-14 -7.880e-16 6.429e-14 1.158e-13 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 8.119e+02 3.605e-14 2.252e+16 <2e-16 *** x 5.589e+01 3.755e-15 1.488e+16 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.438e-14 on 61 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 2.216e+32 on 1 and 61 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/3yp5u1321792211.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 -539.26 -362.67 -46.29 325.33 719.17 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -3.918e-15 1.579e+02 0 1 x 2.808e-15 1.645e+01 0 1 Residual standard error: 369.6 on 61 degrees of freedom Multiple R-squared: 1.571e-33, Adjusted R-squared: -0.01639 F-statistic: 9.586e-32 on 1 and 61 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/488yy1321792211.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 -289.18 -121.53 -9.76 102.01 325.55 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.325e+03 2.026e+01 65.38 <2e-16 *** m$residuals 4.459e-17 5.570e-02 0.00 1 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 160.8 on 61 degrees of freedom Multiple R-squared: 4.523e-30, Adjusted R-squared: -0.01639 F-statistic: 2.759e-28 on 1 and 61 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/54ilc1321792211.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 -535.6 -357.5 -29.5 248.7 803.6 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.0065 46.3591 0.086 0.931 Residuals -0.1736 0.1272 -1.365 0.177 Residual standard error: 365 on 60 degrees of freedom (2 observations deleted due to missingness) Multiple R-squared: 0.03012, Adjusted R-squared: 0.01395 F-statistic: 1.863 on 1 and 60 DF, p-value: 0.1774 > abline(m5) > grid() > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/6237k1321792211.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/www/rcomp/tmp/7m3au1321792211.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/www/rcomp/tmp/8bthv1321792211.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/www/rcomp/tmp/93gh91321792211.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/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/10ly6j1321792211.tab") > > try(system("convert tmp/1jaym1321792211.ps tmp/1jaym1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/254hw1321792211.ps tmp/254hw1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/3yp5u1321792211.ps tmp/3yp5u1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/488yy1321792211.ps tmp/488yy1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/54ilc1321792211.ps tmp/54ilc1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/6237k1321792211.ps tmp/6237k1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/7m3au1321792211.ps tmp/7m3au1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/8bthv1321792211.ps tmp/8bthv1321792211.png",intern=TRUE)) character(0) > try(system("convert tmp/93gh91321792211.ps tmp/93gh91321792211.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.970 0.320 4.261