richjenks / stats Goto Github PK
View Code? Open in Web Editor NEWStatistics library for non-statistical people
Statistics library for non-statistical people
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.
Line 119 in 5e5b546
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
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
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']
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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.