[R] Discrete choice model maximum likelihood estimation

infinitehorizon barisvardar at hotmail.com
Mon May 14 17:32:07 CEST 2012


Hello again,

You are absolutely right about probabilities.. Thanks for reminding me about
that.

I did exactly how you said but in the end I receive the error : "objective
function in optim evaluates to length 12 not 1".
I checked how llfn give a vector instead of scalar,  but couldn't figure it
out.

Can you please tell me how did you obtain those estimates?
Thanks again,

Best,

Marc


Rui Barradas wrote
> 
> 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-tp4629877p4629952.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list