gpt4 book ai didi

math - 解释 R 中的 quantile() 函数

转载 作者:行者123 更新时间:2023-12-03 05:31:12 28 4
gpt4 key购买 nike

我一整天都对 R 分位数函数感到困惑。

我对分位数的工作原理有一个直观的概念,并且拥有硕士学位。在统计数据中,但是天哪,它的文档让我感到困惑。

来自文档:

Q[i](p) = (1 - gamma) x[j] + gamma x[j+1],

到目前为止我都同意。对于类型 i 分位数,它是 x[j] 和 x [j+1] 之间的插值,基于一些神秘常数 gamma

where 1 <= i <= 9, (j-m)/n <= p < (j-m+1)/ n, x[j] is the jth order statistic, n is the sample size, and m is a constant determined by the sample quantile type. Here gamma depends on the fractional part of g = np+m-j.

那么,如何计算j呢?米?

For the continuous sample quantile types (4 through 9), the sample quantiles can be obtained by linear interpolation between the kth order statistic and p(k):

p(k) = (k - alpha) / (n - alpha - beta + 1), where α and β are constants determined by the type. Further, m = alpha + p(1 - alpha - beta), and gamma = g.

现在我真的迷失了。 p 以前是一个常数,现在显然是一个函数。

因此,对于类型 7 分位数,默认值...

Type 7

p(k) = (k - 1) / (n - 1). In this case, p(k) = mode[F(x[k])]. This is used by S.

有人愿意帮我吗?特别是,我对 p 作为函数和常量的表示法感到困惑,到底 m 是什么,现在要计算某些特定 p 的 j。

我希望根据这里的答案,我们可以提交一些修订后的文档,以更好地解释这里发生的事情。

quantile.R source code或输入:quantile.default

最佳答案

你很困惑,这是可以理解的。该文档太糟糕了。我必须回到它基于的论文(Hyndman, R.J.;Fan, Y.(1996 年 11 月)。“统计包中的样本分位数”。美国统计学家 50 (4): 361–365 . doi:10.2307/2684934 )以获得理解。让我们从第一个问题开始。

where 1 <= i <= 9, (j-m)/n <= p < (j-m+1)/ n, x[j] is the jth order statistic, n is the sample size, and m is a constant determined by the sample quantile type. Here gamma depends on the fractional part of g = np+m-j.

第一部分直接来自论文,但文档作者省略了 j = int(pn+m)。这意味着Q[i](p)仅取决于(排序的)观察中最接近p分数的两个顺序统计量。 (对于像我这样不熟悉这个术语的人来说,一系列观察的“顺序统计”是排序后的系列。)

另外,最后一句话是错误的。应该是这样的:

Here gamma depends on the fractional part of np+m, g = np+m-j

至于m,这很简单。 m 取决于选择 9 种算法中的哪一种。因此,就像 Q[i] 是分位数函数一样,m 应该被视为 m[i]。对于算法 1 和 2,m 为 0,对于算法 3,m 为 -1/2,对于其他算法,将在下一部分中介绍。

For the continuous sample quantile types (4 through 9), the sample quantiles can be obtained by linear interpolation between the kth order statistic and p(k):

p(k) = (k - alpha) / (n - alpha - beta + 1), where α and β are constants determined by the type. Further, m = alpha + p(1 - alpha - beta), and gamma = g.

这确实令人困惑。文档中所说的 p(k) 与之前的 p 不同。 p(k)plotting position 。在论文中,作者将其写为 pk,这很有帮助。特别是在 m 的表达式中,p 是原始的 p,并且 m = alpha + p * (1 -阿尔法 - 贝塔)。从概念上讲,对于算法 4-9,点 (pk, x[k]) 被插值为得到解决方案(pQ[i](p))。每种算法仅在 pk 的算法上有所不同。

至于最后一位,R 只是说明 S 使用的内容。

原始论文给出了 6 个“样本分位数所需的属性”函数的列表,并指出了对 #8 的偏好,它满足所有 1 个。#5 满足所有这些,但他们不喜欢其他的理由(它更多的是现象学而非原理)。 #2 是像我这样的非统计极客会考虑的分位数,也是维基百科中描述的内容。

顺便说一句,回应 dreeves answer , Mathematica 的做法截然不同。我想我理解了映射。虽然 Mathematica 更容易理解,但 (a) 使用无意义的参数更容易搬起石头砸自己的脚,(b) 它无法执行 R 的算法 #2。 (这里是 Mathworld's Quantile page ,它指出 Mathematica 无法执行#2,但根据四个参数给出了所有其他算法的更简单的概括。)

关于math - 解释 R 中的 quantile() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/95007/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com