• No results found

2.2 A Suite of Useful Shape Constraints

2.2.4 The Bivariate Case

Defining constraints in higher dimensions is more difficult than in the univariate case, and it is also harder to implement efficient functions for checking constraint validity. Several constraints applicable to two-dimensional data are considered in this section, to explore some of the possibilities.

The first constraint is bivariate unimodality. There are several non-equivalent definitions of unimodality that can be applied to multivariate densities, such as star unimodality, level set unimodality, and α-unimodality, among others (see, for exam- ple, Gupta, 1976; Klemel¨a, 2009, p. 38–39). Star unimodality finds application in Chapter 5. Constraint 13 provides one way of defining it.

Constraint 13 (Star unimodality) A multivariate densityf is star unimodal with mode m if it is a decreasing function along all rays emanating from m.

For present purposes, however, the following definition of unimodality is sufficient, and acts as an easily-verified constraint in the bivariate case.

Constraint 14 (Bivariate unimodality) A bivariate density f is unimodal with mode m if it has only one local maximum (at m), and no unique local minima.

The stipulation that the density have no local minima is required because a bivariate density with only one mode can have one or more local minima as well. Any such

Figure 2.6: A unimodal bivariate density with a local minimum.

minimum will have the appearance of a dimple in the downward-sloping side of the density (see Figure 2.6).

To check these constraints and the ones to follow numerically, it is necessary to evaluate the density function at a rectangular grid of points. Letv= [v1· · ·vm2]

T and

z = [z1· · ·zm1]

T be two regularly-spaced, increasing vectors of grid points covering

the range of the data in dimensions 1 and 2, respectively. Then we may use the notationgrid(v,z)to represent them1×m2 grid with points at coordinates (vi, zj).

A simple means of checking the validity of Constraint 14 is given in the function

isuni2D (Algorithm 2.4). The function evaluates the density over a rectangular grid, producing a matrix of function values. An element of this matrix is taken to corre- spond to a local maximum if its value is higher than those of its eight neighbouring points. Note that Algorithm 2.4 does not require the mode location as an input; this would certainly be required if setting up this constraint using mathematical program- ming.

Another option is to base the constraints on the density’s marginal or conditional distributions. In Constraints 15 and 16, these distributions are required to be uni- modal.

Constraint 15 (Unimodal marginals) A bivariate densityf satisfies the unimodal marginals constraint if both of its marginal distributions are unimodal (they satisfy

Algorithm 2.4: Checking for 2-D unimodality (isuni2D).

Input: ˆf, a bivariate density estimator; v and z, vectors of grid points in each dimension.

Output: TF, a logical variable (true if the constraint is satisfied). Set f ← a matrix of ˆf values evaluated at grid(v,z).

Set nmax ← the number of local max. inf. *Compare points to 8 neighbours*

Set nmin ← the number of local max. in −f. *Counts minima*

if nmax = 1 and nmin = 0

TF ← true

else

TF ← false

Constraint 1).

Constraint 16 (Unimodal conditionals) A bivariate density f satisfies the uni- modal conditionals constraint if all of its conditional densities, in either variable, are unimodal (they satisfy Constraint 1).

The unimodal marginals constraint is a relatively weak shape restriction, but it could be of interest if there is reason to believe each of the variables in question should have unimodal densities. Other marginal constraints (bell-shape, for example) could be used instead.

Algorithm 2.5: Checking for unimodal marginals (unimarg).

Input: ˆf, a bivariate density estimator; v and z, vectors of grid points in each dimension.

Output: TF, a logical variable (true if the constraint is satisfied). Set f ← a matrix of ˆf values evaluated at grid(v,z).

Set f1 ← a vector with jth element P

ifij.

Set f2 ← a vector with ith element Pjfij.

if f1 and f2 are both unimodal *Use Algorithm 2.2*

TF ← true

else

TF ← false

The unimodal conditionals constraint, on the other hand, is a strong shape require- ment, and should enforce a higher degree of smoothness onf. In practice, Constraint

15 and Constraint 16 can both be checked using a similar approach, as shown in Algorithms 2.5 and 2.6. In both cases the density is evaluated at a rectangular grid of points, and the resulting matrixf is used to approximate the appropriate marginal or conditional densities. The haskmodes function is then employed to check for uni- modality. Note that checking for unimodal conditionals is more computationally intensive, because it requires checking for the unimodality of every row and column of f.

Algorithm 2.6: Checking for unimodal conditionals (unicond).

Input: ˆf, a bivariate density estimator; v and z, vectors of grid points in each dimension.

Output: TF, a logical variable (true if the constraint is satisfied). Set f ← an m1×m2 matrix of ˆf values evaluated at grid(v,z).

for i= 1 tom1

Set fi ←the ith row of f.

if fi is NOT unimodal *Use Algorithm 2.2*

TF ← false

Terminate the algorithm.

for i= 1 tom2

Set fj ← the jth column of f.

if fj is NOT unimodal *Use Algorithm 2.2*

TF ← false

Terminate the algorithm. TF ← true

The last two constraints to be considered involve level sets of a bivariate density function. It is common to use contour plots when visualizing a bivariate density, and each contour in the plot is a level set enclosing a certain probability mass. Often sampling variability makes the outer contours in such a plot convoluted and dis- contiguous. The effect of sampling variability on these contours can be reduced by requiring that certain level sets be connected, or enclose a convex region.

Constraint 17 (Contiguous contour) Let A be a level set of a bivariate density

f, defined either directly by the function value, or by the probability mass it encloses. Then f satisfies the constraint if A is a connected set. In this case A forms a con- tiguous contour.

Constraint 18 (Convex contour) Let A be the level set of a bivariate density

f(x), with level c. Then f satisfies the constraint if {x : f(x) ≥ c} is a convex set. In this case A forms a convex contour.

Making certain level sets connected is a way of selectively smoothing certain re- gions of a contour plot. Requiring that the outermost contours be drawn as single lines allows the low-density regions of the plot to be smoothed without affecting the estimate in higher-density areas. See for example the heart disease data (Figure 2.2). Applying Constraint 17 to the outermost three contours would improve the qualita- tive appearance of the estimate with h = 0.3. A higher degree of smoothing can be imposed by requiring the contours to be not only contiguous, but convex as well.

The best way to implement constraints 17 and 18 will depend on the system being used to produce the contour plots. For this reason no algorithms for do- ing so are presented here. The plots in this thesis were produced using MATLAB (The Mathworks, Inc., 2007), and in this environment the contour plotting function returns a data structure that makes it easy to inspect individual contours to see if they are contiguous or convex6.

Constraints 17 and 18 again demonstrate the utility of defining constraints in a black-box manner. Computer implementation of these constraints, in the form of a binary constraint-checking function, is easy. Expressing the constraint in a form suitable for mathematical programming, on the other hand, would be a daunting task.