Giter Club home page Giter Club logo

stats's People

Contributors

richjenks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stats's Issues

Noice

Overall Structure and Organization

The class is properly organized and follows the PSR-12 coding style guide for PHP.
It is placed in the RichJenks\Stats namespace, which helps prevent naming conflicts with other libraries or code.
The class contains a set of static methods, making it easy to use the library without instantiating an object.

Features and Functionality

The class provides a wide range of statistical calculations, including mean, median, mode, range, variance, standard deviation, quartiles, interquartile range, outliers, inliers, percentiles, and more.
The method names are descriptive and intuitive, making it easy to understand their purpose.
The class uses appropriate mathematical formulas and algorithms to perform the calculations accurately.

Method Usage and Parameters

The methods are well-documented with PHPDoc comments, specifying the purpose, parameter details, and return types.
The methods have clear and consistent parameter names, such as $data, which indicates that an array of values is expected.
The class includes constants, SAMPLE and POPULATION, to distinguish between sample and population calculations. This provides flexibility in statistical calculations.
The default values for optional parameters are appropriately set to self::SAMPLE, ensuring backward compatibility with previous code.

Error Handling and Edge Cases

The class does not include explicit error handling or exception throwing. It assumes that the input data will be in the correct format and handles the calculations accordingly.
The class does not handle cases where the input arrays are empty or contain non-numeric values. It is assumed that the input data will be properly validated before using the library.

Potential Improvements

While the class provides a useful set of statistical calculations, it could benefit from additional methods for other common statistical operations, such as correlation, regression, hypothesis testing, etc.
It would be helpful to provide more examples and usage instructions in the class documentation, showcasing how to use the library effectively.

Overall, the Stats class appears to be a useful and well-implemented PHP statistics library for non-statisticians. It provides a range of statistical calculations and operations, allowing developers to perform common statistical tasks easily.

Deviation function is unstable

stats/Stats.php

Line 119 in 5e5b546

public static function deviations(array $data): array

Hello,

I started using your library, and quickly saw divergences between its results and some other JS library.

After few research, your deviation function is not correct in all case because of your deviation array keys : If 2 or more values from the array are float with same int value (like 146.54, 146.88) this would only create one key and overwrite it with other values.
This is because your loop actually sets an Int as key, and this create a high chance of overwriting, you should use something like :
foreach ($data as $key => $value) { $deviations[] = pow($value - $mean, 2); }
So you are sure no data is lost in the process.

This issue also create cascade problem with the sd function, as if you try to get the std dev of the array [0.124, 0.431, 0.155, 0.555] the deviation created will be something like [0 => xxx] . If you use this for a std dev of sample, this will divide the whole by 0 (array length - 1) and create php error division by 0.

I hope this might help, however I am not an expert and might also be totally wrong :O

Cheers

\RichJenks\Stats\Stats::percentile() is wrong

Hello,
50th percentile for a random simple data is wrong

\RichJenks\Stats\Stats::percentile([212.52, 360.53, 368.05, 401.77, 430.86, 491, 516.56, 782.86], 50)

returns: 491

but is actually: 416.315 = (401.77 + 430.86) / 2
a.k.a the median

Division by zero error on Stats::sd and Stats::variance

Hi, i am getting a 'division by zero' error when using stats::variance and stats::sd following your data example which is [1,2,3]

Currently, i have to quote the number to avoid the 'division by error' like this ['1','2','3']

Composer could not find

In InitCommand.php line 727:

Could not find a matching version of package richjenks/stats. Check the package spel
ling, your version constraint and that the package is available in a stability which
matches your minimum-stability (dev).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.