楼主: webgu
6289 3

[学习分享] 三分位数的求解: SAS , R, Matlab 均不一致 [推广有奖]

贵宾

学科带头人

95%

还不是VIP/贵宾

-

TA的文库  其他...

Python与统计

SAS与统计

威望
2
论坛币
102549 个
通用积分
3.4687
学术水平
475 点
热心指数
493 点
信用等级
434 点
经验
62369 点
帖子
1555
精华
4
在线时间
2201 小时
注册时间
2009-5-4
最后登录
2025-12-25

初级学术勋章 初级热心勋章 初级信用勋章 中级学术勋章 中级热心勋章 中级信用勋章

楼主
webgu 发表于 2015-1-20 20:11:04 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
一串数字:1 1 1 2 3 3 6 6 6 6  8 8
求其三分位数,发现 SAS , R, Matlab给出的结果均不一样。
难道各软件的算法不同?

1. SAS
SAS.jpg

2. R

R.jpg

3. Matlab
matlab.jpg

附SAS Code:

  1. data tmp;
  2.   input w@@;
  3. datalines;
  4. 1 1 1 2 3 3 6 6 6 6  8 8
  5. ;
  6. run;

  7. proc univariate data=tmp;
  8.         var w;
  9.         output out=pct pctlpts=33.3333  66.6666 pctlpre=p;
  10. run;

  11. proc print data=pct;
  12. run;
复制代码



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB matla atlab Mat Atl 软件

SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

沙发
pobel 在职认证  发表于 2015-1-21 08:31:13
33.3333 和66.6666应该还不足以让SAS明白我们想要的是3分位数。

data tmp;
  input w@@;
datalines;
1 1 1 2 3 3 6 6 7 7 8 8
;
run;
%let p33=%sysevalf(100/3);
%let p66=%sysevalf(200/3);


proc univariate data=tmp;
        var w;
       output out=pct pctlpts=&p33  &p66 pctlpre=p;
run;

proc print data=pct;
run;
已有 1 人评分经验 论坛币 收起 理由
webgu + 100 + 100 精彩帖子

总评分: 经验 + 100  论坛币 + 100   查看全部评分

藤椅
pobel 在职认证  发表于 2015-1-21 08:40:21
其他能够影响到结果的就是percentile的计算方法了。SAS里是PCTLDEF=这个选项
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
webgu + 100 + 100 + 1 + 1 + 1 NICE!

总评分: 经验 + 100  论坛币 + 100  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

板凳
webgu 发表于 2015-1-21 08:48:54
pobel 发表于 2015-1-21 08:31
33.3333 和66.6666应该还不足以让SAS明白我们想要的是3分位数。

data tmp;
多谢pobel兄。

好久不见啊,论坛的时代好像过去了,大家都很少上来了。

我后来又查了下R 的help,发现有9种算法,第三种是SAS的算法。

飞信截图20150121084401.jpg

types
quantile returns estimates of underlying distribution quantiles based on one or two order statistics from the supplied elements in x at probabilities in probs. One of the nine quantile algorithms discussed in Hyndman and Fan (1996), selected by type, is employed.
All sample quantiles are defined as weighted averages of consecutive order statistics. Sample quantiles of type i are defined by:

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

where 1 ≤ i ≤ 9, (j-m)/n ≤ p < (j-m+1)/n, x[j] is the jth order statistic, n is the sample size, the value of γ is a function of j = floor(np + m) and g = np + m - j, and m is a constant determined by the sample quantile type.

Discontinuous sample quantile types 1, 2, and 3
For types 1, 2 and 3, Q(p) is a discontinuous function of p, with m = 0 when i = 1 and i = 2, and m = -1/2 when i = 3.

Type 1
Inverse of empirical distribution function. γ = 0 if g = 0, and 1 otherwise.

Type 2
Similar to type 1 but with averaging at discontinuities. γ = 0.5 if g = 0, and 1 otherwise.

Type 3
SAS definition: nearest even order statistic. γ = 0 if g = 0 and j is even, and 1 otherwise.

Continuous sample quantile types 4 through 9
For types 4 through 9, Q(p) is a continuous function of p, with gamma = g and m given below. The sample quantiles can be obtained equivalently by linear interpolation between the points(p[k],x[k]) where x[k] is the kth order statistic. Specific expressions for p[k] are given below.

Type 4m = 0. p[k] = k / n. That is, linear interpolation of the empirical cdf.

Type 5m = 1/2. p[k] = (k - 0.5) / n. That is a piecewise linear function where the knots are the values midway through the steps of the empirical cdf. This is popular amongst hydrologists.

Type 6
m = p
. p[k] = k / (n + 1). Thus p[k] = E[F(x[k])]. This is used by Minitab and by SPSS.

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

Type 8
m = (p+1)/3. p[k] = (k - 1/3) / (n + 1/3). Then p[k] =~ median[F(x[k])]. The resulting quantile estimates are approximately median-unbiased regardless of the distribution of x.

Type 9
m = p/4 + 3/8. p[k] = (k - 3/8) / (n + 1/4). The resulting quantile estimates are approximately unbiased for the expected order statistics if x is normally distributed.
Further details are provided in Hyndman and Fan (1996) who recommended type 8. The default method is type 7, as used by S and by R < 2.0.0.
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 17:25