pforret/estimator

PHP package to help with statistic estimation (extrapolation) based on historic reference data

1.5.5 2022-01-13 20:14 UTC

This package is auto-updated.

Last update: 2024-05-14 01:34:40 UTC


README

Github: GitHub tag Tests Psalm Styling

Packagist: Packagist Version Packagist Downloads

Package to help estimate stats based on partial data and historic averages.

Example:

  • given the average rainfall in December in 20 cities for the last 5 years (e.g.86 mm for Brussels, ...)
  • when I have the rainfall this year for 15 of those cities,
  • estimate the other 5 cities

Installation

You can install the package via composer:

composer require pforret/estimator

Usage

use Pforret\Estimator\Estimator;
$est = new Estimator();
$est->set_references($references);

// and then

$estimated = $est->estimate_from_partials($partials);

// or 

$estimated = $est->estimate_from_total(100);
$evaluation = $est->evaluate_partials($partials);

// references = values set with set_references
[references_count] => 4
[references_maximum] => 25
[references_mean] => 25
[references_median] => 25
[references_minimum] => 25
[references_sum] => 100
// partials = values specified with estimate_from_partials
[partials_maximum] => 28
[partials_mean] => 26
[partials_median] => 25
[partials_minimum] => 25
[partials_multiplier] => 1.04
[partials_sum] => 78
// found = subset of references, matching with partials keys
[found_count] => 3
[found_count_fraction] => 0.75
[found_mean] => 25
[found_sum] => 75
[found_sum_fraction] => 0.75
// stat = statistic evaulation of estimate/extrapolation
[stat_confidence] => 74.913
[stat_deviation] => 3

Example

$references=[
    "John"  =>  100,
    "Kevin" =>  120,
    "Sarah" =>  100,
    "Vince" =>  100,
    ];
$est = new Estimator();
$est->set_references($references);
$partials=[
    "John"  => 120,
    "Kevin" => 150,
    // "Sarah" is to be estimated
    "Vince" =>  175,
    ];
$estimation=$est->estimate_from_partials();
/*
    [John] => 120
    [Kevin] => 150
    [Vince] => 175
    [Sarah] => 139 <<< estimation
*/

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email author_email instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.