Now that you have implemented the probability functions in PHP, the only remaining hurdle in developing a PHP-based data-exploration tool is to devise methods for displaying the results of the analysis.
The simple solution is to dump the values of all the instance
variables to the screen as needed. I did this in the first article when
I displayed the linear equation, T value, and T probability for the Burnout Study. It is useful to be able to access a particular value for particular purposes and the
SimpleLinearRegression supports this type of usage.
Another way to output the results, however, is to systematically group parts of the output. If you study the output of the leading statistical packages for regression analysis, you will notice that they tend to group the output in the same manner. They tend to have a Summary Table, an Analysis Of Variance table, a Parameter Estimates table, and R Values. Similarly, I have created output methods called:
I also have a method for showing the linear prediction formula (
Many statistical packages do not output the formula, expecting the user
to construct the formula based on output from the above methods. This
is partly due to the final form of the formula you ultimately use to
model the data may be different than this default formula because:
- The Y-intercept has no meaningful interpretation, or
- The input values may be transformed and you probaby need to un-transform them for final interpretation.
All of these methods assume that the output medium is a Web page. To
anticipate the possibility that you would want to output these summary
values using a medium other than a Web page, I decided to wrap these
output methods inside a class that extends the
SimpleLinearRegression class. The code in Listing 2 is meant to demonstrate the general logic of the output class. Code implementing the various show methods are removed to make the general logic more apparent.
The constructor of this class is simply a wrapper for the constructor of the
SimpleLinearRegression class. This means that when you want to display HTML output from a
SimpleLinearRegression analysis, you should instantiate the
SimpleLinearRegressionHTML class in lieu of instantiating the
SimpleLinearRegression class directly. The benefit is that you do not bloat the
class with unused methods and you have more freedom to define classes
for other output media (perhaps implementing the same API for different