Collapse axes by calculating their standard deviation.
The standard deviation may be adjusted for the number of degrees of freedom and may be calculated with weighted values.
Missing data array elements and those with zero weight are omitted from the calculation.
The unweighted standard deviation, \(s\), of \(N\) values \(x_i\) with mean \(m\) and with \(N-ddof\) degrees of freedom (\(ddof\ge0\)) is
The weighted standard deviation, \(\tilde{s}_N\), of \(N\) values \(x_i\) with corresponding weights \(w_i\), weighted mean \(\tilde{m}\) and with \(N\) degrees of freedom is
The weighted standard deviation, \(\tilde{s}\), of \(N\) values \(x_i\) with corresponding weights \(w_i\) and with \(N-ddof\) degrees of freedom (\(ddof>0\)) is
where \(f\) is the smallest positive number whose product with each weight is an integer. \(f \sum_{i=1}^{N} w_i\) is the size of a new sample created by each \(x_i\) having \(fw_i\) repeats. In practice, \(f\) may not exist or may be difficult to calculate, so \(f\) is either set to a predetermined value or an approximate value is calculated. The approximation is the smallest positive number whose products with the smallest and largest weights and the sum of the weights are all integers, where a positive number is considered to be an integer if its decimal part is sufficiently small (no greater than \(10^{-8}\) plus \(10^{-5}\) times its integer part). This approximation will never overestimate \(f\), so \(\tilde{s}\) will never be underestimated when the approximation is used. If the weights are all integers which are collectively coprime then setting \(f=1\) will guarantee that \(\tilde{s}\) is exact.
Parameters: |
|
---|---|
Returns: | out : cf.Data |
Examples: |
Some, not wholly comprehensive, examples:
>>> d = cf.Data([1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4])
>>> e = cf.Data([1, 2, 3, 4])
>>> d.sd(squeeze=False)
<CF Data: [1.06262254195] >
>>> d.sd()
<CF Data: 1.06262254195 >
>>> e.sd(weights=[2, 3, 5, 6])
<CF Data: 1.09991882817 >
>>> e.sd(weights=[2, 3, 5, 6], f=1)
<CF Data: 1.06262254195 >
>>> d.sd(ddof=0)
<CF Data: 1.02887985207 >
>>> e.sd(ddof=0, weights=[2, 3, 5, 6])
<CF Data: 1.02887985207 >