Page 57 - Computational Statistics Handbook with MATLAB
P. 57

Chapter 2: Probability Concepts                                  43

                             The covariance matrix is symmetric  Σ ΣΣ Σ =(  T  Σ Σ Σ Σ)   positive definite (all eigenval-
                                  Σ Σ Σ Σ
                             ues of   are greater than zero) for most applications of interest to statisticians
                             and engineers.
                              We illustrate some properties of the multivariate normal by looking at the
                             bivariate (d =  2  ) case. The probability density function for a bivariate nor-
                             mal is represented by a bell-shaped surface. The center of the surface is deter-
                                                µ µ µ µ
                             mined by the mean   and the shape of the surface is determined by the
                                       Σ Σ Σ Σ
                             covariance  . If the covariance matrix is diagonal (all of the off-diagonal ele-
                             ments are zero), and the diagonal elements are equal, then the shape is circu-
                             lar. If the diagonal elements are not equal, then we get an ellipse with the
                             major axis vertical or horizontal. If the covariance matrix is not diagonal, then
                             the shape is elliptical with the axes at an angle. Some of these possibilities are
                             illustrated in the next example.

                             Example 2.10
                             We first provide the following MATLAB function to calculate the multivari-
                             ate normal probability density function and illustrate its use in the bivariate
                             case. The function is called csevalnorm, and it takes input arguments
                             x,mu,cov_mat. The input argument x is a matrix containing the points in
                             the domain where the function is to be evaluated, mu is a d-dimensional row
                             vector, and cov_mat is the d ×  d   covariance matrix.

                                function prob = csevalnorm(x,mu,cov_mat);
                                [n,d] = size(x);
                                % center the data points
                                x = x-ones(n,1)*mu;
                                a = (2*pi)^(d/2)*sqrt(det(cov_mat));
                                arg = diag(x*inv(cov_mat)*x');
                                prob = exp((-.5)*arg);
                                prob = prob/a;
                             We now call this function for a bivariate normal centered at zero and covari-
                             ance matrix equal to the identity matrix. The density surface for this case is
                             shown in Figure 2.10.
                                % Get the mean and covariance.
                                mu = zeros(1,2);
                                cov_mat = eye(2);% Identity matrix
                                % Get the domain.
                                % Should range (-4,4) in both directions.
                                [x,y] = meshgrid(-4:.2:4,-4:.2:4);
                                % Reshape into the proper format for the function.
                                X = [x(:),y(:)];
                                Z = csevalnorm(X,mu,cov_mat);
                                % Now reshape the matrix for plotting.
                                z = reshape(Z,size(x));
                                subplot(1,2,1) % plot the surface



                             © 2002 by Chapman & Hall/CRC
   52   53   54   55   56   57   58   59   60   61   62