BivariateTools           package:fMultivar           R Documentation

_H_a_n_d_l_i_n_g _M_i_s_s_i_n_g _V_a_l_u_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     A collection and description of functions  for managing bivariate
     data sets. The functions include a grid generator, a kernel
     density  estimator, a histogram counter, and a suite of bivariate
     elliptical distribution functions. 

     The functions are: 

       'grid2d'         Creates from two vectors x-y grid coordinates,
       'density2d'      returns 2D Kernel Density Estimates,
       'hist2d'         returns 2D Histogram Counts,
       'integrate2d'    integrates over a two dimensional unit square,
       'pnorm2d'        computes bivariate normal distribution function,
       'dnorm2d'        computes bivariate normal density function,
       'rnorm2d'        generates bivariate normal random deviates,
       'pcauchy2d'      computes bivariate Cauchy distribution function,
       'dcauchy2d'      computes bivariate Cauchy density function,
       'rcauchy2d'      generates bivariate Cauchy random deviates,
       'pt2d'           computes bivariate Student-t distribution function,
       'dt2d'           computes bivariate Student-t density function,
       'rt2d'           generates bivariate Student-t random deviates,
       'delliptical2d'  computes  bivariate density for elliptical distributions.

_U_s_a_g_e:

     grid2d(x = (0:10)/10, y = x)
     density2d(x, y = NULL, n = 20, h = NULL, limits = c(range(x), range(y))) 
     hist2d(x, y = NULL, n = c(20, 20))
     integrate2d(fun, error = 1.0e-5, ...)

     pnorm2d(x, y = x, rho = 0)
     dnorm2d(x, y = x, rho = 0)
     rnorm2d(n, rho = 0)

     pcauchy2d(x, y = x, rho = 0)
     dcauchy2d(x, y = x, rho = 0)
     rcauchy2d(n, rho = 0)

     pt2d(x, y = x, rho = 0, nu = 4)
     dt2d(x, y = x, rho = 0, nu = 4)
     rt2d(n, rho = 0, nu = 4)

     delliptical2d(x, y = x, rho = 0, param = NULL, type = c("norm", "cauchy", "t", 
         "logistic", "laplace", "kotz", "epower"), output = c("vector", "list"))

_A_r_g_u_m_e_n_t_s:

   error: [integrate2d] - 
           the error bound to be achieved by the integration formula. A
          numeric value. 

     fun: [integrate2d] - 
           the function to be integrated. The first argument requests
          the x values, the second the y values, and the remaining are
          reserved for recise in a  matrix with one row. 

     The function 'tr' computes the trace of a square matrix which is
     the sum of the diagonal elements of the matrix under
     consideration. 

     The function 'rk' computes the rank of a matrix which is  the
     dimension of the range of the matrix corresponding to the number 
     of linearly independent rows or columns of the matrix, or to the 
     number of nonzero singular values. The rank of a matrix is also
     named inear map.  

     The function 'norm' computes the norm of a matrix. Three choices 
     are possible:  'p=1' - The maximum absolute column sum norm which
     is defined  as the maximum of the sum of the absolute valued
     elements of columns  of the matrix. 'p=2' - The spectral norm is
     "the norm" of a matrix 'X'.  This value is computed as the square
     root of the maximum eigenvalue  of 'CX' where 'C' is the conjugate
     transpose. 'p=Inf' - The maximum absolute row sum norm is defined 
     as the maximum of the sum of the absolute valued elements of rows
     of the matrix. 

     'More Linear Algebra:' 

     The function 'chol' returns the Cholesky factor matrix, 'eigen'
     returns eigenvalues and eigenvectors, 'svd' returns the singular
     value decomposition, 'kappa' estimate the condition number of a
     matrix, 'qr' returns the QR decomposition of a matrix, 'ginv'
     returns the Moore-Penrose generalized inverse, 'solve' solves a
     system of linear equations, use 'backsolve' when the matrix is
     upper triangular, and 'forwardsolve' when the matrix is lower
     triangular. 

     'Time Series:' 
      The function 'pdl' returns a regressor matrix suitable  for
     polynomial distributed lags.  
      The function 'tslag' returns a lagged/led vector or matrix  for
     given time series data.

_A_u_t_h_o_r(_s):

     Marina Shapira and David Firth for the 'mexp' function, 
      Diethelm Wuertz for the Rmetrics R-port.

_R_e_f_e_r_e_n_c_e_s:

     Higham N.J., (2002); _Accuracy and Stability of Numerical
     Algorithms_,  2nd ed., SIAM.

     Golub, van Loan, (1996); _Matrix Computations_,  3rd edition.
     Johns Hopkins University Press. 

     Ward, R.C., (1977);   _Numerical computation of the matrix
     exponential with  accuracy estimate_, SIAM J. Num. Anal. 14,
     600-610.

     Moler C., van Loan C., (2003); _Nineteen dubious ways to compute
     the exponential of a matrix,  twenty-five years later_, SIAM
     Review 45, 3-49.

_E_x_a_m_p_l_e_s:

     ## SOURCE("fMultivar.6A-MatrixAddon")

     ## Create Pascal Matrix:
        P = pascal(3)
        P
        # Create lower triangle matrix
        L = triang(P)
        L
        # Extract diagonal part
        diag(P)
        
     ## Add/Subtract/Multiply/Divide:  
        X = P
        # Multiply matrix with a constant
        3 * X
        # Multiply two matrices elementwise
        X * P                     
        # Multiplies rows/columns of a matrix by a vector
        X %*% diag(P)            
        diag(P) %*% X           
            
     ## Operate on Subsets of a Matrix:
        n = 3; i = 2; j = 3
        D = diag(1:3)
        # Return the dimension of a matrix
        dim(P)                         
        # Get the last colum of a matrix
        P[, ncol(P)]                   
        # Delete a column of a matrix
        P[, -i]                      
        # Permute the columns of a matrix
        P[c(3, 1, 2), ]              
        # Augments matrix horizontally 
        cbind(P, D)                           
           
     ## Apply a function to all Elements of a Matrix: 
        # Return square root for each element
        sqrt(P)
        # Exponentiate the matrix elementwise
        exp(P)
        # Compute the median of each column
        apply(P, 2, "median") 
        # Test on all elements of a matrix       
        all( P > 2 )   
        # test on any element in a matrix                
        any( P > 2 )                  
          
     ## More Matrix Operations:
        # Return the product of two matrices
        P %*% D   
        # Return the Kronecker Product                     
        P %x% D         