【问题标题】:Integration of Logistic distribution in RR中的Logistic分布集成
【发布时间】:2020-11-01 22:58:37
【问题描述】:

Logistic分布的概率密度函数$f(x) = e^{-x} (1+e^{-x})^{-2}$跨度>

LL_cdf <- function(x) ((1+exp(-x))^(-1) # cumulative distribution function of logistic distribution

LL_pdf <- function(x) ( (exp(-x))*(1+exp(-x))^-2 ) # Probability density function (pdf) of logistic distribution

任何发行版的 pdf 对其支持的集成都必须是一个。我们在其支持 $x \in [-\infty,\infty]$ 上集成了 logistic distribution 的 pdf,但它给出了错误消息。我们在下面的代码中提到了错误消息。为什么物流分布的 pdf 在 R 的支持 $x \in [-\infty,\infty]$ 上没有集成?

integrate( LL_pdf, lower = -Inf, upper = Inf)$value 

Error in integrate(LL_pdf, lower = -Inf, upper = Inf) : 
  non-finite function value

【问题讨论】:

  • integrate( LL_pdf, lower = -Inf, upper = 0) 也失败了。
  • 我得到了 0.5,其实没用,因为我们需要集成超过 $X \in (\infty, \infty)$ @StephanKolassa 的支持
  • 它并非完全没用,因为 PDF 是围绕 0 对称的。
  • integrate( LL_pdf, lower = -Inf, upper = 0) 给你0.5?这很有趣,它暗示了一些奇怪的差异。我在 Windows 10 上运行 R 4.0.2。sessionInfo() 告诉你什么?
  • 你是对的。我正在使用 R 版本 4.0.0 (2020-04-24) @StephanKolassa

标签: r numerical-integration


【解决方案1】:

这与您对密度函数的实现有关,因为它会为较大的负值生成 Inf/Inf = NaN 类型的比率

> LL_pdf(-1000)
[1] NaN

函数的实现应该避免这种数值问题(0/0Inf/Inf)。

一种解决方案是实现对数密度,它在数值上是稳定的,并返回对数密度的指数,从而避免了这种问题:

LL_pdf2 <- Vectorize(function(x){
  log.val <- -x -2*log(1+exp(-x))
  return(exp(log.val))
  })  # Probability density function (pdf) of logistic distribution

然后,你得到,

> LL_pdf2(-1000)
[1] 0
> 
> integrate( LL_pdf2, lower = -Inf, upper = Inf)$value
[1] 1

您可以将这些结果与使用dlogis 获得的结果进行比较

> dlogis(-1000)
[1] 0
> integrate( dlogis, lower = -Inf, upper = Inf)$value
[1] 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 2021-12-13
    • 2018-08-07
    • 2018-09-01
    • 2020-04-13
    • 2014-06-22
    相关资源
    最近更新 更多