# ::Free Statistics and Forecasting Software::

v1.1.23-r7
Secure website (SSL) | Donate to wessa.net

### :: Simulated Regression - Free Statistics Software (Calculator) ::

All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.

This program is one that an instructor could use to introduce simple linear regression. This R module uses a simple simulated data set and allows a sequence of graphs which show what regression is trying to do, how you can use it for prediction, and shows the residual plot. The last part uses a quadratic data set to show what the residual plot looks like in this case.
You can replace the default x and y by changing the underlying R code - for example: x=1:20 and y=1:20+rgamma(20,2,1)

 Chart options Width: Height:

 Source code of R module x=0:10 y=x+2+1.5*rnorm(length(x)) bitmap(file="test1.png") print(x) print(y) plot(x,y,xlab="predictor,x",ylab="predicted y",main="data for estimating predictive model",pch=16,cex=1.5,xlim=c(min(x)-.2*sd(x),max(x)+.2*sd(x)),ylim=c(0-.2*sd(y),max(y)+.2*sd(y))) lmout=lm(y~x) lines(x,lmout\$fitted,col="red",lwd=2) x0=mean(x)+sd(x) y0=lmout\$coefficients[[1]]+lmout\$coefficients[[2]]*x0 x1=mean(x)-.5*sd(x) y1=lmout\$coefficients[[1]]+lmout\$coefficients[[2]]*x1 arrows(x0,min(y)-.2*sd(y),x0,y0,col="blue",code=2) arrows(x0,y0,min(x)-.2*sd(x),y0,col="blue",code=2) arrows(x1,min(y)-.2*sd(y),x1,y1,col="blue",code=2) arrows(x1,y1,min(x)-.2*sd(x),y1,col="blue",code=2) for (i in 1:length(x)) { lines(c(x[i],x[i]),c(y[i],lmout\$fitted[i]),col="darkgreen",lwd=1.5) } legend(mean(x),mean(y)-.5*sd(x),"regression line-red") legend(mean(x),mean(y)-1.0*sd(x),"predictions-blue") legend(mean(x),mean(y)-1.5*sd(x),"prediction errors-green") text(mean(x)-.75*sd(x),max(y)+.15*sd(y),"Regression Line Minimizes",col="purple") text(mean(x)-sd(x),max(y)-.10*sd(y),"Root-Mean-Square",col="purple") text(mean(x)+0.4*sd(x),max(y)-.10*sd(y),"Prediction Error",col="darkgreen") dev.off() bitmap(file="myresid.png") plot(x,lmout\$residuals,xlab="predictor,x",ylab="prediction error (residual)",main="Residuals from Regression Fit",xlim=c(min(x)-.2*sd(x),max(x)+.2*sd(x)),pch=16,cex=1.5) lines(c(min(x),max(x)),c(0,0),lwd=2) for (i in 1:length(x)) { lines(c(x[i],x[i]),c(lmout\$residuals[i],0),col="darkgreen",lwd=1.5) } dev.off() z=x+5*(x/sd(x))^2+5*rnorm(length(x)) lmout2=lm(z~x) bitmap(file="mynew.png") plot(x,z,pch=16,cex=1.5,main="New data set - linear? (Not!)") lines(x,lmout2\$fitted,lwd=2,col="red") dev.off() bitmap(file="myresid1.png") plot(x,lmout2\$residuals,pch=16,cex=1.5,main="Residual plot for new data",ylab="residual") lines(c(min(x),max(x)),c(0,0),lwd=2) fit=loess(lmout2\$residuals~x,span=1,degree=2) lines(fit\$x,fit\$fitted,col="red") dev.off()
 Top | Output | Charts | References | History | Feedback

 Cite this software as: Weldon Larry, (2008), Simulated Regression (v1.0.2) in Free Statistics Software (v1.1.23-r7), Office for Research Development and Education, URL http://www.wessa.net/rwasp_regr.wasp/ The R code is based on : Weldon Larry, Stat Ed Programs for Demos in R, Simon Fraser University, URL http://www.stat.sfu.ca/~weldon/title.doc Weldon Larry, R Programs for Statistics Education, Simon Fraser University, URL http://www.stat.sfu.ca/~weldon/Programs Weldon Larry, Instructions for using R programs for Statistics Education, Simon Fraser University, URL http://www.stat.sfu.ca/~weldon/instructions.doc
 Top | Output | Charts | References | History | Feedback
 Top | Output | Charts | References | History | Feedback
 To cite Wessa.net in publications use:Wessa, P. (2013), Free Statistics Software, Office for Research Development and Education, version 1.1.23-r7, URL http://www.wessa.net/ © All rights reserved. Academic license for non-commercial use only. The free use of the scientific content, services, and applications in this website is granted for non commercial use only. In any case, the source (url) should always be clearly displayed. Under no circumstances are you allowed to reproduce, copy or redistribute the design, layout, or any content of this website (for commercial use) including any materials contained herein without the express written permission. Information provided on this web site is provided "AS IS" without warranty of any kind, either express or implied, including, without limitation, warranties of merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information and periodically update the information, and software without notice. We make no warranties or representations as to the accuracy or completeness of such information (or software), and it assumes no liability or responsibility for errors or omissions in the content of this web site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and under no legal theory shall we be liable to you or any other person for any direct, indirect, special, incidental, exemplary, or consequential damages arising from your access to, or use of, this web site. Software Version : 1.1.23-r7Algorithms & Software : Patrick Wessa, PhDServer : www.wessa.net