Daniel Barton
2010-Mar-26 18:59 UTC
[R] Linear mixed models with custom link functions in R
Hello All, I am looking for an R library/function that allows the specification of a custom link function in a linear mixed model. I've been using glm() in library MASS to fit fixed-effect models with a custom link but my study design demands mixed models. Any suggestions on the best R library/function to achieve this would be greatly appreciated. I have tried, to no avail, to locate a library that fits my needs by searching CRAN and the web on the basis of which ones allow custom link functions. Some of the mixed-effect models I'm hoping to fit involve more than a single random factor. An example of how I've been doing this with glm() is shown below to illustrate what I'm hoping to scale up to a mixed model. Thanks very much for your time and thoughts. ----------------- library(MASS) logexp <- function(days = 1) ##Custom link function from Shaffer (2004) Auk 121:526-540. { linkfun <- function(mu) qlogis(mu^(1/days)) linkinv <- function(eta) plogis(eta)^days mu.eta <- function(eta) days * plogis(eta)^(days-1) * .Call("logit_mu_eta", eta, PACKAGE = "stats") valideta <- function(eta) TRUE link <- paste("logexp(", days, ")", sep="") structure(list(linkfun = linkfun, linkinv = linkinv, mu.eta = mu.eta, valideta = valideta, name = link), class = "link-glm") } model0 <- glm(survive~1, family=binomial(logexp(days=expos))) ##Call to glm with custom link --------------------- Best, Dan Barton -- Daniel C. Barton PhD Candidate USGS Montana Cooperative Wildlife Research Unit & Program in Organismal Biology and Ecology University of Montana 205 Natural Science Missoula, MT 59812 daniel.barton at umontana.edu Missoula, MT 59812
Daniel Barton <daniel.barton <at> umontana.edu> writes:> > Hello All, > I am looking for an R library/function that allows the specification > of a custom link function in a linear mixed model.You might want to try on the r-sig-mixed-models at r-project.org list. I would probably call this a *G*LMM because of the link function, even if you are assuming normally distributed errors. I *think* (although haven't tried it) that if you use glmmPQL from the MASS package, its 'family' argument is identical to that in glm() [and in fact gets passed through to the glm() function], so you should be able to adapt what you have already done to glmmPQL. The only down side (if it works) is that glmmPQL (as the name suggests) uses penalized quasi-likelihood, which may under some circumstances give biased estimates of the random effects (see Breslow 2003) -- but it may not be important in your application. If worse comes to worst, you may end up coding your own in WinBUGS or AD Model Builder ...