Stochastic parameter estimation

Solution 1:

MLE() takes two variables, yet you gave the optim() function three parameters. Essentially, the optim() function expects b in your MLE function to be a vector of two spots. If you wanted to optimize b and y, for example, this will work.

MLE <- function(b){
  J <<- vector(length = Ti)
  for(i in 1:Ti){
    J[i] <<- log(PL(i, b[1], b[2]))
    }
  return(sum(J))
  }

MLE(c(1, 0.5)) 
optim(c(1, 1),  MLE)

Now b is b[1] and y is b[2]. I'm not sure if that's what you wanted to optimize, though.