UK-based online statistics and data analysis support for USA, UK, and international clients. No exams, no impersonation, no fabricated data.
Basic Descriptive Statistics Guides

Interquartile Range: Complete R, Python, SPSS and Excel Guide

Learn Interquartile Range with a complete worked example using student performance data. This guide explains Q1, median, Q3, IQR, Tukey outlier fences, box plots, histograms, R, Python, SPSS, Excel and chart interpretation.

Statistics guide Ethical learning support SPSS/R/Python/Excel friendly
Interquartile Range guide showing Q1, median, Q3, IQR, Tukey fences, box plots, histogram, R, Python, SPSS and Excel workflow

Descriptive Statistics Guide

Interquartile Range is a robust descriptive statistic that measures the spread of the middle 50% of a dataset. It is calculated as Q3 minus Q1 and is especially useful when a variable has skewness, unusual values or outliers. This complete guide explains Q1, median, Q3, IQR, Tukey 1.5 × IQR fences, possible outliers, box plots, histogram interpretation, R charts, Python charts, SPSS output and Excel workflow using student performance data.

Advertisement
Google AdSense top placement reserved here

Quick Answer: Interquartile Range Result

An Interquartile Range analysis was used to describe the middle spread of the student performance dataset. The main outcome variable was G3 final grade. For G3, the first quartile was 10, the median was 12, the third quartile was 14 and the IQR was 4.

Dataset rows649
Main outcomeG3
G3 IQR4
G3 possible outliers16

Main finding: The middle 50% of G3 final grades falls between 10 and 14. The median is 12. Tukey’s lower fence is 4 and the upper fence is 20, so the possible G3 outliers are low-end scores below 4 rather than high-end scores above the upper fence.

Important interpretation note: IQR is not the same as the full range. The full G3 range is 0 to 19, but the IQR focuses only on the central 50% of values. This is why IQR is more robust than the range when extreme values are present.

Table of Contents

What Is Interquartile Range?

Interquartile Range, usually written as IQR, is the distance between the third quartile and the first quartile. The first quartile, Q1, is the 25th percentile. The third quartile, Q3, is the 75th percentile. The IQR therefore describes the spread of the middle half of a dataset.

In simple words, IQR ignores the lowest 25% and the highest 25% of values and focuses on the central 50%. This makes it very useful for skewed data, ordinal scales, exam marks, clinical measures, survey scores, absence counts and other variables where extreme values can distort the mean or the range.

Interquartile Range is commonly reported with the five-number summary, box plot interpretation, histogram interpretation, frequency distribution and descriptive statistics. It is also helpful before more advanced analysis because it quickly shows whether the middle spread is narrow, wide or affected by outlier fences.

Simple meaning: IQR tells how spread out the middle 50% of values are. A small IQR means the central values are close together. A large IQR means the central values are more spread out.

Why IQR Is Needed with Mean and Standard Deviation

The mean and standard deviation are important descriptive measures, but they can be sensitive to extreme values. If a dataset has skewness, unusual low values, unusual high values or many outliers, the mean and standard deviation may not fully describe the typical spread. IQR helps by giving a resistant measure of spread.

For G3 final grade, the mean is 11.9060 and the standard deviation is 3.23066. These values are useful, but they do not show where the middle half of students are located. IQR adds that missing information by showing that the middle 50% of final grades is between 10 and 14.

MeasureWhat it usesHow it reacts to outliersBest interpretation use
RangeMinimum and maximumVery sensitiveShows total spread from lowest to highest value.
Standard deviationAll values around the meanSensitiveBest for roughly symmetric numeric distributions.
Interquartile RangeQ1 and Q3RobustBest for central spread, skewed data and outlier-aware reporting.
Coefficient of variationStandard deviation relative to meanSensitive to mean and outliersUseful when comparing relative variation across different scales.

When you need relative variation, use the coefficient of variation. When you need uncertainty around a mean or proportion, use a confidence interval. When you need a robust spread summary, IQR is usually the better descriptive statistic.

Interquartile Range Formula and Tukey Fences

The basic IQR formula is simple. First find Q1 and Q3. Then subtract Q1 from Q3. Tukey’s 1.5 × IQR rule can then be used to flag possible outliers.

Interquartile Range:
IQR = Q3 - Q1

Tukey lower fence:
Lower fence = Q1 - 1.5 × IQR

Tukey upper fence:
Upper fence = Q3 + 1.5 × IQR

Possible low outlier:
Value < Lower fence

Possible high outlier:
Value > Upper fence

For the G3 final grade variable, Q1 = 10 and Q3 = 14. Therefore, the IQR is 14 – 10 = 4. The lower fence is 10 – 1.5 × 4 = 4. The upper fence is 14 + 1.5 × 4 = 20.

G3 formula result: IQR = 14 – 10 = 4. Lower fence = 4. Upper fence = 20. Scores below 4 are possible low-end outliers. Since the maximum observed G3 is 19, there are no high-end G3 outliers by this rule.

Outlier warning: Tukey fences flag possible outliers, not automatic errors. A low G3 value can be a real score, a missing-code problem or a special case. Always inspect the data before deleting observations.

Advertisement
Google AdSense middle placement reserved here

Dataset and Variables Used

This guide uses the student-por.csv student performance dataset with 649 rows. The main outcome is G3, which represents final grade. The analysis also uses G1, G2, age, absences, study time, failures, family relationship, free time, going out, weekday alcohol use, weekend alcohol use and health as numeric variables for IQR comparison.

ItemVariableRole in this IQR guide
First-period gradeG1Used to compare grade spread before G3.
Second-period gradeG2Used to compare middle grade spread before final grade.
Final gradeG3Main numeric outcome for quartiles, IQR and Tukey fences.
AbsencesabsencesUsed to show high-end outliers and a wider central spread.
Study timestudytimeUsed for G3 group box plots and central-spread comparison.
Failure groupfailures / failure_groupUsed to show how prior failures shift the G3 median and IQR.
School groupschoolUsed to compare G3 median and IQR between GP and MS schools.

External dataset source: UCI Machine Learning Repository: Student Performance dataset.

Verified Interquartile Range Results

The R, Python and SPSS outputs show the same main pattern. G3 has Q1 = 10, median = 12, Q3 = 14 and IQR = 4. Absences has the widest IQR among the listed numeric variables, with Q1 = 0, median = 2, Q3 = 6 and IQR = 6. G1 and G2 each have IQR = 3, while G3 has a slightly wider central spread.

VariableNQ1MedianQ3IQRLower fenceUpper fencePossible outliersOutlier %
G164910.0011.0013.003.005.5017.50162.47
G264910.0011.0013.003.005.5017.50253.85
G364910.0012.0014.004.004.0020.00162.47
age64916.0017.0018.002.0013.0021.0010.15
absences6490.002.006.006.00-9.0015.00213.24
studytime6491.002.002.001.00-0.503.50355.39
failures6490.000.000.000.000.000.0010015.41

The failures variable needs careful interpretation because Q1, median and Q3 are all zero. This does not mean the variable has no information. It means at least 75% of students have zero failures, so the middle 50% is concentrated at zero. Values above zero become possible outliers by the strict 1.5 × IQR rule, but they are also meaningful category values.

G3 Interquartile Range by Groups

Grouping variableGroup levelNQ1MedianQ3IQRLower fenceUpper fencePossible outliers
schoolGP42311.0013.0014.003.006.5018.506
schoolMS2269.0011.0013.004.003.0019.0014
sexFemale38310.0012.0014.004.004.0020.007
sexMale26610.0011.0013.003.005.5017.5015
studytime<2 hours21210.0011.0013.003.005.5017.5010
studytime2 to 5 hours30510.0012.0014.004.004.0020.008
studytime5 to 10 hours9712.0013.0015.003.007.5019.500
studytime>10 hours3511.0013.0015.004.005.0021.000
failure0 failures54911.0012.0014.003.006.5018.5010
failure1 failure708.0010.0010.002.005.0013.009
failure2 failures167.759.5010.002.254.3813.382
failure3+ failures148.008.5010.002.005.0013.001

Chart-by-Chart Interpretation of the Interquartile Range Analysis

This section explains the uploaded Python and R charts. Python charts use a clear publication layout, while R charts confirm the same quartile, IQR and outlier-fence patterns in a second software workflow.

Chart 1: G3 Quartiles and IQR Box Plot

Python G3 quartiles and interquartile range box plot
Python chart showing Q1 = 10, median = 12, Q3 = 14 and IQR = 4 for G3 final grade.
R G3 quartiles and interquartile range box plot
R chart confirming the G3 quartile structure with Q1, median and Q3 markers.

Specific interpretation: The G3 box shows that the middle half of final grades lies between 10 and 14. The median is 12. The lower fence is 4, and the upper fence is 20. The plotted low values show why an IQR-based outlier check is useful before making decisions from the mean alone.

Decision from Chart 1: The central grade spread is moderate. The main outlier concern is low G3 scores, not high G3 scores.

Chart 2: Interquartile Range Across Numeric Variables

Python IQR comparison across numeric variables
Python chart comparing IQR values across grades, absences and ordinal numeric variables.
R IQR comparison across numeric variables
R chart confirming the ranking of IQR values across numeric variables.

Specific interpretation: Absences has the largest IQR at 6, meaning the middle 50% of absence counts is wider than the middle 50% of grade scores. G3 has IQR = 4. G1, G2 and health have IQR = 3. Variables such as studytime, freetime, family relationship and weekday alcohol use have smaller IQR values because they are ordinal variables with limited scale ranges.

Decision from Chart 2: Absences is the most spread-out central variable, while G3 has the widest central grade spread among G1, G2 and G3.

Chart 3: Grade Quartiles for G1, G2 and G3

Python quartile comparison for G1 G2 and G3
Python chart showing how Q1, median and Q3 change across G1, G2 and G3.
R quartile comparison for G1 G2 and G3
R chart confirming that G3 has a slightly wider central spread than G1 and G2.

Specific interpretation: G1 and G2 both have Q1 = 10, median = 11 and Q3 = 13, so their IQR is 3. G3 has Q1 = 10, median = 12 and Q3 = 14, so its IQR is 4. This means the final grade distribution is slightly wider in the central 50% than the earlier grade periods.

Decision from Chart 3: Central final-grade variation increases slightly by G3, and the median also rises from 11 to 12.

Chart 4: G3 Distribution by School

Python G3 IQR by school box plot
Python box plot comparing G3 median, IQR and outliers across GP and MS schools.
R G3 IQR by school box plot
R box plot confirming school-based differences in central G3 spread.

Specific interpretation: GP has Q1 = 11, median = 13, Q3 = 14 and IQR = 3. MS has Q1 = 9, median = 11, Q3 = 13 and IQR = 4. GP therefore has a higher central final-grade band, while MS has a wider middle spread.

Decision from Chart 4: School differences are visible in both center and spread. GP students have a higher G3 median, while MS students show more central variation.

Chart 5: G3 Spread in Binary Groups

Python G3 IQR across binary groups
Python chart comparing G3 IQR across school, sex, internet and romantic-status groups.
R G3 IQR across binary groups
R chart confirming selected binary-group IQR values for G3.

Specific interpretation: Several groups have G3 IQR = 4, including female students, MS school, internet-yes students and both romantic-status groups. Male students, GP school and internet-no students have IQR = 3. These values show that central spread differs slightly across groups, even when the overall G3 IQR is 4.

Decision from Chart 5: IQR is useful because it shows spread differences that are not obvious from the mean alone.

Chart 6: G3 by Study Time

Python G3 IQR by study time box plot
Python box plot showing G3 median and IQR by study-time group.
R G3 IQR by study time box plot
R box plot confirming G3 middle-spread changes by study-time group.

Specific interpretation: Students studying less than 2 hours have median G3 = 11 and IQR = 3. The 2 to 5 hours group has median = 12 and IQR = 4. The 5 to 10 hours group has median = 13 and IQR = 3. The more than 10 hours group also has median = 13 but IQR = 4.

Decision from Chart 6: Higher study-time groups have higher medians, but the spread is not perfectly linear. IQR helps separate center from spread.

Chart 7: G3 by Failure Group

Python G3 IQR by failure group box plot
Python chart showing how prior failures shift the median and middle spread of G3.
R G3 IQR by failure group box plot
R chart confirming that prior failures are associated with lower G3 medians.

Specific interpretation: Students with zero failures have median G3 = 12 and IQR = 3. Students with one failure have median = 10 and IQR = 2. Students with two failures have median = 9.5 and IQR = 2.25. Students with three or more failures have median = 8.5 and IQR = 2.

Decision from Chart 7: Prior failure history shifts the G3 distribution downward. The main change is a lower median, not a wider central spread.

Chart 8: Tukey Outlier Fences for G3

Python Tukey outlier fences for G3
Python chart showing the lower fence, Q1, median, Q3 and upper fence for G3.
R Tukey outlier fences for G3
R chart confirming G3 Tukey fences and possible low-end outliers.

Specific interpretation: The G3 lower fence is 4, and the upper fence is 20. Because the maximum G3 value is 19, there are no high-end outliers using Tukey’s rule. The possible outliers are low-end scores below 4. The summary table reports 16 possible G3 outliers, which is about 2.47% of the dataset.

Decision from Chart 8: Do not remove these scores automatically. Investigate whether they are real low performance scores, data-entry errors or special cases.

Chart 9: Tukey Outlier Fences for Absences

Python Tukey outlier fences for absences
Python chart showing absence quartiles, IQR and high-end outliers.
R Tukey outlier fences for absences
R chart confirming the high-end outlier pattern for school absences.

Specific interpretation: Absences has Q1 = 0, median = 2, Q3 = 6 and IQR = 6. The upper fence is 15, so absence values above 15 are possible high-end outliers. The summary table reports 21 possible absence outliers, about 3.24% of cases.

Decision from Chart 9: Absences is more skewed than G3 and should be interpreted with robust summaries and visual checks.

Chart 10: G3 Histogram with Quartiles

Python G3 histogram with quartile markers
Python histogram showing where Q1, median and Q3 fall inside the G3 distribution.
R G3 histogram with quartile markers
R histogram confirming that the middle 50% of G3 is concentrated between 10 and 14.

Specific interpretation: The histogram shows that many G3 scores cluster around the middle of the grade scale. Quartile markers locate the middle 50% between 10 and 14. The lower tail includes a small number of very low scores, which explains why Tukey’s rule flags low-end outliers.

Decision from Chart 10: Use the histogram with the box plot. The histogram shows distribution shape, while the box plot summarizes quartiles and outliers.

Advertisement
Google AdSense middle placement reserved here

R Code for Interquartile Range

R can calculate quartiles, IQR, Tukey fences, outlier counts, tables, charts, clean SPSS-ready data and PDF reports. The simplified workflow below follows the same logic used for the uploaded R output.

library(readr)
library(dplyr)
library(ggplot2)

folder <- "D:/DATA ANALYSIS/A Basic Descriptive Statistics Guides/Interquartile Range"
data_file <- file.path(folder, "dataset.csv")

charts_dir <- file.path(folder, "R_Output", "charts")
tables_dir <- file.path(folder, "R_Output", "tables")
pdf_dir    <- file.path(folder, "R_Output", "pdf")
clean_dir  <- file.path(folder, "R_Output", "clean_data")

dir.create(charts_dir, recursive = TRUE, showWarnings = FALSE)
dir.create(tables_dir, recursive = TRUE, showWarnings = FALSE)
dir.create(pdf_dir, recursive = TRUE, showWarnings = FALSE)
dir.create(clean_dir, recursive = TRUE, showWarnings = FALSE)

df <- read_csv(data_file, show_col_types = FALSE)

df_clean <- df %>%
  mutate(
    sex = factor(sex, levels = c("F", "M"), labels = c("Female", "Male")),
    internet = factor(internet, levels = c("no", "yes"), labels = c("No", "Yes")),
    romantic = factor(romantic, levels = c("no", "yes"), labels = c("No", "Yes")),
    studytime_group = factor(studytime, levels = c(1, 2, 3, 4),
      labels = c("<2 hours", "2 to 5 hours", "5 to 10 hours", ">10 hours")),
    failure_group = case_when(
      failures == 0 ~ "0 failures",
      failures == 1 ~ "1 failure",
      failures == 2 ~ "2 failures",
      failures >= 3 ~ "3+ failures",
      TRUE ~ NA_character_
    )
  )

write_csv(df_clean, file.path(clean_dir, "interquartile_range_clean_data_for_spss.csv"))

iqr_summary <- function(x) {
  x <- na.omit(as.numeric(x))
  q1 <- as.numeric(quantile(x, 0.25, type = 7))
  med <- median(x)
  q3 <- as.numeric(quantile(x, 0.75, type = 7))
  iqr_value <- q3 - q1
  lower <- q1 - 1.5 * iqr_value
  upper <- q3 + 1.5 * iqr_value
  outliers <- sum(x < lower | x > upper)
  tibble(
    n = length(x),
    q1 = q1,
    median = med,
    q3 = q3,
    iqr = iqr_value,
    lower_fence = lower,
    upper_fence = upper,
    outlier_count = outliers,
    outlier_percent = outliers / length(x) * 100
  )
}

numeric_vars <- c("G1", "G2", "G3", "age", "absences", "studytime",
                  "failures", "famrel", "freetime", "goout", "Dalc", "Walc", "health")

summary_table <- bind_rows(lapply(numeric_vars, function(v) {
  bind_cols(variable = v, iqr_summary(df_clean[[v]]))
}))

write_csv(summary_table, file.path(tables_dir, "interquartile_range_summary.csv"))

# G3 result
g3_result <- iqr_summary(df_clean$G3)
print(g3_result)

# Basic chart
ggplot(df_clean, aes(y = G3)) +
  geom_boxplot() +
  labs(
    title = "Interquartile Range: G3 Quartiles and IQR",
    subtitle = "Q1 = 10, median = 12, Q3 = 14 and IQR = 4.",
    x = "G3 final grade",
    y = "G3"
  )

R interpretation: R confirms that G3 has Q1 = 10, median = 12, Q3 = 14 and IQR = 4. It also confirms that absences has the widest IQR among the listed numeric variables.

Python Code for Interquartile Range

Python is useful for automatic IQR reporting because it can calculate values, save clean SPSS-ready data, create publication-ready charts and export summary tables in one workflow.

from pathlib import Path
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

MAIN_FOLDER = Path(r"D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range")

CHARTS_DIR = MAIN_FOLDER / "Python_Output" / "charts"
TABLES_DIR = MAIN_FOLDER / "Python_Output" / "tables"
PDF_DIR = MAIN_FOLDER / "Python_Output" / "pdf"
CLEAN_DIR = MAIN_FOLDER / "Python_Output" / "clean_data"

for folder in [CHARTS_DIR, TABLES_DIR, PDF_DIR, CLEAN_DIR]:
    folder.mkdir(parents=True, exist_ok=True)

candidate_files = [
    MAIN_FOLDER / "dataset.csv",
    MAIN_FOLDER / "dataset(1).csv",
    MAIN_FOLDER / "student-por.csv",
    MAIN_FOLDER / "clean data set.csv",
    MAIN_FOLDER / "clean_data.csv",
]

existing_files = [p for p in candidate_files if p.exists()]
if existing_files:
    DATA_FILE = existing_files[0]
else:
    csv_files = list(MAIN_FOLDER.glob("*.csv"))
    if not csv_files:
        raise FileNotFoundError("No CSV dataset found in the Interquartile Range folder.")
    DATA_FILE = csv_files[0]

df = pd.read_csv(DATA_FILE)

df_clean = df.copy()
df_clean["sex"] = df_clean["sex"].map({"F": "Female", "M": "Male"}).fillna(df_clean["sex"])
df_clean["internet"] = df_clean["internet"].map({"no": "No", "yes": "Yes"}).fillna(df_clean["internet"])
df_clean["romantic"] = df_clean["romantic"].map({"no": "No", "yes": "Yes"}).fillna(df_clean["romantic"])
df_clean["studytime_group"] = df_clean["studytime"].map({
    1: "<2 hours",
    2: "2 to 5 hours",
    3: "5 to 10 hours",
    4: ">10 hours"
}).fillna(df_clean["studytime"].astype(str))

def failure_label(x):
    if pd.isna(x):
        return np.nan
    if x == 0:
        return "0 failures"
    if x == 1:
        return "1 failure"
    if x == 2:
        return "2 failures"
    return "3+ failures"

df_clean["failure_group"] = df_clean["failures"].apply(failure_label)

clean_csv = CLEAN_DIR / "interquartile_range_clean_data_for_spss.csv"
df_clean.to_csv(clean_csv, index=False)

def iqr_summary(series):
    x = pd.to_numeric(series, errors="coerce").dropna()
    q1 = x.quantile(0.25)
    med = x.median()
    q3 = x.quantile(0.75)
    iqr_value = q3 - q1
    lower = q1 - 1.5 * iqr_value
    upper = q3 + 1.5 * iqr_value
    outliers = ((x < lower) | (x > upper)).sum()
    return {
        "n": len(x),
        "q1": q1,
        "median": med,
        "q3": q3,
        "iqr": iqr_value,
        "lower_fence": lower,
        "upper_fence": upper,
        "outlier_count": int(outliers),
        "outlier_percent": outliers / len(x) * 100
    }

numeric_vars = ["G1", "G2", "G3", "age", "absences", "studytime",
                "failures", "famrel", "freetime", "goout", "Dalc", "Walc", "health"]

summary = pd.DataFrame([
    {"variable": v, **iqr_summary(df_clean[v])}
    for v in numeric_vars
])

summary.to_csv(TABLES_DIR / "interquartile_range_summary.csv", index=False)

g3_result = iqr_summary(df_clean["G3"])
print(g3_result)

# Basic G3 box plot
fig, ax = plt.subplots(figsize=(13, 8))
ax.boxplot(pd.to_numeric(df_clean["G3"], errors="coerce").dropna(), vert=False)
ax.set_title("Interquartile Range: G3 Quartiles and IQR")
ax.set_xlabel("G3 final grade")
fig.savefig(CHARTS_DIR / "chart_01_python_g3_quartiles_iqr_boxplot.png", dpi=200, bbox_inches="tight")
plt.close(fig)

# PDF report container
pdf_file = PDF_DIR / "Interquartile-Range-Python-Output-Report.pdf"
with PdfPages(pdf_file) as pdf:
    fig, ax = plt.subplots(figsize=(13, 8))
    ax.axis("off")
    ax.text(0.05, 0.90, "Interquartile Range Output Summary", fontsize=22, fontweight="bold")
    ax.text(0.05, 0.80, f"G3 Q1={g3_result['q1']}, median={g3_result['median']}, Q3={g3_result['q3']}, IQR={g3_result['iqr']}", fontsize=14)
    pdf.savefig(fig, bbox_inches="tight")
    plt.close(fig)

Python output note: Run Python before SPSS. The Python script creates the clean SPSS-ready CSV file, output folders, charts, tables and PDF report structure. SPSS then uses the clean CSV and exports the SPSS PDF into the project folder.

SPSS Syntax and Interpretation for Interquartile Range

SPSS can calculate quartiles through Frequencies and can summarize medians through Means. The uploaded SPSS PDF output includes frequency tables, descriptive statistics, percentile output, group medians and manual IQR summary tables.

The uploaded SPSS output file is available below:

View Interquartile Range SPSS Output PDF

SPSS Menu Method

NeedSPSS menu pathOutput to read
Quartiles and medianAnalyze → Descriptive Statistics → Frequencies → Statistics25th percentile, median and 75th percentile.
Box plot and outliersGraphs → Chart Builder → BoxplotBox, whiskers and possible outlier points.
Group mediansAnalyze → Compare Means → MeansN, mean, standard deviation, median, minimum and maximum by group.
Manual Tukey fencesCompute from Q1 and Q3Lower fence, upper fence and possible outlier count.

SPSS Syntax Example with PDF Export

SET PRINTBACK=ON MPRINT=ON DECIMAL=DOT.
SET UNICODE=ON.

HOST COMMAND=['cmd /c if not exist "D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range\Python_Output\pdf" mkdir "D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range\Python_Output\pdf"'].

GET DATA
 /TYPE=TXT
 /FILE='D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range\Python_Output\clean_data\interquartile_range_clean_data_for_spss.csv'
 /ENCODING='UTF8'
 /DELCASE=LINE
 /DELIMITERS=","
 /QUALIFIER='"'
 /ARRANGEMENT=DELIMITED
 /FIRSTCASE=2
 /VARIABLES=
 school A8
 sex A12
 age F8.2
 address A8
 famsize A8
 Pstatus A8
 Medu F8.2
 Fedu F8.2
 Mjob A20
 Fjob A20
 reason A20
 guardian A20
 traveltime F8.2
 studytime F8.2
 failures F8.2
 schoolsup A8
 famsup A8
 paid A8
 activities A8
 nursery A8
 higher A8
 internet A8
 romantic A8
 famrel F8.2
 freetime F8.2
 goout F8.2
 Dalc F8.2
 Walc F8.2
 health F8.2
 absences F8.2
 G1 F8.2
 G2 F8.2
 G3 F8.2
 studytime_group A20
 failure_group A20.
CACHE.
EXECUTE.

DATASET NAME InterquartileRangeMain WINDOW=FRONT.

TITLE "Interquartile Range: Five-Number Summary and Quartiles".

FREQUENCIES VARIABLES=G1 G2 G3 age absences studytime failures famrel freetime goout Dalc Walc health
 /FORMAT=NOTABLE
 /PERCENTILES=25 50 75
 /STATISTICS=MINIMUM MAXIMUM MEAN MEDIAN STDDEV RANGE
 /ORDER=ANALYSIS.

MEANS TABLES=G3 BY school sex internet romantic studytime failures
 /CELLS=COUNT MEAN STDDEV MEDIAN MIN MAX.

OUTPUT SAVE
 OUTFILE='D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range\Python_Output\pdf\Interquartile-Range-SPSS-Output.spv'
 LOCK=NO.

OUTPUT EXPORT
 /CONTENTS EXPORT=ALL LAYERS=PRINTSETTING MODELVIEWS=PRINTSETTING
 /PDF DOCUMENTFILE='D:\DATA ANALYSIS\A Basic Descriptive Statistics Guides\Interquartile Range\Python_Output\pdf\Interquartile-Range-SPSS-Output.pdf'
 /EMBEDBOOKMARKS=YES
 /EMBEDFONTS=YES.

Excel Method for Interquartile Range

Excel can calculate IQR directly with quartile formulas. It is useful when you need a simple teaching method, quick verification or a small manual report.

Excel Steps for IQR

StepExcel actionFormula idea
1Place the G3 scores in one column.Example range: A2:A650
2Calculate Q1.=QUARTILE.INC(A2:A650,1)
3Calculate median.=MEDIAN(A2:A650)
4Calculate Q3.=QUARTILE.INC(A2:A650,3)
5Calculate IQR.=Q3_cell-Q1_cell
6Calculate Tukey fences.=Q1_cell-1.5*IQR_cell and =Q3_cell+1.5*IQR_cell
7Flag possible outliers.=IF(OR(A2<lower_fence,A2>upper_fence),"Possible outlier","Normal")

Excel Result for G3

Using the G3 column, Excel should return Q1 = 10, median = 12, Q3 = 14 and IQR = 4. The lower fence is 4 and the upper fence is 20. Any G3 value below 4 is flagged as a possible low-end outlier.

Download Output and Resources

The SPSS PDF output and dataset source are available below. Use the SPSS output for formal tables and use the Python and R charts for visual interpretation of quartiles, IQR and outlier fences.

APA Style Reporting for Interquartile Range

An IQR report should include the median, Q1, Q3, IQR and outlier-fence interpretation when relevant. For skewed variables, report median and IQR together instead of relying only on mean and standard deviation.

APA-style report for G3: The final grade variable had a median of 12, with the middle 50% of scores falling between 10 and 14, IQR = 4. Tukey’s 1.5 × IQR rule produced a lower fence of 4 and an upper fence of 20, identifying 16 possible low-end outliers.

APA-style report for absences: Absences were positively skewed, with a median of 2 and an interquartile range from 0 to 6, IQR = 6. Values above 15 were flagged as possible high-end outliers using Tukey’s rule.

APA-style report for school groups: GP students had a higher median G3 score than MS students. The GP group had median = 13 and IQR = 3, while the MS group had median = 11 and IQR = 4, suggesting a lower and slightly wider central final-grade distribution in the MS group.

Short report:
The G3 final grade distribution had Q1 = 10, median = 12, Q3 = 14 and IQR = 4. Tukey fences were 4 and 20. Sixteen G3 values were flagged as possible low-end outliers, so the IQR and box plot should be reported alongside the mean and standard deviation.

When Should You Use Interquartile Range?

Use Interquartile Range when you need a robust measure of spread. It is especially useful when the data contain skewness, extreme values, unusual low scores, unusual high scores or ordinal numeric scales.

Analysis situationUse IQR becauseRelated method
Skewed numeric dataIQR is less affected by the tail than standard deviation.Histogram Interpretation
Box plot reportingThe box itself represents Q1 to Q3.Box Plot Interpretation
Outlier detectionTukey fences use 1.5 × IQR.Five-Number Summary
Before parametric testsIQR helps you understand spread and possible outliers before testing.Levene Test
Ordinal numeric scalesIQR describes central spread without over-interpreting the mean.Descriptive Statistics

If your next analysis compares group means, check variance assumptions with Levene Test, Brown-Forsythe Test or Cochran C Test. If your analysis depends on normality, support IQR interpretation with Q-Q Plot Normality Check, Q-Q Plot Normality Check, P-P Plot Normality Check, D’Agostino-Pearson Test, Kolmogorov-Smirnov Test, Lilliefors Test, Ryan-Joiner Test or Cramer-von Mises Test.

References and Related Guides

Interquartile Range connects with descriptive statistics, outlier detection, normality testing, transformations, group comparison, repeated-measures assumptions and regression diagnostics. These related guides can support the next step of analysis:

Related guideWhy it helps
Descriptive StatisticsExplains the wider set of summary measures around IQR.
Five-Number SummaryDirectly supports minimum, Q1, median, Q3 and maximum reporting.
Frequency DistributionShows how values are distributed before quartiles are interpreted.
Histogram InterpretationHelps explain the shape behind IQR and quartiles.
Box Plot InterpretationExplains the visual meaning of Q1, median, Q3, whiskers and outliers.
Coefficient of VariationUseful when spread needs to be compared relative to the mean.
Confidence IntervalUseful when reporting uncertainty around estimated values.
Effect SizePairs with IQR when practical group differences need interpretation.
Central Limit TheoremExplains why large-sample averages can still behave well even when raw values are skewed.
Reciprocal TransformationSupports transformation decisions when extreme skewness affects analysis.
Cross TabulationUseful when numeric IQR findings are compared with categorical group patterns.
One-Tailed T TestGroup comparisons should be supported by descriptive spread and outlier checks.
One-Sample Z TestConnects one-sample inference with descriptive center and spread.
One-Proportion Z TestUseful when analysis changes from numeric spread to proportions.
Mauchly’s Test of SphericityRelevant when the same outcome is measured repeatedly and repeated-measures assumptions are checked.
Greenhouse-Geisser CorrectionSupports repeated-measures analysis when sphericity is violated.
Goldfeld-Quandt TestChecks changing variance in regression contexts where spread matters.
Ramsey RESET TestUseful after descriptive analysis when regression specification needs checking.
Clinical Trial Data Analysis Using RClinical reporting often uses median and IQR for skewed outcomes.

External references: UCI Student Performance dataset, IBM SPSS Statistics, R Project, and Python.

FAQs About Interquartile Range

What is Interquartile Range in simple words?

Interquartile Range is the spread of the middle 50% of values. It is calculated as Q3 minus Q1.

What is the IQR formula?

The formula is IQR = Q3 – Q1. Q1 is the 25th percentile, and Q3 is the 75th percentile.

What is the G3 Interquartile Range in this guide?

For G3 final grade, Q1 = 10, median = 12, Q3 = 14 and IQR = 4.

How are Tukey outlier fences calculated?

The lower fence is Q1 – 1.5 × IQR, and the upper fence is Q3 + 1.5 × IQR. Values outside these fences are possible outliers.

What are the Tukey fences for G3?

For G3, the lower fence is 4 and the upper fence is 20. Values below 4 are possible low-end outliers.

Is IQR better than standard deviation?

IQR is better when the data are skewed or contain outliers. Standard deviation is useful when the distribution is roughly symmetric and the mean is a good center measure.

Can I calculate IQR in Excel?

Yes. Use QUARTILE.INC or QUARTILE.EXC to calculate Q1 and Q3, then subtract Q1 from Q3.

Why does the failures variable have IQR = 0?

Because Q1, median and Q3 are all zero. Most students have zero past failures, so the middle 50% of the variable is concentrated at zero.

Should possible outliers be deleted?

No. Tukey fences identify possible outliers, not automatic errors. Check the source, meaning and influence of the values before deciding what to do.

What chart is best for Interquartile Range?

A box plot is the best visual chart for IQR because the box directly shows Q1, median and Q3. A histogram is useful beside it because it shows the full distribution shape.

Advertisement
Google AdSense bottom placement reserved here

Need help applying this to your own data?

Salar Cafe can help interpret output, clean datasets, review assumptions, build dashboards and explain statistical results ethically.

Need help interpreting your data analysis results?

Contact Salar Cafe
Engr. Muhammad Yar Saqib author profile photo

Engr. Muhammad Yar Saqib

WhatsApp Get Data Analysis Help