escorc
Computes sample cross-correlations at lag 0 only.
Prototype
function escorc ( x : numeric, y : numeric ) return_val : numeric
Arguments
xAn array of any numeric type or size. The rightmost dimension is usually time.
yAn array of any numeric type or size. The rightmost dimension is usually time. The size of the rightmost dimension must be the same as x.
Description
Computes sample cross-correlations at lag 0 only. If a lagged correlations is required, use esccr. Missing values are allowed. This function can be used to determine:
- a "one-point-correlation-map" where one point is used to cross-correlate with all other points (see example 4 below)
- an unweighted "pattern correlation" (aka, "anomaly correlation") which measures the degree of overall agreement between two grids (see examples 4-7).
cor = SUM [(X(t)-Xave)*(Y(t)-Yave)}]/(Xstd*Ystd)
The dimension sizes(s) of c are a function of the dimension sizes of
the x and y arrays. Type double is returned if x or y are double,
and float otherwise. The following illustrates dimensioning:
x(N), y(N) c
x(N), y(K,M,N) c(K,M)
x(I,N), y(K,M,N) c(I,K,M)
x(J,I,N), y(L,K,M,N) c(J,I,L,K,M)
Special case when dimensions of all x and y are identical:
x(J,I,N), y(J,I,N) c(J,I)
The correlation coefficient (r) for n pairs of independent observations can be tested against the null hypothesis (ie.: no correlation) using the statistic
r*sqrt[ (n-2)/(1-r^2) ]
This statistic has a Student t distribution with
n-2 degrees of freedom.
See Also
esacv, esacr, esccr, esccv, escovc
Examples
Example 1
The following will calculate the cross-correlation for a two one-dimensional arrays x(N) and y(N).
ccr = escorc(x,y) ; ccr is a scalar
Example 2
The following will calculate the cross-correlation for one two-dimensional array y(lat,lon) and one one-dimensional array x(time).
ccr = escorc(x,y) ; ccr(lat,lon)
Example 3
Consider x(neval,time) and y(lat,lon,time)
ccr = escorc(x,y) ; ccr(neval,lat,lon)
Example 4
Consider y(nl,ml,time) where nl and ml are specified by the user and y(lat,lon,time). The result is a "one-point correlation pattern". Basically, a specific point is correlated with all other points.
nl = 32 ; for example
ml = 64
ccr = escorc(y(nl,ml,:),y) ===> ccr(lat,lon)
Example 5
Compute the unweighted "pattern correlation" between grid1(nlat,mlon) and grid2(nlat,mlon). Use NCL's ndtooned function to make one long series. This will yield the pattern correlation. If missing data are present in one or both of the grids, then grid1@_FillValue and grid2@_FillValue must be set.
r = escorc(ndtooned(grid1),ndtooned(grid2))
Example 6
Compute the unweighted pattern correlations between two climatologies for each month of the year (ntim=12).
r = new ( ntim, typeof(grid1) )
do nt=0,ntim-1
r(nt) = escorc(ndtooned(grid1(nt,:,:)),ndtooned(grid2(nt,:,:)))
end do
Example 7
Calculate the unweighted pattern correlations in the northern hemisphere mid-latitudes for each month of the year. Further, let grid1 and grid2 have coordinate variables (time,lat,lon) so that coordinate subscripting can be used.
r = new ( ntim, typeof(grid1) )
do nt=0,ntim-1
r(nt) = escorc(ndtooned(grid1(nt,{25:60},:)),ndtooned(grid2(nt,{25:60},:)) )
end do
Example 8
To obtain the weighted pattern correlation (anomaly correlation) the following approach should be used. Consider two grids x(lat,lon) and y(lat,lon) where wgt[*] can be the gaussian weights or the cosines-of-latitude.
xAvgArea = wgt_areaave(x, wgt, 1.0, 1) ; weighted area average
yAvgArea = wgt_areaave(y, wgt, 1.0, 1)
xAnom = x - xAvgArea ; anomalies
yAnom = y - yAvgArea
WGT = conform(x,wgt,0) ; WGT(lat,lon)
covxy = sum(xAnom*yAnom*WGT) ; weighted anomaly covariance
r = covxy/( sqrt(sum(WGT*xAnom^2)) *sqrt(sum(WGT*yAnom^2)) )