Hello Ben,


Thank you so much again. We tried the function but we didn’t achieve to run
it within our data. However, we found this post (see:
https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q2/002413.html),
which uses a similar function in the example (without an extra space at the
end of "try-error"):



*ok <- function(x,type= "try-error") class(x)!=type*

>* *

>* options(warn=2)*

>* *

>* fitmodel <- try(lmer(modelformula,data))*

>* *

**

>* *

>* ok(fitmodel)*



and it works in our data.


Now, we are basically interested in the probability of (non) convergence,
that's why so far we only want to see how often convergence occurs. In the
future, we may also want to study the different kinds of warning
messages....


Best regards,


Martí Casals.


2012/11/1 Ben Bolker <bbolker@gmail.com>

> On 12-10-31 02:27 PM, Martí Casals wrote:
> > Hi Ben,
> > Thank you very much for all your help, so far. Nonetheless, there is
> > still something not working. If you could have a look at the following
> > code, I would highly appreciate it. It's about how to count convergence
> > problems of function glmer within a simulation. I tried to adapt your
> > proposal to my models, but something's not working, probably to me lack
> > of knowledge of functions like tryCatch and withCallingHandlers.
>
>   Here's my attempt.
>   A reproducible example would have been slightly more convenient --
> I'm guessing a bit here.
>
> options(warn=2)
> nsim <- 1000  ## BMB: setting this to a parameter
> warn<-rep(NA,nsim)
> estglmer<-vector('list',nsim)
> ## BMB: it is marginally more efficient to pre-allocate
> ## lists (although prob doesn't
> ##  matter in this much case, glmer() is the slow part)
>
> ## don't know why estglmer needs names?
>
> ## The model to be fitted (Y, Category, fallswinner & ncombat are
> ##  variables in data frame dd)
> modfun <- function(dat) glmer(Y~Category+fallswinner+(1|id),
>        offset=(log(ncombat)),nAGQ=50,family="poisson",data=dat)
>
> for(i in 1:nsim){
>      # The data to be used
>    ## nAGQ=50 is a little surprising.  Do you really need that much?
>      estglmer[[i]]<-withCallingHandlers(
>               tryCatch(modfun(alldata[[i]]),
>                  error = function(e) {
>                       warn[i] <<- paste("ERROR:",e$message)
>                        NA
>                    }),
>                    warning = function(w) {
>                         warn[i] <<- w$message
>                         invokeRestart("muffleWarning")
>                    })
> }
>
>
> >
> >
> > I'm thinking about the topic and I don't know if it’s useful to obtain
> > the warnings/errors, because I should  look at each error and then I
> > should decide what I can do.
> >
> > I only want to inform aboutpercentage of convergence of GLMM, that is
> > the converge is true or false.  I understand that a model is considered
> > as not convergent  either if the estimation process did not converge or
> > if the estimate or its standard error was not provided. For example, in
> > some cases the parameter can be estimated but the estimation process was
> > unable to provide a positive definite variance-covariance matrix of the
> > parameters (problems with Hessian), mainly due to the instability of the
> > model.
> >
> > Thank you very much in advance for your suggestions.
> >
> > Martí
> >
> >
> >
> > 2012/10/23 Martí Casals <mcasals@aspb.cat <mailto:mcasals@aspb.cat>>
> >
> >     Thank you so much Ben!!
> >
> >     Martí
> >
> >
> >     2012/10/23 Ben Bolker <bbolker@gmail.com <mailto:bbolker@gmail.com>>
> >
> >         Martí Casals <mcasals@...> writes:
> >
> >         >
> >         > I’m working on the simulation results and I would like to know
> the
> >         > convergence of the GLMM model. For example, if I want to
> >         obtain the
> >         > converge in the glm case with R, I can extract:
> >         >
> >         > model1<-glm(................family=" ",data=)
> >         >
> >         > *model1$converged*
> >         >
> >         > [1] TRUE
> >         >
> >         > I don’t know if exist a similar function in the lme4 package
> >         (glmer ).
> >         >
> >
> >           I think not.
> >           I believe the only way to do this (it may have been discussed
> >         before)
> >         is to use options(warning=2) to promote warnings to errors, then
> >         to use
> >         tryCatch() etc. to intercept the errors and store the
> >         information somewhere.
> >
> >         http://comments.gmane.org/gmane.comp.lang.r.lme4.devel/8691
> >         https://stat.ethz.ch/pipermail/r-help/2012-February/302767.html
> >
> >           I've added a bit on this to http://glmm.wikidot.com/faq, since
> >         it's
> >         not the first time it has come up ...
> >
> >          Ben Bolker
> >
> >         _______________________________________________
> >         R-sig-mixed-models@r-project.org
> >         <mailto:R-sig-mixed-models@r-project.org> mailing list
> >         https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >
> >
> >
> >
> >     --
> >     Martí Casals Toquero
> >
> >     Centre d' Investigació Biomèdica d'Epidemiología i Salut Pública
> >
> >     Agència de Salut Pública de Barcelona
> >
> >     Servei d' Epidemiologia
> >
> >     Tel. 932384545 extensió: 391
> >
> >     mcasals@aspb.es <mailto:mcasals@aspb.es>
> >
> >
> >
> >
> > --
> > Martí Casals Toquero
> >
> > Centre d' Investigació Biomèdica d'Epidemiología i Salut Pública
> >
> > Agència de Salut Pública de Barcelona
> >
> > Servei d' Epidemiologia
> >
> > Tel. 932384545 extensió: 391
> >
> > mcasals@aspb.es <mailto:mcasals@aspb.es>
>
>
>


-- 
Martí Casals Toquero

Centre d' Investigació Biomèdica d'Epidemiología i Salut Pública

Agència de Salut Pública de Barcelona

Servei d' Epidemiologia

Tel. 932384545 extensió: 391

mcasals@aspb.es

	[[alternative HTML version deleted]]

