Installing PECL stats on Ubuntu 14

If you want to make inferences about a normally distributed population's mean based on a sample, you can't just whip out the normal distribution, because you don't know enough about the population's variance. A project I'm working presented exactly this problem, and currently the codebase is in PHP, so I needed a way to install PECL's stats package, which includes the function for the poorly documented t-distribution, stats_cdf_t. Installing it (and getting it to work) proved to be a difficulty, so I'm documenting it here in the hope it might be useful to someone else.

Firstly, install as per usual

sudo pecl install stats

If your experience is anything like mine, you'll get an error, and a directory where that stats.tgz file is located. My directory was
/build/php5-0LI9sl/php5-5.5.9+dfsg/pear-build-download. So, run

cd /build/php5-0LI9sl/php5-5.5.9+dfsg/pear-build-download
tar -xvf stats-*.

Now, we need to patch the file so that the $which arguments of 2 and 3 work. Grab the latest version here, and replace the file dcdflib.c in the stats-x.y.z (in my case, stats-1.0.3) folder that was created by the gunzip command.
Having changed that file, we now need to update the md5 hash in package.xml. Run

md5sum stats-*/dcdflib.c

You should get something that looks like d6a2f1ceded9d108541f9204741933b6 dcdflib.c. Paste the first string (the alphanumeric) into packages.xml for the dcdflib.c entry.
Finally, we need to package up these files so that PECL can use them, and then an upgrade.

sudo tar cvf stats-1.0.3.tar package.xml stats-1.0.3
sudo pear upgrade stats-1.0.3.tar

Happy statistics-doing!


  • (Not correctly installing bug)
  • (Problem with using modes 2 and 3 for stats_cdf_t)