[R] Discrete choice model maximum likelihood estimation

infinitehorizon barisvardar at hotmail.com
Sun May 13 23:53:07 CEST 2012


Hello,

I am new to R and I am trying to estimate a discrete model with three
choices. I am stuck at a point and cannot find a solution.

I have probability functions for occurrence of these choices, and then I
build the likelihood functions associated to these choices and finally I
build the general log-likelihood function.

There are four parameters in the model, three of them are associated to
three discrete choices I mentioned, and one of them is for a binary variable
in the data (t).  There are also latent variables but I didn't put them in
this question because if I figure out how to do this, I will be able to add
them as well.

I am not familiar with the syntax I have to write in the likelihood
functions, so I really doubt that they are true.  Below I simplify the
problem and provide the code I've written:

# Probabilities for discrete choices for a=3, a=2 and a=1 respectively
P3	<- function(b3,b,t) {
P 	<- exp(b3+b*(t==1))/(1-exp(b3+b*(t==1)))
return(P)		
}
P2	<- function(b2,b,t) {
P 	<- exp(b2+b*(t==1))/(1-exp(b2+b*(t==1)))
return(P)		
}
P1	<- function(b1,b,t) {
P 	<- exp(b1+b*(t==1))/(1-exp(b1+b*(t==1)))
return(P)		
}

# Likelihood functions for discrete choices for a=3, a=2 and a=1
respectively

L3	<- function(b1,b2,b3,b,t) {
P11	<- P1(b1,b,t)
P22	<- P2(b2,b,t)
P33	<- P3(b3,b,t)

L3l	<- (P11=1)*(P22=1)*(P33=1)
return(L3l)
}

L2	<- function(b1,b2,b3,b,t) {
P11	<- P1(b1,b,t)
P22	<- P2(b2,b,t)
P33	<- P3(b3,b,t)

L2l	<- (P11=1)*(P22=1)*(P33=0)
return(L2l)
}

L1	<- function(b1,b2,b,t) {
P11	<- P1(b1,b,t)
P22	<- P2(b2,b,t)

L1l	<- (P11=1)*(P22=0)
return(L1l)
}

# Log-likelihood function

llfn	<- function(par,a,t) {

b1	<- par[1]
b2	<- par[2]
b3	<- par[3]
b	<- par[4]

lL1	<- log(L1(b1,b2,b,t))
lL2	<- log(L2(b1,b2,b3,b,t))
lL3	<- log(L3(b1,b2,b3,b,t))

llfn	<- (a==1)*lL1+(a==2)*lL2+(a==3)*lL3
}
est	<- optim(par,llfn, method = c("CG"),control=list(trace=2,maxit=2000),
hessian=TRUE)

And when I run this code I get "cannot coerce type 'closure' to vector of
type 'double'" error.
I will really appreciate your help. Thanks,



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



More information about the R-help mailing list