The sample variance computed with \(N - 1\) in the denominator is
unbiased for the population variance \(\sigma^2\), but its square
root \(s\) is biased downward for \(\sigma\). Under normality, the
multiplicative bias is
$$E[s] \;=\; \sigma \cdot c_N^{-1},
\qquad
c_N \;=\; \sqrt{(N - 1)/2}\,
\cdot \Gamma((N - 1)/2)\,/\,\Gamma(N/2),$$
(Holtzman, 1950). Multiplying \(s\) by \(c_N\) therefore yields an
unbiased estimator of \(\sigma\). The correction is non-trivial in
small samples: \(c_N\) is about 1.064 at \(N = 5\), 1.028 at
\(N = 10\), 1.009 at \(N = 30\), and is essentially 1 by
\(N = 100\) (about 1.003). For most applied work the bias of \(s\) is small
enough to ignore, but it matters when \(s\) feeds into downstream
quantities (variance components, standardizers, planning calculations)
at small \(N\).
Implementation note: the factor \(c_N\) is computed via lgamma
to avoid the overflow of gamma above \(N \approx 340\), so the
function is numerically stable for arbitrarily large \(N\).