I am attempting to estimate lambda using the method of maximum likelihood estimation.
Here is the code I am using:
set.seed(0)
x=rexp(100,10)
plot(x)
fn <- function(lambda){
length(x)*log(lambda)-lambda*sum(x)
}
plot(fn)
optim(lambda, fn)
Error in optim(lambda, fn) : object 'lambda' not found nlm(fn, lambda) Error in nlm(fn, lambda) : object 'lambda' not found
Clearly my issue is with the error I am not sure how to fix it. can anyone tell me how to fix this so that i can get the estimation or perhaps recommend a better method?