BasicRegression Package
![data=Table[{k,k+Random[Real,{-3,3}]},{k,6}]; SquaredResidualPlot[data]](images/BasicRegressionPics_gr_1.gif)

Synopsis
This package provides some basic commands for viewing
bivariate data and fitting functions to such data. It is
intended as a resource for students learning the technique
of least-squares regression, and for techniques such as
taking logarithms of one or both variables. Note that the
commands are very flexible regarding user input; data may
be given as a list of ordered pairs, or as separate x and
y lists. This latter form easily facilitates transforming one
or both variables.
Commands
The following commands are provided in this package:
ScatterPlot[xdata, ydata]
produces a scatterplot of the data whose x coordinates are stored
in the list xdata and whose y coordinates are stored in the list ydata.
ScatterPlot[data] will also produce such a plot, where data
is a list of x-y pairs of the form {{x1,y1},{x2,y2},...}. ScatterPlot
can accept any options that ListPlot accepts.
LinearFit[xdata, ydata]
gives the equation of the least-squares regression line, the value of
r-squared, and a scatterplot (with the regression line superimposed)
of the data whose x coordinates are stored in the list xdata and whose
y coordinates are stored in the list ydata. LinearFit[data] will also
produce this output, where data is a list of x-y pairs of the form
{{x1,y1},{x2,y2},...}. LinearFit can accept any options that ListPlot accepts.
LinearResidualPlot[xdata, ydata]
gives a residual plot for the best fitting
linear function to the data whose x coordinates are stored in the list xdata
and whose y coordinates are stored in the list ydata.
LinearResidualPlot[data] will also produce this output, where data is a list
of x-y pairs of the form {{x1,y1},{x2,y2},...}. LinearResidualPlot can
accept any of the options accepted by ListPlot.
ExponentialFit[xdata, ydata]
gives the equation of the best fitting
exponential function to the data whose x coordinates are stored in the list
xdata and whose y coordinates are stored in the list ydata. This function is
obtained by performing linear regression on Log[10,ydata] vs. xdata. Also
reported are the value of r-squared, and a scatterplot of the data with the
exponential function superimposed. ExponentialFit[data] will also produce
this output, where data is a list of x-y pairs of the form
{{x1,y1},{x2,y2},...}. ExponentialFit can accept any options that ListPlot
accepts.
ExponentialResidualPlot[xdata, ydata]
gives a residual plot for the best
fitting exponential function to the data whose x coordinates are stored in
the list xdata and whose y coordinates are stored in the list ydata.
ExponentialResidualPlot[data] will also produce this output, where data is a
list of x-y pairs of the form {{x1,y1},{x2,y2},...}. ExponentialResidualPlot
can accept any of the options accepted by ListPlot.
PowerFit[xdata, ydata]
gives the equation of the best fitting power function
to the data whose x coordinates are stored in the list xdata and whose y
coordinates are stored in the list ydata. This function is obtained by
performing linear regression on Log[10,ydata] vs. Log[10,xdata]. Also
reported are the value of r-squared, and a scatterplot of the data with the
power function superimposed. PowerFit[data] will also produce this output,
where data is a list of x-y pairs of the form {{x1,y1},{x2,y2},...}.
PowerFit can accept any options that ListPlot accepts.
PowerResidualPlot[xdata, ydata]
gives a residual plot for the best fitting
power function to the data whose x coordinates are stored in the list xdata
and whose y coordinates are stored in the list ydata.
PowerResidualPlot[data] will also produce this output, where data is a list
of x-y pairs of the form {{x1,y1},{x2,y2},...}. PowerResidualPlot can accept
any of the options accepted by ListPlot.
ResidualTable[xdata,ydata]
gives a table of values for the data whose x
coordinates are stored in the list xdata and whose y coordinates are stored
in the list ydata. Also reported are the predicted responses according to
the least-squares regression line, the residuals, and the squares of the
residuals. ResidualTable[data] will also produce this output, where data is a
list of x-y pairs of the form {{x1,y1},{x2,y2},...}.
ResidualTable[xdata,ydata,intercept,slope] or
ResidualTable[data,intercept,slope] gives a similar table, but bases the
predicted responses on the line with the given y-intercept and slope. The sum
of squares of residuals is reported in either case, as is a plot of the data
with the appropriate line superimposed, and a residual plot. ResidualTable
can accept any of the options accepted by ListPlot.
SquaredResidualPlot[xdata,ydata, y-intercept,slope]
produces a scatterplot
of the points whose x coordinates are stored in the list xdata and whose y
coordinates are stored in the list ydata, together with a graph of the line
whose y-intercept and slope are specified. The scatterplot will superimpose a
square (one for each data point) whose area represents the square of that
data point's residual. Thus the picture provides a geometrical interpretation
of the sum of the squares of residuals. If the y-intercept and slope are
omitted, the least-squares regression line will be used. Also, the first two
arguments xdata and ydata may be replaced with a list of 2-tuples of the form
{{x1,y1},{x2,y2},...}. SquaredResidualPlot will accept any option that
ListPlot does.
Last Updated: February 26, 2004