Search code examples
rintegralnumerical-integrationcalculus

Integrating in R


I am trying to compute L(psi) as given here in R. I have the following values.

nb <- 100
tb <- 25
ns <- 90
ts <- 15
A0 <- 1
S_norm <- 0.4

R <-tb/ts
y_meas <- (ns-nb/R)/A0
sigma_meas = sqrt(ns+(nb+1)/R^2)/A0

I am very confused on how I can integrate L(psi), say from -10 to 10. Because I am integrating with respect to log A.


Solution

  • You can substitute for logA and for a fixed value of psi you can integrate as follows:

    enter image description here

    psi <- 5
    integrate(function(x) exp(-0.5*(((x/A0)/S_norm)^2 + ((psi-y_meas*A0/exp(x))/sigma_meas)^2)),
                                                                                       -10, 10)
    # 0.1775989 with absolute error < 6.6e-05