I am new to R and trying to understand this function call below:
mle_mos <- function (n, m1, m2, x, x1, x2, initial, iters)
mvnewton (function (p) log_likelihood_gradient(p,n,m1,m2,x,x1,x2),
function (p) -fisher_information(p,n,m1,m2,x,x1,x2),
initial, iters)
mvnewton <- function (f, g, x, n)
{
print(f)
if (n < 1)
stop("invalid number of iterations")
for (i in 1:n) {
cat("\nAt iteration",i,":\n\n")
cat("x =",x,"\n")
cat("f(x) =",f(x),"\n")
cat("g(x) =\n")
print(g(x));
x <- x - solve(g(x),f(x)) # computes inverse of g(x) times
f(x)
}
x
}
mvnnewton takes
(function (p) log_likelihood_gradient(p,n,m1,m2,x,x1,x2)
as the first parameter. Where is p getting it's value from? Where is it defined? Can someone explain where p is getting a value to be passed into log_likelihood_gradient as a parameter? I have been googling for the past 2 days and reading up a lot of stuff but am still not clear that I understand this properly.
function (p) log_likelihood_gradient(p,n,m1,m2,x,x1,x2)is a definition of a function. It will get the value from themvnewtonfunction, for which it is an argument.