Search

Useful Lists

Web Host
Partners

Online Manuals

Simple linear regression with PHP: Part 2
By Paul Meagher - 2004-05-21 Page:  1 2 3 4 5 6 7 8 9

## Output methods

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:

• `showSummaryTable()`
• `showAnalysisOfVariance()`
• `showParameterEstimates()`
• `showRValues()`

I also have a method for showing the linear prediction formula (`getFormula()`). 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.

Listing 2. Demonstrating the general logic of the output class
 `````` ``````

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 `SimpleLinearRegression` class with unused methods and you have more freedom to define classes for other output media (perhaps implementing the same API for different media types).

View Simple linear regression with PHP: Part 2 Discussion

Page:  1 2 3 4 5 6 7 8 9 Next Page: Graphical output