7.3 Weights & Constraints

The estimation functions 15668 glmest and 15671 doglm are able to handle special cases as prior weights, replications (automatic search for replications) and constraints on parameters (fix parameters). We will demonstrate this by means of a second running example.


7.3.1 Prior Weights

Consider the lines

  x = read("lizard")
  x = paf(x,(x[,6]!=0))
  y = x[,5]
  m = x[,6]
  x = matrix(rows(x))~x[,1:3]~(x[,4]==1)~(x[,4]==2)
15708 XLGglm03.xpl

which read the lizard data (McCullagh and Nelder; 1989) containing the daytime habits of the two species of lizards (see Data Sets (B.5)). Columns 1 to 4 are the explanatory variables x. Note that we create dummies from x[,4] and include a constant by adding matrix(rows(x)). The fifth column (the dependent variable y) is the number of grahami lizards who decided for a certain site. Finally, the sixth column of this dataset contains the total number of lizards who decided for the site. Hence, the sixth column is a prior weight vector for this data. Note that it is just the binomial index vector which can also be interpreted as the number of replications in x.

We proceed as follows in the estimation here:

  opt=glmopt("wx",m)
  g=glmest("bilo",x,y,opt)
15716 XLGglm03.xpl

The code "bilo" stands for the logit model (binomial with logit linkfunction). The list opt of optional parameters now contains the weight vector as component opt.wx. The resulting vector of estimated coefficients is
  Content of object g.b
  [1,]  1.94469
  [2,]  1.12999
  [3,] -0.76263
  [4,] -0.84727
  [5,]  0.22711
  [6,] -0.73681
An output display can be obtained manually in this case, see Subsection 7.5.2.


7.3.2 Replications in Data

There are two types of replications (or ties) that can occur:

The first case (replications in x with different y values) can be directly handled only in Binomial models. In this case, the matrix should contain the different realizations of the explanatory variables, the response vector y should contain the summed response values corresponding to each line of x. The number of replications needs to be given as prior weights opt.wx in the list of optional parameters opt.

For models other than the Binomial, the original matrix x (with multiple entries) and the original response vector y should be given to 15778 glmest or 15781 doglm . Both will search automatically for replications in data.

The second case (replications in x and y jointly) can simply be handled by giving the number of replications as component opt.wx in the list of optional parameters opt. opt.wx may be a single number if the number of replications in x and y is constant. For an example, see the previous Subsection 7.3.1.


7.3.3 Constrained Estimation

Returning to the running lizard example of Subsection 7.3.1, the resulting vector of estimated coefficients is

  Content of object g.b
  [1,]  1.94469
  [2,]  1.12999
  [3,] -0.76263
  [4,] -0.84727
  [5,]  0.22711
  [6,] -0.73681
Suppose now that we are interested in estimating the same model under the constraint that the last coefficient equals exactly -1. The new estimate could be used in hypothesis testing.

This type of constrained estimation can be done by introducing an offset into the model and omitting the last variable instead. Continuing with

  offset=-x[,6]
  opt=glmopt("off",offset,opt)
  c=glmest("bilo",x[,1:5],y,opt)
15845 XLGglm04.xpl

will now yield the estimated coefficients under the constraint $ b_6=$-1:

  Content of object b
  [1,]  2.0685
  [2,]  1.1409
  [3,] -0.7703
  [4,] -0.86002
  [5,]  0.11794