[Math] Multivariate Newton-Raphson in R language (equations that contains integral)

computer sciencenewton raphsonregression

I am trying to apply multivariate Newton-Raphson method using R language. However I have encountered some difficulties to define functions which includes the integral in the equations. For instance, the general form of the equations look like below.
\begin{align}
F_{a}(a,b) = \int_{\text{all}}f(z;a,b)dz – a &= 0, \\
F_{b}(a,b) = \int_{\text{all}}g(z;a,b)dz – b &= 0.
\end{align}

The R code that I applied is written on the bottom.

integrand_f <- function(z) { some function f(z;a,b) }
integrand_g <- function(z) { some function g(z;a,b) }

F_a <- function(a,b) { integrate(integrand_f,-Inf,Inf)$value - a }
F_b <- function(a,b) { integrate(integrand_g,-Inf,Inf)$value - b }

Apparently, when I substitute initial values $(a_{0},b_{0})$ in both $F_{a}$ and $F_{b}$, the output that I get is $-a_{0}$ and $-b_{0}$, respectively. In other words, the integral parts of both functions do not give a meaningful output but zero. How should I fix this problem?

NEW ATTEMPT

Apparently, if I apply Vectorize function:

F_a <- Vectorize(function(a,b) { integrate(integrand_f,-Inf,Inf)$value - a })

I get some non-trivial value. Perhaps could this be a correct way to compute?

Best Answer

pp.13-16 here discuss a library function that does what you need to use Newton-Raphson, the multiroot function in the rootSolve package. The compulsory arguments of multiroot are a function f, which for your purposes will send a 2D vector to a 2D vector, and an initial value for its argument so you can begin the iteration. The real challenge is creating the function f, whose first and second components should be the values of F_a and F_b. So you want something like:

F_a <- function(a, b) integrate(function(z) some_function_f(a, b), -Inf, Inf)$value-a

F_b <- function(a, b) integrate(function(z) some_function_g(a, b), -Inf, Inf)$value-b

f <- function(v)
{
    a <- v[1]
    b <- v[2]
    c(F_a(a, b), F_b(a, b))
}

solve_for_a_and_b <- function(original_a, original_b) rootSolve::multiroot(f, c(original_a, original_b))
Related Question