s-news
[Top] [All Lists]

3 Dimensional Cross Variance

To: "s-news" <s-news@lists.biostat.wustl.edu>
Subject: 3 Dimensional Cross Variance
From: "Paul Lasky" <phlasky@earthlink.net>
Date: Thu, 22 Apr 2004 16:25:34 -0700
Reply-to: phlasky@earthlink.net

This is a pretty basic question but  . . . is there a better way, without explicit looping, to compute the  3 dimensional cross variance and a diagonal ?  The crossvariance defined as:
      crossvar = array( rep( NA,  p^3 ), dim=c ( p, p, p ) )
      for( i in 1 : p )
        {
          for( j in 1 : p )
           {
             for( k in 1 : p )
              {
                crossvar[ i, j, k ] = 0.5 * t( x[ , i ] ) % * % Q[ , , k] % * % x[ , j ] 
                   }
               }
         }
where x are the  bi-variates, and Q is the covariance array.
 
  The diag(crossvar) is defined as:
 
         crossvar.diag = matrix( rep( NA, p^2), nrow = p)
         for ( i in 1: p )
           {
             for( j in 1: p )
              {
                crossvar.diag[ i, j ] = 0.5 * t ( x[ , i] ) % * % Q[ , , j ] % * % x[ , i ]  
              }
          }
 
Paul Lasky
P & B Consultants
Rancho Santa Fe, CA .
 

<Prev in Thread] Current Thread [Next in Thread>