From sw283 at maths.bath.ac.uk  Tue Apr 11 15:56:53 2006
From: sw283 at maths.bath.ac.uk (Simon Wood)
Date: Tue, 11 Apr 2006 14:56:53 +0100 (BST)
Subject: [Rd] gaussian family change suggestion
In-Reply-To: <mailman.9.1144749603.14828.r-devel@r-project.org>
References: <mailman.9.1144749603.14828.r-devel@r-project.org>
Message-ID: <Pine.LNX.4.56.0604111441331.29929@thoth.maths.bath.ac.uk>

Hi,

Currently the `gaussian' family's initialization code signals an error if
any response data are zero or negative and a log link is used. Given that
zero or negative response data are perfectly legitimate under the GLM
fitted using `gaussian("log")', this seems a bit unsatisfactory. Might
it be worth changing it?

The current offending code from `gaussian' is:

initialize = expression({
            n <- rep.int(1, nobs)
            if (is.null(etastart) && is.null(start) && is.null(mustart) &&
                ((family$link == "inverse" && any(y == 0)) ||
                  (family$link == "log" && any(y <= 0)))) stop(
              "cannot find valid starting values: please specify some")
            mustart <- y
        })

A possible replacement would be ...

initialize = expression({
            n <- rep.int(1, nobs)
            if (is.null(etastart) && is.null(start) && is.null(mustart) &&
                ((family$link == "inverse" && all(y == 0)) ||
                  (family$link == "log" && all(y <= 0)))) stop(
      "cannot find valid starting values: please specify some")
        mustart <- y
      if (family$link=="log") {
        iy <- y<=0
        if (sum(iy)) mustart[iy] <- min(y[!iy])*.5
      } else if (family$link=="inverse") {
        iy <- y==0
        if (sum(iy)) mustart[iy] <- min(abs(y[!iy]))*.5
      }
        })

best,
Simon


>- Simon Wood, Mathematical Sciences, University of Bath, Bath BA2 7AY
>-             +44 (0)1225 386603         www.maths.bath.ac.uk/~sw283/



[Rd] gaussian family change suggestion
Simon Wood