5

让我给你举个例子:

person | salary
----------------
1      | 30'000
2      | 10'000
3      | 15'000
4      | 25'000
5      | 80'000
6      | 56'000
...    | ...

获得此结果的步骤是订购工资,然后创建一个新表,给出从开始到相应行的行/人的份额以及从开始到相应行的工资总和的份额(工资总额)。

然后,只需为人们选择最接近 20% 的那一排,我们就知道他们赚了多少。

这是一个非常标准的问题 - 但由于我不知道如何口头提及它,我无法用谷歌搜索它。

因此,如果有人能告诉我“称之为”什么以及如何在 R 中最简单地计算和绘制它,我将不胜感激 - 所以没有循环和东西。我的直觉告诉我,至少有 5 个包和 10 个函数可以解决这种情况。也许类似于带有固定分位数的 summary() 。

因此,让我们假设上表可用作数据框:

salaries <- data.frame(person = c(1,2,3,...), salary = c(30000,...))

4

1 回答 1

1

使用 -package 中的SLID收入数据集car

library(car)

dat <- SLID[!is.na(SLID$wage),]       # Remove missing values
dat$income <- dat$wage*40*50          # "translate" the wages to their full time annual earnings equivalent.
dat$id <- seq(1,nrow(dat))       

# Create a data.frame with a person ID and their annual income:
keep <- data.frame(id = seq(1, nrow(dat)), 
                   income = dat$income)
keep <- keep[order(keep$income, decreasing = TRUE),]  # Descending ordering according to income
keep$accum <- cumsum(keep$income)                     # Cumulative sum of the descending incomes
keep$pct <- keep$accum/sum(keep$income)*100           # % of the total income

keep$check <- keep$pct<80                      # Check where the % is smaller than 80%
threshold <- min(which(keep$check == FALSE))   # First line where % is larger than 80%
border <- threshold/nrow(keep)*100             # Check which percentile that was
border <- round(border, digits = 2)
paste0(border, "% of the people earn 80% of the income")

#[1] "62.41% of the people earn 80% of the income"

正如我们所期望的那样,经典的 80-20 规则将显示“20% 的人赚取 80% 的收入”。如您所见,此规则不适用于此处..

颠倒的论点:

# The 20% of the people earn X % of total income:

linenr <- ceiling(1/5*nrow(keep))
outcome2 <- round(keep$pct[linenr], digits = 2)
paste0(outcome2, "% of total income is earned by the top 20% of the people")

# [1] "36.07% of total income is earned by the top 20% of the people"

请注意,此处提供的数字并不代表现实世界:)

此外,维基百科有更多关于帕累托原则的信息,也称为 80-20 规则。似乎这条规则出现在多种环境中,例如商业、经济和数学。

于 2016-07-26T21:00:52.160 回答