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

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

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.

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

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

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

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)

如何在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:

确定