[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-mixed-models
Subject:    [R-sig-ME] Using custom link functions for glmer
From:       Matthew Giovanni <matthewgiovanni () gmail ! com>
Date:       2011-02-22 21:25:31
Message-ID: AANLkTi=N73Rinz-uQvvOXb4p4CtL+-spFxRXKJoDS0rU () mail ! gmail ! com
[Download RAW message or body]

Dear mixed-effects modelers-

I am using a "customized" link function, popularly known as the logistic
exposure link-function, developed by Terry Shaffer, to model daily survival
probabilities for birds based on exposure intervals.  I want to include one
or two random-effect variables, such as ordinal or Julian day to account for
(e.g.) variation in plant/habitat structure across the breeding season, but
I've been unable to use the logexp link function with glmer.  Here is some
example code:

*data=read.csv("Fledgling survival w veg.csv",header=TRUE)
### standardize data values for predictor variables
stand=scale(data[,7:17])
sdata=data.frame(cbind((data[,**1:6]),stand))

### logistic-exposure link function
logexp <- function(days = 1)
{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")}

model=glmer(fate~AGE+(1|ORDDAY),**data=sdata,family=binomial(**logexp))*

I get the following error returned when trying to fit such a model:

*Error in binomial(logexp) : link "logexp" not available for binomial
family; available links are ‘logit’, ‘probit’, ‘cloglog’, ‘cauchit’, ‘log’*

I edited the lmer source code, starting on line 42, in an attempt to
"bypass" this restriction but I still receive the same error:

*famNms <- c("binomial", "gaussian", "Gamma", "inverse.gaussian",
            "poisson")
linkNms <- c("logit", "probit", "cauchit", "cloglog", "identity",
         "log", "sqrt", "1/mu^2", "inverse","logexp")
varNms <- c("constant", "mu(1-mu)", "mu", "mu^2", "mu^3")

#famType <- function(family)
#{
    #if (!(fTyp <- match(family$family, famNms, nomatch = 0)))
        ##stop(gettextf("unknown GLM family: %s",
                      #sQuote(family$family), domain = "R-lme4"))
    #if (!(lTyp <- match(family$link, linkNms, nomatch = 0)))
        #stop(gettextf("unknown link: %s",
                      #sQuote(family$link), domain = "R-lme4"))
    #vNam <- switch(fTyp,
                   #"mu(1-mu)",          # binomial
                   #"constant",          # gaussian
                   #"mu^2",              # Gamma
                   #"mu^3",              # inverse.gaussian
                   #"mu")                # poisson
    #if (!(vTyp <- match(vNam, varNms, nomatch = 0)))
        #stop(gettextf("unknown GLM family: %s",
                      #sQuote(family$family), domain = "R-lme4"))
    #c(fTyp = fTyp, lTyp = lTyp, vTyp = vTyp)
#}*

I have minimal experience in editing source code, and I didn't think a
self-contained example with data was necessary in this case but please let
me know if otherwise.  I would be grateful for any suggestions.  Thanks for
your expertise.  Best,

Matt
*                                                                 *___
Matt Giovanni, Ph.D.
Research Wildlife Ecologist
402-617-3764 mobile
Research website:
http://sites.google.com/site/matthewgiovanni/
* <http://sites.google.com/site/matthewgiovanni/>*

	[[alternative HTML version deleted]]



_______________________________________________
R-sig-mixed-models@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic