Re: [R] Discrete choice model maximum likelihood estimation

2012-05-15 Thread Joshua Wiley
On Tue, May 15, 2012 at 9:57 PM, Bert Gunter wrote: > Hmmm... So you want to fit a nonlinear model with 24 parameters??!! > > I would bet that you'll need to sacrifice some chickens to the > nonlinear optimization gods to get something meaningful from that > exercise. Nominated for a fortune. >

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-15 Thread Bert Gunter
c >> derivatives to make it sing. For 5 parameters, use NM, or better the nmk >> from dfoptim package. >> >> Best, JN >> >> >> On 05/15/2012 06:00 AM, r-help-request@ wrote: >>> Message: 13 >>> Date: Mon, 14 May 2012 04:21:57 -0700 (PDT) >

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-15 Thread infinitehorizon
optim package. > > Best, JN > > > On 05/15/2012 06:00 AM, r-help-request@ wrote: >> Message: 13 >> Date: Mon, 14 May 2012 04:21:57 -0700 (PDT) >> From: infinitehorizon <barisvardar@> >> To: r-help@ >> Subject: Re: [R] Discrete choice model m

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-15 Thread John C Nash
Best, JN On 05/15/2012 06:00 AM, r-help-requ...@r-project.org wrote: > Message: 13 > Date: Mon, 14 May 2012 04:21:57 -0700 (PDT) > From: infinitehorizon > To: r-help@r-project.org > Subject: Re: [R] Discrete choice model maximum likelihood estimation > Message-ID: <13369945170

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread Berend Hasselman
See below. On 14-05-2012, at 13:21, infinitehorizon wrote: > Hello again, > > I changed the name to tt. > and for a and tt actually I was getting them from data, I didn't put them > here in the question. Now I restructured my code and below I copy the full > code, I tried many things but still

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread infinitehorizon
Of course, that was the trick! It works now. Thank you very much Rui, I am very grateful. I hope this thread will help others as well. Best, Rui Barradas wrote > > Once again, sorry. > I had a different llfn in my R session and it messed with yours. > > llfn <- function(param, a, tt) { > >

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread Rui Barradas
Once again, sorry. I had a different llfn in my R session and it messed with yours. llfn <- function(param, a, tt) { llfn <- sum((a==1)*lL1+(a==2)*lL2+(a==3)*lL3) # sum of logs, it's a log-likelihood. return(-llfn) } Rui Barradas infinitehorizon wrote > > Hello again, > > You are absolutely

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread Rui Barradas
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'

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread infinitehorizon
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 o

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread infinitehorizon
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

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread infinitehorizon
Hello again, I changed the name to tt. and for a and tt actually I was getting them from data, I didn't put them here in the question. Now I restructured my code and below I copy the full code, I tried many things but still getting the same error, I don't understand where is the mistake. I also

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread Rui Barradas
Ok, I forgot to say that 't' is also an R function, the matrix transpose. Sorry, but after 'par' I thought (in my mind) I had said it when in fact I even talked about 't'! Use 'tt'. If 'tt' is a vector you must first define it, in your code it doesn't exist. That's why R searches for and finds an o

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-14 Thread infinitehorizon
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,

Re: [R] Discrete choice model maximum likelihood estimation

2012-05-13 Thread Rui Barradas
Hello, There are several issues with your code. 1. The error message. Don't use 'par' as a variable name, it's already an R function, tyo get or set graphics parameters. Call it something else, say, 'param'. This is what causes the error. You must pass initial values to optim, but the variable yo

[R] Discrete choice model maximum likelihood estimation

2012-05-13 Thread infinitehorizon
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 gener