Coder Social home page Coder Social logo

Comments (1)

markrogoyski avatar markrogoyski commented on May 27, 2024 2

Hi @davidjr82,

Thank you for your interest in MathPHP.

Quartiles, unfortunately, do not have a single standard way to compute them. In R for instance, there are nine different variations. Excel has two. The Wikipedia article shows four. MathPHP's documentation for quartilesInclusive indicates it uses the "Tukey's hinges" quartile method, which is "method 2" in the Wikipedia article.

Method 2
Use the median to divide the ordered data set into two-halves.
If there are an odd number of data points in the original ordered data set, include the median (the central value in the ordered list) in both halves.
If there are an even number of data points in the original ordered data set, split this data set exactly in half.
The lower quartile value is the median of the lower half of the data. The upper quartile value is the median of the upper half of the data.
The values found by this method are also known as "Tukey's hinges";[4] see also midhinge.

Using your dataset and computing the Wikipedia method 2 by hand.
[0,900,1800,2700,3600,4500]

Use the median to divide the ordered data set into two-halves.

There is an even number of numbers, so the median is the average of 1800 and 2700 which is 2250.

If there are an even number of data points in the original ordered data set, split this data set exactly in half.

Lower half = [0, 900, 1800]
Upper half = [2700, 3600, 4500]

The lower quartile value is the median of the lower half of the data

The median of [0, 900, 1800] is 900.

The upper quartile value is the median of the upper half of the data.

The median of [2700, 3600, 4500] is 3600.

This matches the result MathPHP provides.

Also for reference, there are multiple quartile methods in R which give the same result:

> quantile(c(0, 900, 1800, 2700, 3600, 4500), type=2)
  0%  25%  50%  75% 100% 
   0  900 2250 3600 4500 

> quantile(c(0, 900, 1800, 2700, 3600, 4500), type=5)
  0%  25%  50%  75% 100% 
   0  900 2250 3600 4500

Keep in mind there is also a Descriptive::percentile function you can use which has a more "standard" definition if that is what you are looking for.

Descriptive::percentile([0,900,1800,2700,3600,4500], 25)  // 1125

from math-php.

Related Issues (20)

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.