【发布时间】:2020-10-19 19:50:12
【问题描述】:
我有以下代码:
library(purrr)
library(dplyr)
library(ineq)
library(ggplot2)
taxations <- c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)
N = 1000000
gamma <- 1/12 #scale parameter
beta <- 0.95#shape parameter
u <- runif(N)
v <- runif(N)
tau <- -gamma*log(u)*(sin(beta*pi)/tan(beta*pi*v)-cos(beta*pi))^(1/beta)
make_lorenz_2 <- function(i, tau) {
newtau = sort(tau)
transfers = i * sort(tau, decreasing = T)
newtau = ((1 - i) * tau) + transfers
OX <- sort(newtau)
CumWealth <- cumsum(OX)/sum(newtau)
PoorPopulation <- c(1:N)/N
index <- c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.99,0.999,0.9999,0.99999,0.999999,1)*N
QQth <- CumWealth[index]
x <- PoorPopulation[index]
data.frame(x,QQth, Gini(newtau))
}
Lorenzdf1 <- purrr::map(taxations, tau = tau, make_lorenz_2) %>%
setNames(taxations) %>%
bind_rows(.id = "taxations")
Lorenzdf1
cols <- c("0" = "black", "0.1"="blue","0.2"="green","0.3"="red", "0.4" = "grey", "0.5" = "pink", "0.6"="yellow","0.7"="brown","0.8"="orange", "0.9" = "purple", "1" = "darkgreen")
g <- ggplot(data=Lorenzdf1, aes(x=x, y=QQth, colour = taxations)) +
geom_point() +
geom_line() +
ggtitle("Lorenz curves after flat taxation") +
xlab("Cumulative share of people from lowest to highest wealth") +
ylab("Cumulative share of wealth") +
scale_color_manual(name="Rate of taxation",values=cols)
这会生成链接图像。一切都很完美,但我不确定是否有些线条没有绘制,或者它们是否只是靠得很近,以至于有些线条不显示。如果有人能澄清一下,那真的很有帮助。
【问题讨论】: