R中的标准正态分位数函数积分

R中的标准正态分位数函数积分,r,integral,numerical-integration,R,Integral,Numerical Integration,我需要计算积分的除法,其中函数q_α(z)是标准正态分布的分位数函数 我有一个关于分母的问题。由于正态标准分布具有齐次性,它是simmetric、continuous等。分母项的积分是否简单?我只需要把这个函数的每个分位数提升到平方,然后继续计算?对吧? 这是我在R中的代码: library(Bolstad) thau=1:99/100 z.standard.quantile=qnorm(thau,0,1) z.standard.quantile.square=qnorm(thau,0,1)

我需要计算积分的除法,其中函数q_α(z)是标准正态分布的分位数函数

我有一个关于分母的问题。由于正态标准分布具有齐次性,它是simmetric、continuous等。分母项的积分是否简单?我只需要把这个函数的每个分位数提升到平方,然后继续计算?对吧?

这是我在R中的代码:

library(Bolstad)

thau=1:99/100
z.standard.quantile=qnorm(thau,0,1)
z.standard.quantile.square=qnorm(thau,0,1)^2

sintegral(thau[1:50],z.standard.quantile[1:50])$value/sintegral(thau[1:50], z.standard.quantile.square[1:50])$value

结果是:
-0.8676396
qnorm
的平方没有问题,但是
qnorm
[0,0.5]
上是无界的(注意
qnorm(0)
-Inf
),因此积分不是有限的

我的第二个想法是,实际上没有必要使用
Bolstad::sintegral
(辛普森规则);R基函数
integrate
就足够了。或者,我们可以离散化
qnorm
并使用梯形规则,因为
qnorm
是一个平滑函数,可以通过线性插值很好地逼近

在你的问题中,我将编写一个计算积分比的函数,但在
l
上有下限:

## using `integrate`
f1 <- function (l) {
  a <- integrate(qnorm, lower = l, upper = 0.5)$value
  b <- integrate(function (x) qnorm(x) ^ 2, lower = l, upper = 0.5)$value
  a / b
  }

## using Trapezoidal rule, with `n` division on interval `[l, 0.5]`
f2 <- function (l, n) {
  x <- seq(l, 0.5, length = n)
  delta <- x[2] - x[1]
  y1 <- qnorm(x)
  y2 <- y1 ^ 2
  a <- sum(y1[-1] + y1[-n]) / 2 * delta
  b <- sum(y2[-1] + y2[-n]) / 2 * delta
  a / b
  }
现在,唯一令人感兴趣的是当
l->0
时的限制行为(在数字意义上)。让我们试试看

l <- 10 ^ (- (1:16))
# [1] 1e-01 1e-02 1e-03 1e-04 1e-05 1e-06 1e-07 1e-08 1e-09 1e-10 1e-11 1e-12
# [13] 1e-13 1e-14 1e-15 1e-16

y1 <- sapply(l, f1)
# [1] -1.2761674 -0.8698411 -0.8096179 -0.7996069 -0.7981338 -0.7979341
# [7] -0.7978877 -0.7978848 -0.7978846 -0.7978846 -0.7978846 -0.7978846
# [13] -0.7978846 -0.7978846 -0.7978846 -0.7978846

## quite a dense grid; takes some time to compute
y2 <- sapply(l, f2, n = 1e+6)
# [1] -1.2761674 -0.8698411 -0.8096179 -0.7996071 -0.7981158 -0.7979137
# [7] -0.7978877 -0.7978834 -0.7978816 -0.7978799 -0.7978783 -0.7978767
# [13] -0.7978750 -0.7978734 -0.7978717 -0.7978700

l@ZheyuanLi但是做
[0.09,0.50]
之间的积分是可以的,例如?我有另一个问题,但我创建了另一个主题。我应该把这个问题纳入这个主题。你怎么认为?
l <- 10 ^ (- (1:16))
# [1] 1e-01 1e-02 1e-03 1e-04 1e-05 1e-06 1e-07 1e-08 1e-09 1e-10 1e-11 1e-12
# [13] 1e-13 1e-14 1e-15 1e-16

y1 <- sapply(l, f1)
# [1] -1.2761674 -0.8698411 -0.8096179 -0.7996069 -0.7981338 -0.7979341
# [7] -0.7978877 -0.7978848 -0.7978846 -0.7978846 -0.7978846 -0.7978846
# [13] -0.7978846 -0.7978846 -0.7978846 -0.7978846

## quite a dense grid; takes some time to compute
y2 <- sapply(l, f2, n = 1e+6)
# [1] -1.2761674 -0.8698411 -0.8096179 -0.7996071 -0.7981158 -0.7979137
# [7] -0.7978877 -0.7978834 -0.7978816 -0.7978799 -0.7978783 -0.7978767
# [13] -0.7978750 -0.7978734 -0.7978717 -0.7978700