• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

R:summary() 返回奇怪的 1st Qu

用户头像
it1352
帮助1

问题说明

在可汗学院的概率和统计课程中有一个关于创建盒须图的练习.这是代表正确解决方案的屏幕截图.但是当我尝试在 R 中检查解决方案时,我得到以下信息:

There's an exercise in Khan Academy' Probability and Statistics course on creating box-and-whisker plot. Here's screenshot representing correct solution. But when I tried to check solution in R I got the following:

d <- c(11, 4, 1, 4, 2, 2, 6, 10, 5, 6, 0, 6, 3, 3)
summary(d)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   0.00    2.25    4.00    4.50    6.00   11.00 

您可以看到 1st Qu 的值是 2.25.但正确的值是 2.用 summary() 返回的任何其他值都是正确的.任何想法为什么 summary() 返回错误的结果?

You can see 2.25 value for 1st Qu. But the correct value is 2. Any other values returned with summary() are correct. Any ideas why summary() returns wrong result?

正确答案

#1

简而言之,有许多合理的方法来计算分位数.quantile 函数.

In a nutshell, there are many reasonable ways to compute quantiles. This is evidenced by the nine (!) different methods supported by the quantile function.

summary 没有错,它只是使用了与您期望的方法不同的方法.它可能正在使用默认方法 7(在帮助页面中称为类型 7").与大多数其他方法一样,它在两个相邻值 2 和 3 之间执行线性插值.

summary is not wrong, it is just using a different method to the one you're expecting. It likely is using the default method 7 (called "type 7" in the help page). Like most other methods, it is performing linear interpolation between two adjacent values, 2 and 3.

您可以通过使用适当的 type 参数调用 quantile 来尝试使用其他方法:

You could try experimenting with the other methods by calling quantile with the appropriate type argument:

> quantile(s, type=1)
  0%  25%  50%  75% 100% 
   0    2    4    6   11 

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfffjb
系列文章
更多 icon
同类精品
更多 icon
继续加载