I would like to know how to do the maximum likelihood estimation in R when fitting parameters are given in an array. This is needed when the number of parameters is large. So basically, to fit a normal distribution to the data x, I would like to do something like the following
LL <- function(param_array) {
R = dnorm(x, param_array[1], param_array[2])
-sum(log(R))
}
mle(LL, start = list(param_array = c(1,1)))
(Instead of this original code in the first section of http://www.r-bloggers.com/fitting-a-model-by-maximum-likelihood/) If I ran the code above I will get an error
Error in dnorm(x, param_array[1], param_array[2]) : argument "param_array" is missing, with no default
Could anyone let me know how to achieve what I want in the correct way?
?bbmle::mle2
, and thevecpar
argument ... – Ben Bolker