WeBWorK Problems

stats and least squares linear regression

stats and least squares linear regression

by Zak Zarychta -
Number of replies: 1

Having done a quick search I am unsure of the status of the stats functions available in WW. 

What I am aiming to do is give the students a set of 10 data points which they are required to calculate the gradient and intercept of the line of best fit and their respective uncertainties. 

Any pointers to existing functionality in WW is welcome.

Zak

In reply to Zak Zarychta

Re: stats and least squares linear regression

by Danny Glin -

You can look at the code of the problems in the Regression section of the OPL to get some ideas.  Here are a few techniques that I am aware of:

  1. Use the R integration with WeBWorK.  This allows you to call any R functions to do statistical calculations.  Many of the UBC statistics problems in the OPL take advantage of this.
  2. There appears to be a function called linear_regression in PGstatisticsmacros.pl.  According to the documentation, the usage is:
    @xdata = (-1,2,3,4,5,6,7);
    @ydata = (6,5,6,7,8,9,11);
    ($slope,$intercept,$var,$SXX) = linear_regression(~~@xdata,~~@ydata);
    Though based on a quick look, this isn't used in any OPL problem, so I don't know how well tested it is.
  3. You can create a for loop within your problem to manually calculate the parameters.  This is inelegant but effective.