Hi r-users,
I would like to solve system of nonlinear equation using BBsolve function and
below is my code. I have 4 parameters and I have 4 eqns.
mgf_gammasum <- function(p)
{
t <- rep(NA, length(p))
mn <- 142.36
vr <- 9335.69
sk <- 0.8139635
kur <- 3.252591
rh <- 0.896
# cumulants
k1 <- p[1]*(p[2]+p[3])
k2 <- p[1]*(2*p[2]*p[3]*p[4] +p[2]^2+p[3]^2)
k3 <- 2*p[1]*(p[2]+p[3])*(p[2]^2 + p[3]^2 - p[2]*p[3] + 3*p[2]*p[3]*p[4])
k4 <- 6*p[1]*((p[2]+p[3])^2*(p[2]^2 + p[3]^2 - 2*p[2]*p[3] +
4*p[2]*p[3]*p[4])+
2*p[2]^2*p[3]^2*(1-p[4])^2)
t[1] <- k1 - mn
t[2] <- k2 - vr
t[3] <- k3/(k2^1.5) - sk
t[4] <- k4/(k2^2) - kur
t
}
I tried this
p0 <- rep(0, 4)
BBsolve(par = p0, fn = mgf_gammasum)
dfsane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE))
sane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE))
and got the error message:
> BBsolve(par = p0, fn = mgf_gammasum)
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in optim(par = par, fn = U, method = "Nelder-Mead", control =
list(maxit =
100), :
function cannot be evaluated at initial parameters
Error in BBsolve(par = p0, fn = mgf_gammasum) :
object "ans.best" not found> dfsane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE))
Error in dfsane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE)) :
Failure in initial functional evaluation. > sane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE))
Error in sane(par = p0, fn = mgf_gammasum, control = list(trace = FALSE)) :
Failure in initial functional evaluation
Does anybody has any idea what is wrong? Any suggetsion is very much
appreciated.
[[alternative HTML version deleted]]