Skip to content

mu^2(1-mu)^2 variance function for GLM

2 messages · David Firth, Henric Nilsson

#
Dear Henric

I do not have a ready stock of other examples, but I do have my own 
version of a family function for this, reproduced below.  It differs 
from yours (apart from being a regular family function rather than 
using a modified "quasi") in the definition of deviance residuals.  
These necessarily involve an arbitrary constant (see McCullagh and 
Nelder, 1989, p330); in my function that arbitrariness is in the choice 
eps <- 0.0005.  I don't think the deviance contributions as you 
specified in your code below will have the right derivative (with 
respect to mu) for observations where y=0 or y=1.

Anyway, this at least gives you some kind of check.  I hope it helps.  
This function will be part of a new package which Heather Turner and I 
will submit to CRAN in a few days' time.  Please do let me know if you 
find any problems with it.

Here is my "wedderburn" family function:

"wedderburn" <-
     function (link = "logit")
{
     linktemp <- substitute(link)
     if (!is.character(linktemp)) {
         linktemp <- deparse(linktemp)
         if (linktemp == "link")
             linktemp <- eval(link)
     }
     if (any(linktemp == c("logit", "probit", "cloglog")))
         stats <- make.link(linktemp)
     else stop(paste(linktemp,
                     "link not available for wedderburn quasi-family;",
                     "available links are",
                     "\"logit\", \"probit\" and \"cloglog\""))
     variance <- function(mu)  mu^2 * (1-mu)^2
     validmu <- function(mu) {
         all(mu > 0) && all(mu < 1)}
     dev.resids <- function(y, mu, wt){
         eps <-  0.0005
         2 * wt * (y/mu + (1 - y)/(1 - mu) - 2 +
                   (2 * y - 1) * log((y + eps)*(1 - mu)/((1- y + eps) * 
mu)))
     }
     aic <- function(y, n, mu, wt, dev) NA
     initialize <- expression({
         if (any(y < 0 | y > 1)) stop(paste(
                    "Values for the wedderburn family must be in [0,1]"))
         n <- rep.int(1, nobs)
         mustart <- (y + 0.1)/1.2
     })
     structure(list(family = "wedderburn",
                    link = linktemp,
                    linkfun = stats$linkfun,
                    linkinv = stats$linkinv,
                    variance = variance,
                    dev.resids = dev.resids,
                    aic = aic,
                    mu.eta = stats$mu.eta,
                    initialize = initialize,
                    validmu = validmu,
                    valideta = stats$valideta),
               class = "family")
}

Best wishes,
David
http://www.warwick.ac.uk/go/dfirth
On 16 Jun 2005, at 09:27, Henric Nilsson wrote:

            
5 days later
#
Dear Professor Firth,

David Firth said the following on 2005-06-16 17:22:
I'm sorry for the late reply.

You're right -- my definition of the deviance residuals isn't correct. 
Your code, on the other hand, seems to do the right thing.

Many thanks for this note and the provided `wedderburn' function.


Henric