All formulas

Statistics

Sample standard deviation

stats.sample-stdAlso called sample standard deviation, std, stdev, standard deviation

s=1n−1∑i=1n(xi−xˉ)2s = \sqrt{\frac{1}{n-1}\sum_{i=1}^{n} (x_i - \bar{x})^2}

wherexˉ=1n∑j=1nxj\bar{x} = \frac{1}{n}\sum_{j=1}^{n} x_j

Square root of the sample variance (divisor n − 1).

Notation

xx

observations

x ∈ ℝn

nn

number of observations

Size, at least 2

ss

Result: the sample standard deviation

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[2,4,4,4,5,5,7,9]x = [2, 4, 4, 4, 5, 5, 7, 9]

    Result

    s=4147\displaystyle s = \frac{4 \sqrt{14}}{7}

    ≈ 2.1380899353

  2. Given

    x=[1,2,3,4]x = [1, 2, 3, 4]

    Result

    s=153\displaystyle s = \frac{\sqrt{15}}{3}

    ≈ 1.29099444874

  3. Given

    x=[1,3]x = [1, 3]

    Result

    s=2\displaystyle s = \sqrt{2}

    ≈ 1.41421356237

Common mistakes

  • Divides by n instead of n − 1

    This is the population standard deviation (NumPy's np.std default, ddof=0); the result is sqrt((n − 1)/n) times the sample value.

    Fix: Divide by n − 1 inside the square root, or call np.std(x, ddof=1).

  • Returns the variance

    The final square root is missing.

    Fix: Take the square root of the sample variance.

Source

  • NIST/SEMATECH e-Handbook, §1.3.5.6

    NIST/SEMATECH e-Handbook of Statistical Methods. https://www.itl.nist.gov/div898/handbook/ Last updated 2022-04-27. doi:10.18434/M32189

    doi.org