Statistics, Modeling & Visualization · Models, inference, and charts
phit
Regression, mixed models and probability distributions for PHP.
pie install phpstats/phit
- Requires
- PIE unzip or the PHP zip extension
- Builds with
- Rust toolchain Clang and libclang PHP development files (phpize and php-config) autoconf and make
- Platforms
- Linux macOS NTS (non-thread-safe) PHP
Can't install extensions? phit-polyfill defines the same functions in plain PHP.
phit fits statistical models inside PHP and returns plain PHP arrays. It provides OLS, logistic, probit, and Poisson regression, linear mixed models, and mixed logistic regression.
It also provides probability distributions, descriptive statistics, posterior-draw kernels, and a seeded random number generator. Results are verified against R.
Every function is in the Phit namespace, such as Phit\fit_lm(), Phit\predict(), and Phit\dist_normal_cdf(). The functions were named stats_* when the extension was called php-stats.
The extension targets PHP 8.3 to 8.5 on Linux and macOS and installs with PIE as phit.
Example
use function Phit\{fit_lm, predict};
$fit = fit_lm('monthly_rent ~ area_m2 + bedrooms', $housing);
$fit['named']; // ['(Intercept)' => ..., 'area_m2' => ..., 'bedrooms' => ...]
$p = predict($fit, ['area_m2' => [60, 90], 'bedrooms' => [1, 3]], interval: 'prediction');
$p['fit']; // point predictions; $p['lower'], $p['upper'] give 95% intervals