esacr, esacv, esccr, esccv

Functions for computing autocovariances, autocorrelations, crosscovariances, and crosscorrelations for an input vector with missing data. The normalizing factor in the denominator (xvar) is kept constant.


Synopsis

    function esacr(
        x        : float,
        mxlag[1] : integer
    )

    function esacv(
        x        : float,
        mxlag[1] : integer
    )

    function esccr(
        x        : float,
        y        : float,
        mxlag[1] : integer
    )

    function esccv(
        x        : float,
        y        : float,
        mxlag[1] : integer
    )

Arguments

x
Input array of any dimensionality (last dimension is npts). Missing values should be indicated by x@_FillValue. If x@_FillValue is not set, then the NCL default (-999) will be assumed.
y
Input array of same dimensionality as x.Missing values should be indicated by y@_FillValue. If y@_FillValue is not set, then the NCL default (-999) will be assumed.
mxlag
single scalar maximum lag to be estimated (0 <= mxlag <= npts)

Description

Given vector/array x, esacv and esacr compute sample autocovariances and autocorrelations respectively, returning a multi-dimensional float array of the same dimensions as x except with the last dimension npts replaced by mxlag+1.

Given vectors/arrays (x, y), esccv and esccr compute sample crosscovariances and crosscorrelations respectively, returning a multi-dimensional array of the same dimensions as x and y except with the last dimension npts replaced by mxlag+1.

In the crosscovariance and crosscorrelation computations the y data "lead" the x data.

It is recommended that mxlag not be greater than npts/3, for statistical reasons.

Currently, to calculate positive and negative lags one must invoke this function twice. (See example 5 below.)


Example 1

Consider a one-dimensional array, x. Then,
   acr = esacr(x,10)
   acv = esacv(x,10)
will calculate the autocorrelations and variances at 11 lags (0->10). acr and acv will be one-dimensional variables of length 11.

Example 2

Consider two three-dimensional arrays, y(lat,lon,time) and z(time,lat,lon) with named dimensions "time", "lat" and "lon". Then
   mxlag = 10
   acr_y = esacr(y,mxlag)
   acv_z = esacv(z(lat|:,lon|:,time|:),mxlag) ; dimension reordering
will calculate the autocorrelations and variances at (mxlag+1) lags (0->mxlag). acr_y and acv_z will have dimension sizes (nlat,mlon,mxlag+1). (NCL's dimension reordering was used in the latter case.)

Example 3

Consider two one-dimensional series x and y of the same size.
   ccr = esacr(x,y,10)
   ccv = esacv(x,y,10)
will calculate the cross-correlations and variances at 11 lags (0->10). ccr and ccv will be one-dimensional variables of length 11. The y series leads the x series in the computations.

Example 4

Consider two three-dimensional arrays, y(lat,lon,time) and z(lat,lon,time). Then
   mxlag  = 10
   ccr_yz = esccr(y,z,mxlag)
   ccv_zy = esacv(z,y,mxlag) 
will calculate the autocorrelations and variances at (mxlag+1) lags (0->mxlag). ccr_yz and ccv_zy will have dimension sizes (nlat,mlon,mxlag+1). Of course, users might have to use dimension reordering if the dimensions are not in the desired order.

Example 5

Consider two one-dimensional series x and y of the same size and the user wishes to calculate cross-correlations at positive and negative lags. Then the user will have to use the (admittedly cumbersome) procedure:
   mxlag    = 9
   y_Lead_x = esccr(x,y,mxlag)
   x_Lead_y = esccr(y,x,mxlag)    ; switch the order of the series

   ccr = new ( 2*mxlag+1, float)    
   ccr(0:mxlag-1) = x_Lead_y(1:mxlag:-1)  ; "negative lag", -1 reverses order
   ccr(mxlag:)    = y_Lead_x(0:mxlag)     ; "positive lag"
Remember that NCL is C based and does not allow negative subscripts like Fortran does (in Fortran, ccr(-mxlag:mxlag)). Thus in the above example ccr(0:mxlag-1) corresponds to lags -9,-8,...,-2,-1 and ccr(mxlag:2*mxlag) corresponds to lags 0,1,2,...,8,9.

In a future release, a single interface which does the above process will be provided.


Reference Manual Control Panel

NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?


$Revision: 1.11 $ $Date: 1999/03/22 20:49:09 $