NCL Home > Documentation > Functions > General applied math, Statistics


Calculate the value(s) of coherence-squared required for a specified significance level and effectiove degrees-of-freedom.

Available in version 6.4.0 and later.


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"  ; This library is automatically loaded
                                                             ; from NCL V6.2.0 onward.
                                                             ; No need for user to explicitly load.

	function cohsq_p2c (
		prob  : numeric,  ; float or double
		edof  : numeric   

	return_val  :  An array of the same size, shape and shape  as prob.



A scalar or array containing probabilities (0 to 1.0).


A scalar or array containing the effective degrees-of-freedom. If an array, it must match the size and shape as prob.

Return value

Numeric (float or double) array containing coherence-squared of the same size and shape as prob.


The coherence-squared is a statistic that can be used to examine the degree of linear association between two series. It allows identification of significant frequency-domain correlation between the two time series. It is analogous to the coefficient of determination (square of the correlation coefficient) between two series.

NOTE: Phase estimates in the cross spectrum are only useful where significant frequency-domain correlation exists.

NCL's specxy_anal returns the total (FFT-based) degrees of freedom. The effective degrees-of-freedom (edof) is half that number. (See Example 4)


Data Analysis Methods in Physical Oceanography /
  William J. Emery; Thomson, Richard E.
  Elsevier, 2001 (2nd Edition); ISBN: 0444507566 (hardbound); 0444507574 (paperback).

Course Notes
  Dennis Hartmann (Univ. Washington)
  See Table 6.2 , page 187 and the associated caption on page 186

Comments on the Determination of Significance Levels of the Coherence Statistic
   Paul R. Julian
   J. of Atm. Sci. (1975), Volume 32, pp 836-837. 

Coherence Significance Levels
   Rory O. R. Y. Thompson
   Journal of the Atmospheric Sciences, 1979
   Volume 36, pp 2020-2021

Tables of the Distribution of the Coefficient of Coherence 
          for Stationary Bivariate Gaussian Processes
   Amos, D.  E., and L.  H.  Koopmans (1963) 
   Washington, Office of Technical  Services, Dept.  of Commerce. 

On the Joint Estimation of the Spectra, Cospectrum and Quadrature Spectrum of a 
          Two-dimensional Stationary Gaussian Process 
   Goodman, N.R. (1957)
   New York University

See Also

cohsq_c2p, specxy_anal


The following match the numbers of Hartmann's Table 6.2. Note: The examples use nice round effective degrees of freedom but, they may be fractional (eg: 20.37):

Example 1: Both prob and edof are scalars:

    p    = 0.95 
    edof = 10
    c2   = cohsq_p2c(c2, edof)        ; c2 = 0.283

Example 2: The prob is an array and edof is a scalar:

    p    = (/0.50, 0.90, 0.95, 0.99, 0.999 /)
    edof = 20                       
    c2   = cohsq_p2c(c2, edof)        ; c2(5)
                                      ; c2 = (/0.036, 0.112, 0.146, 0.215, 0.305 /) 

Example 3: Both prob and edof are arrays which have the same shape and size:

    p    = /0.50, 0.90, 0.95, 0.99, 0.999 /)
    edof = (/  5  ,  10  ,  20  ,  50  ,  100  /)  ; edof(5)
    c2   = cohsq_p2c(p , edof)        ; c2_1(5)
                                      ; c2 = (/0.159, 0.226, 0.146, 0.089, 0.067 /) 

Example 4: Calculate the minimum coherence-squared value required for the 95% level given the degrees of freedom returned by specxy_anal. The specxy_anal function explicitly returns the total (FFT-based) degrees-of-freedom.

    d     = 0                     ; detrending opt: 0=>remove mean 1=>remove mean and detrend
    sm    = 7                     ; smoothing periodogram: should be at least 3 and odd
    pct   = 0.10                  ; percent tapered: 0.10 common. 

                                  ; calculate the cross-spectrum
    sxydof= specxy_anal(x,y,d,sm,pct)   ; sxydof is a scalar; FFT-based dof
    printVarSummary(sxydof)   ; look at the returned variable

    edof  = sxydof/2              ; effective degrees of freedom

    p_95  = 0.95
    c2_95 = cohsq_p2c(p_95, edof) ; c2_95 is a scalar 
    print("c2_95="+sprintf("%6.3f", c2_95))

                                  ; count the number of returned coherence-squared (sdof@coher2)
                                  ; that exceed the critical value
    n_95  = num(sxydof@coher2 .ge. c2_95)

    print( n_95)