2
$\begingroup$

I am an economics student attempting to do somewhat of an unorthodox maximum likelihood estimation of the parameters of a labor market model.

I basically have two equations. One first order condition (16) and a log likelihood function, that I wish to maximize wrt. (alpha,delta,gamma). The variables (w, T, n, x, P) are some data for firm-observations i = 1, ... , 1470.

Eq. 16 - must hold for all observations i=1,2, ...,1470

log Likelihood function

The tricky thing is that I have to compute the values for the product lambda*s_i via (16) by assuming some initial value for (alpha,gamma) and then use an identifying restriction that for the largest observation i = 1470, that

 s_1470 = 0 

By doing this eq. (16) has only 1 unknown for (i=1469), which I can solve for using the uniroot command in R. Afterwards i can solve for (i=1468) and so on recursively until (i=1).

Having done this operation, I then wish to maximize the log-likelihood function wrt. (alpha,delta,gamma). The crucial thing here is that I could only solve (16) by assuming some initial values for (alpha,gamma).

My problem is that I cannot seem to make R understand, that it should maximize the likelihood function taking into account, that (alpha,gamma) impacts the likelihood-function through it's effect on the (lambda*s_i)'s calculated via (16).

I use the following code. I've coded a function search_solve that does the calculation of the (lambda*s_i)'s and stores them in lambdas. logpdfb calculates the term in brackets, in the likelihood-function.

## Likelihoodfunction

loglik<-function(theta,n,x,netwage)
{
  delta <- exp(theta[1])
  alpha <- exp(theta[2])
  gam <- exp(theta[3])

  lambdas = matrix(0,nrow(netwage),1)
  lambdas <- search_solve(netwage,p)

  d <- 1*delta + lambdas * (1-p)
  d2 <- exp(-d)
  b = logpdfb(x,d2,n)

  logl <- colSums(b)
  return(-logl)
}

#STARTING VALUE PARAMETERS
start <- matrix(0,3,1);
start[1,1] = -2;
start[2,1] = -5;
start[3,1] = 0.5;

###################################

optim(start,fn=loglik,n=size,x=stayer,netwage=netwage,method="BFGS",hessian = TRUE)

When I use this code R does not optimize wrt. to (alpha,gamma) and the estimates reported are just equal to the starting values.

          [,1]
[1,] -1.336792
[2,] -5.000000
[3,]  0.500000

How can I make R understand that it should optimize the likelihood-function taking into account that (alpha,gamma) impacts the likelihood-function indirectly?

$\endgroup$
  • 2
    $\begingroup$ When an optimisation algorithm does not "move a lot" from the initial values of it you might want to check if the algorithm can actually move or you have accidentally constrained it too much. Similarly you might want to check the derivative of our log-likelihood function at that point. If for some reason the algorithm thinks it is already at some optimum well... it is not going to move. Finally, try different solvers; for example NLopt has some pretty good solvers. $\endgroup$ – usεr11852 Feb 27 '16 at 21:48
  • $\begingroup$ Thanks for your comment user11852. Regarding whether the supplied starting values might be the optimum, I'm fairly certain they are not, since I am recreating a paper, where the values they find are much different. My guess is that the algorithm does not move at all, since it doesn't even recognize that the parameters enter the likelihood function (since they only do in this indirect way). Thank you for recommending NLopt - I will definitely try that out. $\endgroup$ – AGK1991 Feb 28 '16 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.