[R] How to use mle2 function?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Tue Jun 30 11:39:11 CEST 2020


Hello,
I would like to optimize the function:
```
holling = function(a, b, x) {
  y = (a * x^2) / (b^2 + x^2)
  return(y)
}
```
I am trying to use the function mle2 from bbmle, but how do I need to
feed the data?
If I give `holling` as function to be optimized, passing the starting
values for `a`, `b`, and `x`, I get:
```
X = 1:60
A = 3261
B = 10
O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```
If I pass the negative log-function (assuming a binomial distribution
of the data, which I am not sure about)
```
nll = function(p, n, k) {
  # extract parms
  a = p[1]
  h = p[2]
  # calculate probability of attack
  pred = a/(1+a*h*n)
  # calc NLL
  -sum(dbinom(k, prob = pred, size = n, log = TRUE))
}
```
then I get the same error:
```
> O = mle2(minuslogl = nll, start = list(a = A, h = B),
+          data = list(n = 57200000, k = A))
Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
list(n = 57200000,  :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```
but with the disadvantage of working on an assumed function (nll).
How can I optimize the function `holling` properly?
Thank you




-- 
Best regards,
Luigi



More information about the R-help mailing list