I've written the following model in R
:
model1_b <- glm(bupacts ~ sex + couples + women_alone, data = risky, family = poisson(link="log"))
I would like to find the coefficient estimates for this model using optim
. That is, I would like to get to the point where the coefficients produced by the above model match those produced using optim
. Here is the code for the likelihood function:
log.like <- function(par) {
xb <- par[1] + par[2] * risky$sex + par[3] * risky$couples + par[4] * risky$women_alone
lambda <- exp(xb)
ll <- sum(log(exp(-lambda) * (lambda ^ risky$bupacts) / factorial(risky$bupacts)))
return(-ll)}
result <- optim(c(0, 0, 0, 0), log.like, hessian = TRUE, method = "BFGS")
I keep getting the error: initial value in 'vmmin' is not finite
. Could someone help me out here? I'm not sure what's going on.