R:summary() 返回奇怪的 1st Qu [英] R: summary() returns strange 1st Qu

查看:132
本文介绍了R:summary() 返回奇怪的 1st Qu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在可汗学院的概率和统计课程中有一个关于创建盒须图的练习.这是代表正确解决方案的屏幕截图.但是当我尝试在 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?

推荐答案

简而言之,有许多合理的方法来计算分位数.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 

这篇关于R:summary() 返回奇怪的 1st Qu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆