I am trying to implement Maximum likelihood estimation for the following 2-parameter Beta-Poisson model
Working through other solutions in StackOverflow I came to the conclusion - possibly incorrectly - that the "optim" function might be the best solution. Accordingly, I have made an attempt at coding this up:
Log_Lik_BP <- function(alpha_beta, D, Y, N){
alpha <- alpha_beta[1]
beta <- alpha_beta[2]
sum(Y * log(1 - (1 + (D/beta))^(-alpha))) - alpha*sum(N-Y)*log(1+(D/beta))
}
optim(par = c(0,0), fn = Log_Lik_BP, D = df$D, N = df$N, Y = df$Y)
But I haven't been very successful and I am receiving the following error message, with "length 22" referring to the 22 data points in the dataframe
Error in optim(par = c(0, 0), fn = Log_Lik_BP, D = df$D, N = df$N, Y = df$Y) :
objective function in optim evaluates to length 22 not 1
The dataset I am applying this MLE estimation is as follows:
D <- c(4.2,8,10.6,11.9,12.2,12.6,13,13.2,28.3,28.7,68.2,69,71.1,83,91.7,95.5,106.5,136.5,171.2,186.9,309.3,1557.1)
N <- c(1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
Y <- c(0,0,1,1,2,1,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1)
df <- data.frame(D, N, Y)
Thanks in advance for advice and corrections to my code