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

spcorr_n

Computes Spearman rank order correlation (Rho) correlation coefficient across the given dimension.

Available in version 6.1.0 and later.

Prototype

	function spcorr_n (
		x       : numeric,  
		y       : numeric,  
		dim [1] : integer   
	)

	return_val  :  float or double

Arguments

x

An array of any numeric type or size. The dim-th dimension is the dimension to be used.

y

An array of any numeric type and same size as x. The dim-th dimension is the dimension to be used.

dim

A scalar integer indicating which dimension of x, y to do the calculation on. Dimension numbering starts at 0.

Return value

The return value will have the same dimensions as all but the dim-th dimension of x and y. The return will be a double if x or y are double, and float otherwise.

Description

Computes Spearman rank order correlation (Rho) across the given dimension. The Spearman correlation is less sensitive than the Pearson correlation to strong outliers that are in the tails of both samples. That is because Spearman's Rho limits the outlier to the value of its rank.

This function should not be used if there are many ranked 'ties'. The formula used does not apply to this situation.

Missing values will be removed from the input x and/or y prior to doing the calculation.

 
References:
     Kendall and Stuart: THE ADVANCED THEORY OF STATISTICS, VOLUME 2, EDITION 1, 1961, PAGES 476-477.
     Snedecor and Cochran, STATISTICAL METHODS, EDITION 6, 1967, PAGES 193-195.
     Dixon and Massey, INTRODUCTION TO STATISTICAL ANALYSIS, EDITION 2, 1957, PAGES 294-295.
     Mood and Grable, 'INTRODUCTION TO THE THEORY OF STATISTICS, EDITION 2, 1963, PAGE 424.

 Source code: James J. Filliben: Nat. Bureau of Standards: DATAPAC

See Also

spcorr, rtest, escorc, escorc_n, esacv, esacr, esccr, esccv, escovc

Examples

Example 1: See: http://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient

  x   = (/ 86, 97, 99, 100, 101, 103, 106, 110, 112, 113/) 
  y   = (/  0, 20, 28,  27,  50,  29,   7,  17,   6,  12/)
  N   = dimsizes(x)

  spc = spcorr_n( x, y, 0)  ; spc = -0.1757576
  p   = rtest( spc, N, 0)   ; p   =  0.6271883

Example 2: x(2,ntim), y(2,ntim)

  x   = (/ (/ 86, 97, 99, 100, 101, 103, 106, 110, 112, 113/), \   ; (2,ntim) 
           (/ 90, 93, 96, 102, 103, 105, 106, 109, 111, 113/) /)

  y   = (/ (/  0, 20, 28,  27,  50,  29,   7,  17,   6,  12/), \
           (/  0, 10, 15,  26,  40,  35,  16,   8,   3,   1/) /)

  dimxy = dimsizes(y)
  ntim  = dimy(1)

  spc = spcorr_n( x, y, 1)     ; spc = (/ -0.1757576, -0.1151515 /)
  p   = rtest( spc, ntim, 0)    ; p   = (/  0.6271883, 0.75142    /)

Example 3: Consider x(ntim), y(ntim,nlat,mlon). Currently the spcorr_n function does not automatically 'conform' the x(ntim) array to the size and shape as the y(ntim,nlat,mlon). This must be explicitly done via the conform or conform_dims functions.

                               ; create an 'x' array that conforms to 'y'
  X   = conform(y,x,0)        ; X(ntim,nlat,mlon)   (temporary)
  spc = spcorr_n( X, y, 0)     ; spc(nlat,mlon) 
  delete(X)                    ; no longer needed

This conform could also be done within the spcorr_n function so there is no temporary array.

  spc = spcorr_n( conform(y,x,0), y, 0)     ; spc(nlat,mlon)