在 R 中,atan() 是否提供了优于 pnorm() 的任何计算优势?

Does atan() provide any computational advantage over pnorm() in R?

This article 描述了正态 CDF 的解析近似:

近似使用反正切函数,也是数值近似。我发现 R 中 pnorm()some discussions about the algorithm of arctan functions in general, and it seems pretty convoluted. In comparison, the source code 看起来很简单,尽管它可能没有那么有效。

在 R 中使用 atan() 而不是 pnorm() 是否有任何计算优势,特别是对于大数据和高参数 space 当已经有一堆其他数值计算基于已经关闭普通 PDF 了吗?

谢谢!

出于好奇想看看

首先定义函数

PNORM <- function(x) { 1/(exp(-358/23*x + 111*atan(37*x/294)) + 1) }

然后让我们看一下 [-4, 4]

范围内的差异
x <- seq(-4, 4, .01)
plot(x, pnorm(x)-PNORM(x), type="l", lwd=3, ylab="Difference")

生成此图

所以差异很小,但在某些应用程序中可能还不足以忽略。 YMMV。如果我们看一下计算时间,那么它们大致相等,近似值似乎稍快

> microbenchmark::microbenchmark(pnorm(x), PNORM(x))
Unit: microseconds
     expr    min      lq     mean  median      uq    max neval cld
 pnorm(x) 34.703 34.8785 36.54254 35.1820 38.3150 47.786   100   b
 PNORM(x) 24.293 24.4625 27.07660 24.8875 28.9035 59.216   100  a