ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > VBA计算四分位数

VBA计算四分位数

作者:绿色风 分类: 时间:2022-08-18 浏览:100
楼主
nothingwmm
  1. Sub t()
  2. arr = Array(1, 35, 4, 13) ‘ 定义一维数组
  3. MsgBox Application.Quartile(arr, 1) ’第一个四分位数
  4. MsgBox Application.Quartile(arr, 2) ’第一个四分位数
  5. MsgBox Application.Quartile(arr, 3) ’第一个四分位数
  6. MsgBox Application.Quartile(arr, 4)‘ 第二个四分位数
  7. End Sub
运行结果:3.25/8.5/ 18.5/35

另一种写法:
  1. Sub t()
  2. Dim Ary, wf As WorksheetFunction
  3. Ary = Array(1, 35, 4, 13)
  4. Set wf = Application.WorksheetFunction
  5. MsgBox wf.Quartile(Ary, 1)
  6. MsgBox wf.Quartile(Ary, 2)
  7. MsgBox wf.Quartile(Ary, 3)
  8. MsgBox wf.Quartile(Ary, 4)
  9. End Sub

计算过程如下:
1.第一个四分位数:

     k=(1/4)*(4-1)+1=1.75,所以 f=0.75 第一个四分位数=第一个值+0.75*(第二个值-第一个值)=1+0.75*(4-1)=3.25
2.第二个四分位数:
     k=(2/4)*(4-1)+1=2.5,所以 f=0.5  第二个四分位数=第二个值+0.75*(第三个值-第二个值)=4+0.5*(13-4)=8.53.第三个四分位数:
     k=(3/4)*(4-1)+1=3.25,所以 f=0.25  第散个四分位数=第三个值+0.75*(第四个值-第三个值)=13+0.25*(35-13)=18.5
4.第四个分位数:
    k=(4/4)*(4-1)+1=4,所以 f=0  第散个四分位数=第四个值+0.75*(第四个值-第三个值)=35
    注意到:其实四分位数当然是最后的那个最大数了。

关于四分位数的说明参考:
1.Find the kth smallest member in the array of values, where:
               k=(quart/4)*(n-1))+1
    If k is not an integer, truncate it but store the fractional portion (f) for use in step 3.
    And where: quart = value between 0 and 4 depending on which quartile you want to find o n = number of values in the array
2. Find the smallest data point in the array of values that is greater than the kth smallest -- the (k+1)th smallest member.
3. Interpolate between the kth smallest and the (k+1)th smallest values:

           Output = a[k]+(f*(a[k+1]-a[k])) a[k] = the kth smallest a[k+1] = the k+1th smallest
2楼
亡者天下
挖宝来了

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap