Skip to content
Prev 109238 / 398500 Next

error using user-defined link function with mixed models (LMER)

Ok, I've tried checking out the structure of the binomial and
logexposure families, the big difference  appears to be the valideta
parameter (it's "NULL" in the logexposure family).

First, binomial:
List of 11
 $ family    : chr "binomial"
 $ link      : chr "logit"
 $ linkfun   :function (mu)
 $ linkinv   :function (eta)
 $ variance  :function (mu)
 $ dev.resids:function (y, mu, wt)
 $ aic       :function (y, n, mu, wt, dev)
 $ mu.eta    :function (eta)
 $ initialize:  expression({     if (NCOL(y) == 1) {         if
(is.factor(y))              y <- y != levels(y)[1]         n <-
rep.int(1, nobs)         if (any(y < 0 | y > 1))              stop("y
values must be 0 <= y <= 1")         mustart <- (weights * y +
0.5)/(weights + 1)         m <- weights * y         if (any(abs(m -
round(m)) > 0.001))              warning("non-integer #successes in a
binomial glm!")     }     else if (NCOL(y) == 2) {         if
(any(abs(y - round(y)) > 0.001))              warning("non-integer
counts in a binomial glm!")         n <- y[, 1] + y[, 2]         y <-
ifelse(n == 0, 0, y[, 1]/n)         weights <- weights * n
mustart <- (n * y + 0.5)/(n + 1)     }     else stop("for the binomial
family, y must be a vector of 0 and 1's\n",          "or a 2 column
matrix where col 1 is no. successes and col 2 is no. failures") })
 $ validmu   :function (mu)
 $ valideta  :function (eta)
 - attr(*, "class")= chr "family"


Now, logexposure:
List of 11
 $ family    : chr "binomial"
 $ link      :List of 5
  ..$ linkfun :function (mu)
  .. ..- attr(*, "source")= chr "function(mu) qlogis(mu^(1/days))"
  ..$ linkinv :function (eta)
  .. ..- attr(*, "source")= chr "function(eta) plogis(eta)^days"
  ..$ mu.eta  :function (eta)
  .. ..- attr(*, "source")= chr [1:3] "function(eta)" ...
  ..$ valideta:function (eta)
  .. ..- attr(*, "source")= chr "function(eta) TRUE"
  ..$ name    : chr "logexp()"
  ..- attr(*, "class")= chr "link-glm"
 $ linkfun   :function (mu)
  ..- attr(*, "source")= chr "function(mu) qlogis(mu^(1/days))"
 $ linkinv   :function (eta)
  ..- attr(*, "source")= chr "function(eta) plogis(eta)^days"
 $ variance  :function (mu)
  ..- attr(*, "source")= chr "function(mu) mu * (1 - mu)"
 $ dev.resids:function (y, mu, wt)
  ..- attr(*, "source")= chr [1:2] "function(y, mu, wt)
.Call(\"binomial_dev_resids\"," ...
 $ aic       :function (y, n, mu, wt, dev)
  ..- attr(*, "source")= chr [1:7] "function(y, n, mu, wt, dev) {" ...
 $ mu.eta    :function (eta)
  ..- attr(*, "source")= chr [1:3] "function(eta)" ...
 $ initialize:  expression({     if (NCOL(y) == 1) {         if
(is.factor(y))              y <- y != levels(y)[1]         n <-
rep.int(1, nobs)         if (any(y < 0 | y > 1))              stop("y
values must be 0 <= y <= 1")         mustart <- (weights * y +
0.5)/(weights + 1)         m <- weights * y         if (any(abs(m -
round(m)) > 0.001))              warning("non-integer successes in a
binomial glm!")     }     else if (NCOL(y) == 2) {         if
(any(abs(y - round(y)) > 0.001))              warning("non-integer
counts in a binomial glm!")         n <- y[, 1] + y[, 2]         y <-
ifelse(n == 0, 0, y[, 1]/n)         weights <- weights * n
mustart <- (n * y + 0.5)/(n + 1)     }     else stop("for the binomial
family,", " y must be a vector of 0 and 1's\n",          "or a 2
column matrix where col 1 is", " no. successes and col 2 is no.
failures") })
 $ validmu   :function (mu)
  ..- attr(*, "source")= chr "function(mu) all(mu > 0) && all(mu < 1)"
 $ valideta  : NULL
 - attr(*, "class")= chr "family"


So, could this be the root of the problem?

Here again is the logexp function:
logexp <- function(days = 1)
{
    linkfun <- function(mu) qlogis(mu^(1/days))
    linkinv <- function(eta) plogis(eta)^days
    mu.eta <- function(eta)
      days*.Call("logit_mu_eta", eta,
       PACKAGE = "stats")*plogis(eta)^(days-1)
    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")
}

So, does something seem obviously wrong about the "valideta <-
function(eta) TRUE" bit? I readily admit that I did not write these
user-defined link and family functions (I believe they resulted from
the combined efforts of Mark Herzog and Brian Ripley), so my clumsy
efforts to toy with the valideta portion of the logexp link function
aren't working.

Thanks again in advance for any further advice.

cheers, Jessi Brown
On 2/10/07, Douglas Bates <bates at stat.wisc.edu> wrote: