简体   繁体   English

计算平均值,不包括当前观察值

[英]Calculate average excluding current observation

How do I calculate a mean (or any other summary statistic) excluding the current observation? 如何计算不包括当前观察值的均值(或任何其他汇总统计量)?

For example, I have following data: 例如,我有以下数据:

i - value - category --类别

1 - 5 - 1 1 - 5 - 1

2 - 5 - 1 2 - 5 - 1

3 - 9 - 1 3 - 9 - 1

4 - 2 - 2 4 - 2 - 2

5 - 2 - 2 5 - 2 - 2

I would like to calculate the mean for each category (egen value_mean = mean(value), by(category)), but exclude the i-th observation: For i=1, for example, the mean value by category 1 would be (5+9)/2. 我想计算每个类别的平均值(egen value_mean = mean(value),by(category)),但不包括第i个观察值:例如,对于i = 1,类别1的平均值为( 5 + 9)/ 2。 For i=3, it would be (5+5)/2. 对于i = 3,它将是(5 + 5)/ 2。 For i=4, it would be 2/1. 对于i = 4,它将为2/1。

There were various threads online matching my question, the closest one being this one , but I do not understand the explanation and I'd require something in Excel, not whatever language that is. 在线上有各种各样与我的问题匹配的主题,最接近的主题是这个主题 ,但是我不明白其解释,因此我需要Excel中的某些功能,而不是任何语言。

My range for data is an entire column, formula so far works and looks like this: 我的数据范围是整个列,到目前为止,公式有效,并且看起来像这样:

=AVERAGEIFS(A:A,D:D,D3,E:E,E3,AP:AP,AP3)

But as you can see it does not exclude the current observation, namely the value in A3. 但是如您所见,它并不排除当前的观察值,即A3中的值。

There ought to be a simple solution, any help is appreciated. 应该有一个简单的解决方案,感谢您的帮助。

Although you could switch to SUMPRODUCT so as to be able to create an explicit reference to the row in which the formula resides (not possible within SUMIF ), I'd probably prefer the slightly longer: 尽管您可以切换到SUMPRODUCT以便能够创建对公式所在行的显式引用(在SUMIF不可能的),但我可能希望稍长一些:

=(SUMIFS(A:A,D:D,D3,E:E,E3,AP:AP,AP3)-A3)/(COUNTIFS(D:D,D3,E:E,E3,AP:AP,AP3)-1)

which retains the advantage that these functions have over SUMPRODUCT , in that arbitrarily large ranges can be referenced with no detriment to performance. 保留了这些功能优于SUMPRODUCT的优点,因为可以引用任意较大的范围,而不会影响性能。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM