Computes an unbiased estimate the variance of all input points.
function variance ( value : numeric ) return_val  : float or double
An array of any dimensionality.
Returns a floating point value, or type double if value is of type double.
This function computes the unbiased estimate of the variance for all input points, regardless of the dimensionality of the input. Technically, this function calculates an estimate of the sample variance. This means that it divides by [1/(N-1)] where N is the total number of non-missing values.
The following calculates the population and sample variance of 5 values. For illustration, a step-by-step calculation of the variance is done. The variances returned by NCL's three built-in variance funtions are included.
f = (/ 7, 9, -2, -8, 2/) favg = avg(f) ; average fdev = f-favg ; deviations fdev2 = fdev^2 ; deviations squared nf = dimsizes(f) ; N pvar = sum(fdev2)/nf ; population variance svar = sum(fdev2)/(nf-1) ; sample variance var1 = variance(f) var2 = dim_variance(f) var3 = dim_variance_n(f,0) print("pvar="+pvar+" svar="+svar+" var1="+var1+" var2="+var2+" var3="+var3) === output: pvar=37.84 svar=47.3 var1=47.3 var2=47.3 var3=47.3
The following calculates the overall variance of a (3,5,10) array, f.