Skip to content
Prev 294434 / 398502 Next

Discrete choice model maximum likelihood estimation

Hello Rui,

First of all, thanks a lot!
1. I changed par to param,
2. t is a variable too, a binary one, b is the parameter associated to it,

4. Yes, this is where I am stuck actually.

I fixed the code for likelihood functions as follows, but still getting the
same error:

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

L3l	<- P11*P22*P33
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*P22
return(L2l)
}

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

L1l	<- P11
return(L1l)
}

# Log-likelihood function

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

b1	<- param[1]
b2	<- param[2]
b3	<- param[3]
b	<- param[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
}
start.par <- c(1,1,1,1)
est	<- optim(param=start.par,llfn, method =
c("CG"),control=list(trace=2,maxit=2000), hessian=TRUE)

In the end, i receive the same error message, 
actually, first I tried without start.par and I got the error of "object
param not found", then I defined start.par, it lead me to same error "cannot
coerce type 'closure' to vector of type 'double'".

I am aware that my questions might be too basic, but as I said I am not
familiar with syntax :/
Thanks for your help! 

Best,

Marc



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