英文:
How to plot the Lorenz curve in R
问题
我想为给定的概率密度函数绘制洛伦兹曲线。
L=function(x,a,l,b)
{
term1=exp(-l*x-(b*x)^a)
term2=a*l*(b*x)^a
term3=a*b*(1+l)*((b*x)^(a-1))
term4=(l^2)*(1+x)
pdf=(term1/(1+l))*(term2+term3+term4)
return(pdf)
}
给定a=l=b=1。是否有人可以帮助在R中执行这个任务。
累积分布函数(CDF)由以下代码给出:
Cdf=function(x,a,l,b)
{
term5=(1+l+l*x)/(1+l)
cdf=1-term5*term4
return(cdf)
}
英文:
I would like to plot Lorenz curve for the given pdf
L=function(x,a,l,b)
{
term1=exp(-l*x-(b*x)^a)
term2=a*l*(b*x)^a
term3=a*b*(1+l)*((b*x)^(a-1))
term4=(l^2)*(1+x)
pdf=(term1/(1+l))*(term2+term3+term4)
return(pdf)
}
Given a=l=b=1. Can anyone help to do this in R.
CDF is given by
Cdf=function(x,a,l,b)
{
term5=(1+l+l*x)/(1+l)
cdf=1-term5*term4
return(cdf)
}
答案1
得分: 4
Your PDF is f(x) = e^(-2*x)/2 * (3+2*x)
. It is defined on (0, infinity)
(I checked the integral with Wolfram). We will need its average which is 5/8 (=0.625
) according to Wolfram.
Wolfram also provides the CDF (which is not the one you give):
F(x) = -e^(-2*x)/2 * (x+2) + 1.
Wolfram also provides the solution of F(x) = p
, that is to say the quantile function. It is
Q(p) = -W(4*(p - 1)/e^4)/2 - 2
where W
is the Lambert W
function.
Now we have to integrate Q
. Again, Wolfram is successful:
Now we have everything needed.
英文:
Your PDF is f(x) = e^(-2*x)/2 * (3+2*x)
. It is defined on (0, infinity)
(I checked the integral with Wolfram). We will need its average which is 5/8 (=0.625
) according to Wolfram.
Wolfram also provides the CDF (which is not the one you give):
F(x) = -e^(-2*x)/2 * (x+2) + 1.
Wolfram also provides the solution of F(x) = p
, that is to say the quantile function. It is
Q(p) = -W(4*(p - 1)/e^4)/2 - 2
where W
is the Lambert W
function.
Now we have to integrate Q
. Again, Wolfram is successful:
Now we have everything needed.
library(lamW)
H0 <- function(p) {
u <- 4*(p - 1)/exp(4)
(1 - p) * (lambertWm1(u)^2 - lambertWm1(u) + 1) / (2 * lambertWm1(u)) - 2*p
}
Lorenz <- function(p) {
(H0(p) - H0(0)) / 0.625
}
curve(Lorenz(x), from = 0, to = 1)
This looks like a Lorenz curve.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论