Next: Fitting a Bradley-Terry Up: Structure of the Previous: Error Structures

The link function g for a generalized linear model relates the linear predictor to the mean response by

Links are implemented as objects. Table 1 lists the pre-defined link functions, along with the expressions used to return link objects.

With one exception, the pre-defined links require no parameters. These link objects can therefore be shared among models. The exception is the power link. Links for binomial models are defined for n = 1 trials and assume .

```(defproto log-link () () glim-link-proto)
```
Since this prototype can be used directly in model objects, the convention of having prototype names end in -proto is not used. The glim-link-proto prototype provides a :print method that should work for most link functions. The log-link object prints as
```> log-link
```

The glim-proto computing methods assume that a link object responds to three messages: (send link :eta mu)

The :eta method returns a sequence of linear predictor values for a particular mean sequence. The :means method is the inverse of :eta: it returns mean values for specified values of the linear predictor. The :derivs method returns the values of

at the specified mean values. As an example, for the log-link object these three methods are defined as

```(defmeth log-link :eta (mu) (log mu))
(defmeth log-link :means (eta) (exp eta))
(defmeth log-link :derivs (mu) (/ mu))
```

Alternative link structures can be constructed by setting up a new prototype and defining appropriate :eta, :means, and :derivs methods. Parametric link families can be implemented by providing one or more slots for holding the parameters. The power link is an example of a parametric link family. The power link prototype is defined as

```(defproto power-link-proto '(power) () glim-link-proto)
```
The slot power holds the power exponent. An accessor method is defined by
```(defmeth power-link-proto :power () (slot-value 'power))
```
and the :isnew initialization method is defined to require a power argument:
```(defmeth power-link-proto :isnew (power) (setf (slot-value 'power) power))
```
Thus a power link for a particular exponent, say the exponent 2, can be constructed using the expression
```(send power-link-proto :new 2)
```

To complete the power link prototype, we need to define the three required methods. They are defined as

```(defmeth power-link-proto :eta (mu) (^ mu (send self :power)))
```
```(defmeth power-link-proto :means (eta) (^ eta (/ (slot-value 'power))))
```
and
```(defmeth power-link-proto :derivs (mu)
(let ((p (slot-value 'power)))
(* p (^ mu (- p 1)))))
```
The definition of the :means method could be improved to allow negative arguments when the power is an odd integer. Finally, the :print method is redefined to reflect the value of the exponent:
```(defmeth power-link-proto :print (&optional (stream t))
```
Thus a square link prints as
```> (send power-link-proto :new 2)