In the previous article, I side-stepped the issue of probability functions in PHP by shelling out to R for a probability value. I was not entirely happy with this solution, so I began exploring the issue of what it would take to develop PHP-based probability functions.
I began trolling the Web for information and code. One source of both was the probability functions in the book Numerical Recipes in C. I re-implemented some probability function code in PHP (the
functions), but, again, was not happy with the results. Compared with
some of the other implementations, it seemed to be a lot of code. Also,
I needed to have inverse probability functions.
I ported the Student T and Fisher F functions to PHP. I changed the
API a bit to conform to a Java naming style and embedded all the
functions in a class called
Distribution. One elegant feature of this implementation is the
method that is reused by all the functions in this library. The other
tests that I have not bothered to implement (Normal and ChiSquare) use
You cannot do this in PHP. The only values you can assign to an instance variable are simple constants. Hopefully this limitation will be addressed in PHP5.