Table of Contents

Class Quartile<T>

Namespace
AiDotNet.Statistics
Assembly
AiDotNet.dll

Computes and stores the quartiles (Q1, Q2, Q3) of a numeric dataset.

public class Quartile<T>

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

Inheritance
Quartile<T>
Inherited Members

Remarks

The Quartile class calculates the three standard quartiles of a dataset: the first quartile (Q1, 25th percentile), the second quartile (Q2, 50th percentile or median), and the third quartile (Q3, 75th percentile). These quartiles divide the dataset into four equal parts and provide insights into the distribution of the data.

For Beginners: Quartiles divide your data into four equal parts, giving you a quick way to understand the distribution of your values.

Think of quartiles like dividing a line of people by height into four equal groups:

  • Q1 (First Quartile): The height where 25% of people are shorter and 75% are taller
  • Q2 (Second Quartile): The height where 50% are shorter and 50% are taller (this is also called the median)
  • Q3 (Third Quartile): The height where 75% are shorter and 25% are taller

Quartiles help you understand:

  • Where the "middle half" of your data lies (between Q1 and Q3)
  • If your data is skewed (if the distance from Q1 to Q2 is different from Q2 to Q3)
  • What values might be considered outliers (typically those below Q1-1.5×IQR or above Q3+1.5×IQR)

For example, if test scores have Q1=70, Q2=80, and Q3=90, you know half the scores are between 70 and 90, and the median score is 80.

Constructors

Quartile(Vector<T>)

Initializes a new instance of the Quartile class with the provided dataset.

public Quartile(Vector<T> data)

Parameters

data Vector<T>

The vector of data values to analyze.

Remarks

This constructor calculates all three quartiles (Q1, Q2, Q3) for the provided dataset. It first sorts the data in ascending order, then uses the StatisticsHelper class to calculate each quartile as the 25th, 50th, and 75th percentiles respectively.

For Beginners: This sets up a new quartile object with your data.

When you create a Quartile object:

  • It takes your set of numbers as input
  • It sorts them from smallest to largest
  • It calculates all three quartiles (Q1, Q2, Q3)
  • It stores these results for you to access later

For example, if you provide [85, 60, 95, 70, 80, 75, 90], it will:

  1. Sort them to [60, 70, 75, 80, 85, 90, 95]
  2. Calculate Q1 ˜ 70 (25th percentile)
  3. Calculate Q2 = 80 (50th percentile)
  4. Calculate Q3 ˜ 90 (75th percentile)

Properties

Q1

Gets the first quartile (Q1, 25th percentile) of the dataset.

public T Q1 { get; }

Property Value

T

Remarks

The first quartile (Q1) is the value below which 25% of the observations in the dataset fall. It represents the median of the lower half of the data. Various methods exist for calculating Q1, and this implementation uses a standard interpolation method.

For Beginners: Q1 is the value where 25% of your data falls below it.

If you divide your sorted data into four equal parts, Q1 is the value at the boundary of the first and second parts.

For example, if you have test scores [60, 70, 75, 80, 85, 90, 95]:

  • Q1 would be approximately 70
  • This means about 25% of scores are 70 or lower

Q1 helps you identify the lower portion of your data range.

Q2

Gets the second quartile (Q2, 50th percentile, median) of the dataset.

public T Q2 { get; }

Property Value

T

Remarks

The second quartile (Q2) is the median of the dataset - the value that divides the dataset into two equal halves. For datasets with an odd number of elements, it is the middle value; for datasets with an even number of elements, it is the average of the two middle values.

For Beginners: Q2 is the middle value of your data (also called the median).

It's the value where:

  • 50% of data points are below it
  • 50% of data points are above it

For example, if you have test scores [60, 70, 75, 80, 85, 90, 95]:

  • Q2 would be 80
  • This means half the scores are 80 or lower, and half are 80 or higher

The median (Q2) is often a better measure of "central tendency" than the average (mean) when your data contains outliers.

Q3

Gets the third quartile (Q3, 75th percentile) of the dataset.

public T Q3 { get; }

Property Value

T

Remarks

The third quartile (Q3) is the value below which 75% of the observations in the dataset fall. It represents the median of the upper half of the data. Various methods exist for calculating Q3, and this implementation uses a standard interpolation method.

For Beginners: Q3 is the value where 75% of your data falls below it.

If you divide your sorted data into four equal parts, Q3 is the value at the boundary of the third and fourth parts.

For example, if you have test scores [60, 70, 75, 80, 85, 90, 95]:

  • Q3 would be approximately 90
  • This means about 75% of scores are 90 or lower

Q3 helps you identify the upper portion of your data range.