Hi all,
I am new to Bayesian modelling, so apologies in advance. My question is in relation to whether or not it is possible to create custom link functions in brms
?
In ecology (for this example, think of individual nesting attempts by birds), it is common to model the survival of a nest using a binary response outcome (e.g., 1 = alive, 0 = depredated). However, individual nests can differ in the number of days they are exposed to predation risk, and irregular data collection methods mean that nests may be found at different stages of development. To account for this, Shaffer (2004) proposed a modified logistic regression which incorporates the # of exposure days into the link function:
# Define logistic exposure family link function
library(MASS)
library(lme4)
logexp <- function(exposure = 1)
{
linkfun <- function(mu) qlogis(mu^(1/exposure))
linkinv <- function(eta) plogis(eta)^exposure
mu.eta <- function(eta) exposure * plogis(eta)^(exposure-1) * .Call(stats:::C_logit_mu_eta, eta, PACKAGE = "stats")
valideta <- function(eta) TRUE
link <- paste("logexp(",
deparse(substitute(exposure)), ")",sep="")
structure(list(linkfun = linkfun, linkinv = linkinv,
mu.eta = mu.eta, valideta = valideta, name = link),
class = "link-glm")
}
mod.1 <- glmer(survival ~ nest_height + (1|nest_id),
data = dat,
family = binomial(logexp(exposure =dat$exposure)))
Is there an equivalent method for doing this kind of model using brms
?
I have included some dummy data:
dat.csv (4.1 KB)
Which is modified from: https://rpubs.com/bbolker/logregexp
Thanks!