[R] Help with optim() to maximize log-likelihood

Sophia Kyriakou sophia.kyriakou17 at gmail.com
Mon Mar 9 19:07:39 CET 2015


yes Ben, this works indeed! Thanks a million!!

On Mon, Mar 9, 2015 at 7:17 PM, Ben Bolker <bbolker at gmail.com> wrote:

> Sophia Kyriakou <sophia.kyriakou17 <at> gmail.com> writes:
>
> >
> > hello, I am using the optim function to maximize the log likelihood of a
> > generalized linear mixed model and I am trying to replicate glmer's
> > estimated components. If I set both the sample and subject size to
> q=m=100
> > I replicate glmer's results for the random intercept model with
> parameters
> >  beta=-1 and sigma^2=1. But if I change beta to 2 glmer works and optim
> > gives me the error message "function cannot be evaluated at initial
> > parameters".
> >
> > If anyone could please help?
> > Thanks
>
>  snip to make gmane happy.
>
> It looks like you're getting floating-point under/overflow.  If you do
> all the computations on the log scale first and then exponentiate,
> it seems to work, i.e.:
>
>         piYc_ir[i,] <- lchoose(m,Y[i]) + Y[i]*(z+beta) +
> (-z^2/(2*exp(psi))) -
>             m*(log1p(exp(z+beta))) - 0.5*(log(2*pi)+psi)
>         piYc_ir[i,] <- exp(piYc_ir[i,])
>
> follow-ups should probably go to r-sig-mixed-models at r-project.org
> instead ...
>
>   Ben Bolker
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list