开始使用免费开始使用

使用 IQR 查找离群值

四分位距(interquartile range,IQR)是另一种衡量离散程度的方法,受离群值影响较小。IQR 也常用于识别离群值。若某个值小于 \(\text{Q1} - 1.5 \times \text{IQR}\) 或大于 $\text{Q3} + 1.5 \times \text{IQR}$,则视为离群值。实际上,ggplot2 箱线图中"须"(whiskers)的长度就是这样计算的。

Diagram of a box plot showing median, quartiles, and outliers

在本练习中,您将计算 IQR 并用它来寻找一些离群值。dplyrggplot2 库已加载,food_consumption 数据可用。

本练习是课程的一部分

R 统计学入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Compute the 25th percentile and 75th percentile of co2_emission
q1 <- quantile(___$___, ___)
q3 <- ___

# Compute the IQR of co2_emission
iqr <- ___
iqr
编辑并运行代码