I am writing a t test using the code here :

How to perform two-sample t-tests in R by inputting sample statistics rather than the raw data?

But I would like to use the root of the variance as an estimator of the standard deviation.

Why? Because I can pass only once through my data to have mean and variance.

For standard deviation, I need the mean so I need to scan my data twice.

  • 2
    $\begingroup$ The square root of the variance is in fact the standard deviation. You need to know the mean to calculate either one. $\endgroup$
    – Andrew
    Commented Mar 5, 2014 at 21:07
  • 1
    $\begingroup$ You can calculate either variance or standard deviation in one pass (but beware, there are bad algorithms and good algorithms, and the most obvious algorithms are the bad ones). $\endgroup$
    – Glen_b
    Commented Mar 5, 2014 at 22:01

1 Answer 1


Your question appears to betray a confusion.

Firstly, the standard deviation is the square root of the variance, essentially by definition (see the second paragraph). So if you have the variance, you simply take its square root to get the standard deviation.

Normally you must use the mean at some point in the calculation of either the variance or the standard deviation. It's possible to compute a variance and hence, a standard deviation without ever computing the mean, but it's less efficient than using the mean.

It's possible to have one-pass calculation of the variance (and the standard deviation since we just take square roots at the end), but the "obvious formula" based on the average of the squares minus the square of the average is not numerically stable and cannot be recommended.

A stable one-pass calculation of variance is given in this answer as pseudocode.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.