# ::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

 [Select module] Main Menu Equation Plotter   Scientific Forecasting   Descriptive Statistics -Central Tendency -Variability -Skewness/Kurtosis -Quartiles -Percentiles -Stem and Leaf -Histogram -Kernel Density -Harrell-Davis -Univariate EDA -Bootstrap -Blocked Bootstrap -Mean Plot -SD Plot -(P)ACF -Spectrum -SD Mean-Plot -Variance Reduction -Correlation -Kendall Rank Corr. -Simple Regression -Bivariate KDE -Box-Cox Linearity -Regression Validation -Back-Back Histo. -Partial Correlation -Trivariate Scatter -Kendall tau Matrix -Notched Boxplots -Star Plot   Distributions -Normal ML Fit -Beta ML Fit -Cauchy ML Fit -Exponential ML Fit -Gamma ML Fit -Lognormal ML Fit -Logistic ML Fit -Neg. Binom. ML Fit -Poisson ML Fit -Weibull ML Fit -Tukey lambda PPCC -Box-Cox Normality   Hypothesis Tests -Mean -Skewness/Kurtosis   Multiple Regression -Estimate Equation   About this server

 Home Page Equation Plotter Time Series Analysis Multiple Regression Descriptive Statistics Statistical Distributions Hypothesis Testing Simon Fraser University Aston University Academic citations Computations Archive Search Computations R Project FAQ About Wessa.net Powered by Linux Server status page Any R Server'Herman Ole Andreas Wold''Gwilym Jenkins''Sir Ronald Aylmer Fisher''George Udny Yule''Gertrude Mary Cox''Sir Maurice George Kendall'Installed PackagesHistory list