1
$\begingroup$

I am trying to evaluate this integral: \begin{align*} \alpha_{2}=\int_{-\infty}^{1.645}\left[1-\Phi\left(\frac{\sqrt{25}}{\sqrt{15}} 1.645-\frac{\sqrt{10}}{\sqrt{15}} z_{1}\right)\right] \phi\left(z_{1}\right) d z_{1} \end{align*} where $\Phi$ is the Normal CDF and $\phi$ is the normal PDF. I know that the answer should be 0.03325.

I used the following code, but it doesn't converge to an answer. Any suggestions?

pdf[x_] := PDF[NormalDistribution[0, 1], x]

cdf[x_] := CDF[NormalDistribution[0, 1], x]

NIntegrate[ 1 - cdf[Sqrt[25]/Sqrt[15] 1.645 - Sqrt[10]/Sqrt[15] x]* pdf[x], {x, -Infinity, 1.645}]

which returns

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {-8.16907*10^224}. NIntegrate obtained 8.582639123060543`15.954589770191005*^27949 and 8.582639123060543`15.954589770191005*^27949 for the integral and error estimates.

The following code in R gives me the correct answer:

inside <- function(z1, n1, n2, cv) {
  nt <- n1 + n2
  (1 - pnorm(sqrt(nt/n2) * cv - sqrt(n1/n2) * z1)) * dnorm(z1)
}

additional.error <- function(n1, n2, cv) {
  integrate(inside, lower = -Inf, upper = cv, n1 = n1, n2 = n2, cv = 1.645)$value
}

additional.error(n1 = 10, n2 = 15, cv = qnorm(0.95))
```
$\endgroup$
3
$\begingroup$

I think you forgot some parentheses:

NIntegrate[(1 - cdf[Sqrt[25]/Sqrt[15] 1.645 - Sqrt[10]/Sqrt[15] x])*
  pdf[x], {x, -Infinity, 1.645}]

(*  0.0332387  *)
$\endgroup$
1
  • $\begingroup$ Oops, you are right -- thank you! $\endgroup$ – 876868587 Feb 14 at 3:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.