如何在R中绘制洛伦兹曲线

huangapple go评论98阅读模式
英文:

How to plot the Lorenz curve in R

问题

我想为给定的概率密度函数绘制洛伦兹曲线。

  1. L=function(x,a,l,b)
  2. {
  3. term1=exp(-l*x-(b*x)^a)
  4. term2=a*l*(b*x)^a
  5. term3=a*b*(1+l)*((b*x)^(a-1))
  6. term4=(l^2)*(1+x)
  7. pdf=(term1/(1+l))*(term2+term3+term4)
  8. return(pdf)
  9. }

给定a=l=b=1。是否有人可以帮助在R中执行这个任务。

累积分布函数(CDF)由以下代码给出:

  1. Cdf=function(x,a,l,b)
  2. {
  3. term5=(1+l+l*x)/(1+l)
  4. cdf=1-term5*term4
  5. return(cdf)
  6. }
英文:

I would like to plot Lorenz curve for the given pdf

  1. L=function(x,a,l,b)
  2. {
  3. term1=exp(-l*x-(b*x)^a)
  4. term2=a*l*(b*x)^a
  5. term3=a*b*(1+l)*((b*x)^(a-1))
  6. term4=(l^2)*(1+x)
  7. pdf=(term1/(1+l))*(term2+term3+term4)
  8. return(pdf)
  9. }

Given a=l=b=1. Can anyone help to do this in R.

CDF is given by

  1. Cdf=function(x,a,l,b)
  2. {
  3. term5=(1+l+l*x)/(1+l)
  4. cdf=1-term5*term4
  5. return(cdf)
  6. }

答案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):

  1. 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

  1. 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):

  1. 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

  1. Q(p) = -W(4*(p - 1)/e^4)/2 - 2

where W is the Lambert W function.

如何在R中绘制洛伦兹曲线

Now we have to integrate Q. Again, Wolfram is successful:

如何在R中绘制洛伦兹曲线

Now we have everything needed.

  1. library(lamW)
  2. H0 <- function(p) {
  3. u <- 4*(p - 1)/exp(4)
  4. (1 - p) * (lambertWm1(u)^2 - lambertWm1(u) + 1) / (2 * lambertWm1(u)) - 2*p
  5. }
  6. Lorenz <- function(p) {
  7. (H0(p) - H0(0)) / 0.625
  8. }
  9. curve(Lorenz(x), from = 0, to = 1)

如何在R中绘制洛伦兹曲线

This looks like a Lorenz curve.

huangapple
  • 本文由 发表于 2023年5月22日 00:27:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300886.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定