[R] Discrete choice model maximum likelihood estimation

Rui Barradas ruipbarradas at sapo.pt
Mon May 14 15:50:10 CEST 2012


Hello, again.

Bug report:
1. Your densities can return negative values, 1 - exp(...) < 0.
    Shouldn't those be 1 PLUS exp()?

P3 <- function(bx,b3,b,tt) {
	P <- exp(bx*x+b3+b*(tt == 1))/(1+exp(bx*x+b3+b*(tt == 1)))
	return(P)
}

And the same for P2 and P1?

2. Include 'a' and 'tt' as llfn parameters and call like the following.

llfn <- function(param, a, tt) {

           [... etc ...]
           return(-llfn)
}

start.par <- rep(0, 5)
est <- optim(start.par, llfn, gr=NULL, a=a, tt=tt)
est
$par
[1]  4.1776294 -0.9952026 -0.7667640 -0.1933693  0.7325221

$value
[1] 0

$counts
function gradient 
      44       NA 

$convergence
[1] 0

$message
NULL


Note the optimum value of zero, est$value == 0

Rui Barradas

infinitehorizon wrote
> 
> By the way, in my last post I forgot to return negative of llfn, hence the
> llfn will be as follows:
> 
> llfn <- function(param) { 
> 
> bx <- param[1] 
> b1 <- param[2] 
> b2 <- param[3] 
> b3 <- param[4] 
> b <- param[5] 
> 
> lL1 <- log(L1(bx,b1,b2,b,tt)) 
> lL2 <- log(L2(bx,b1,b2,b3,b,tt)) 
> lL3 <- log(L3(bx,b1,b2,b3,b,tt)) 
> 
> llfn <- (a==1)*lL1+(a==2)*lL2+(a==3)*lL3 
> return(-llfn)
> } 
> 
> However, it does not fix the problem, I still receive the same error..
> 


--
View this message in context: http://r.789695.n4.nabble.com/Discrete-choice-model-maximum-likelihood-estimation-tp4629877p4629935.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list