NCL Home > Documentation > Functions > General applied math


Computes sample auto-correlations on the given dimension.

Available in version 6.5.0 and later.


	function esacr_n (
		x         : numeric,  
		mxlag [1] : integer,  
		dim   [1] : integer   

	return_val  :  numeric



An array of any numeric type or size.


A scalar integer. It is recommended that 0 <= mxlag <= N/4. This is because the correlation algorithm(s) use N rather than (N-k) values in the denominator (Chatfield Chapter 4).


A scalar integer indicating which dimension of x to do the calculation on. Usually this would be the dimension that represents time.

Return value

An array of the same size as x except that the dimension represented by dim will be replaced by mxlag+1. Double values are returned if x is double, and float otherwise.


Computes sample auto-correlations using the equations found in Chatfield [The Analysis of Time Series, 1982, Chapman and Hall]. This function is identical to esacr, except it allows you to specify which dimension to do the operation on. Missing values are allowed.

Algorithm: Here, q(t) and q(t+k) refer to the lefttmost dimension. k runs from 0 to mxlag.

  c(k) = SUM [(q(t)-qAve)*(q(t+k)-qAve)}]/qVar       
The dimension shape of c is a function of the dimension shape of the x arrays. The following illustrates dimensioning:

        x(N)          c(mxlag)
        x(M,N),       c(mxlag,M)
        x(K,M,N)      c(mxlag,K,M)
        x(L,K,M,N)    c(mxlag,L,K,M)

When calculating lag auto-correlations, Chatfield (pp. 60-62, p. 173) recommends using the entire series (i.e. all non-missing values) to estimate mean and standard deviation rather than (N-k) values. The reason is better mean-square error properties.

There are trade-offs to be made. For example, it is possible that correlation coefficients calculated using qAve and qStd based on the entire series can lead to correlation coefficients that are > 1. or < -1. This is because the subset (N-k) points might be a series with slightly different statistical characteristics.

See Also

esacr, esacv, esccr, esccv, escorc, escorc_n, escovc, equiv_sample_size


Example 1

The following will calculate the auto-correlation for a one dimensional array x(N) at 11 lags (0->10). The result is a one-dimensional array of length 11.

    acr = esacr_n(x,10,0)   ; acr(0:10)
Example 2

The following will calculate the auto-correlation for a three-dimensional array x(ntim,nlat,nlon) at mxlag + 1 lags (0->mxlag).

    mxlag = 10
    acr   = esacr_n(x,mxlag,0) ; acr(mxlag+1,nlat,nlon)