next up previous
Next: Link Structures Up: Structure of the Previous: Model Prototypes

Error Structures

The error structure of a generalized linear model affects four methods and two slots The methods are called as (send m :initial-means)
(send m :fit-variances mu)
(send m :fit-deviances mu)
(send m :fit-scale)

The :initial-means method should return an initial estimate of the means for the iterative search. The default method simply returns the dependent variable, but for some models this may need to be adjusted to move the initial estimate away from a boundary. For example, the method for the Poisson regression model can be defined as

(defmeth poissonreg-proto :initial-means () (pmax (send self :yvar) 0.5))
which insures that initial mean estimates are at least 0.5.

The :fit-variances :fit-deviances methods return the values on the variance and deviance functions for a specified vector of means. For the Poisson regression model, these methods can be defined as

(defmeth poissonreg-proto :fit-variances (mu) mu)
and
(defmeth poissonreg-proto :fit-deviances (mu)
  (flet ((log+ (x) (log (if-else (< 0 x) x 1))))
    (let* ((y (send self :yvar))
           (raw-dev (* 2 (- (* y (log+ (/ y mu))) (- y mu))))
           (pw (send self :pweights)))
      (if pw (* pw raw-dev) raw-dev))))
The local function log+ is used to avoid taking the logarithm of zero.

The final message, :fit-scale, is only used by the :display method. The default method returns the mean deviance.

The two slots related to the error structure are estimate-scale and link. If the value of the estimate-scale slot is not nil, then a scale estimate is computed and printed by the :dislay method. The link slot holds the link object used by the model. The Poisson model does not have a scale parameter, and the canonical link is the logit link. These defaults can be set by the expressions

(send poissonreg-proto :estimate-scale nil)
(send poissonreg-proto :link log-link)

The glim-proto prototype itself uses normal errors and an identity link. Other error structures can be implemented by constructing a new prototype and defining appropriate methods and default slot values.



Luke Tierney
Tue Jan 21 14:42:18 CST 1997