# How to calculate standard deviation when only mean of the data and sample size is available?

Many a times it happens that you get comprehensive data at a group level and you have to compare one group against another but you don't have the data points separated. In these cases, how do we get standard deviation/standard error calculated from only the mean of the group and sample size? Is there any proofs available for this?

• Do you ask in full generality, or do you have a special situation in mind? In full generality, the answer is: it is not possible to retrieve the standard deviation from the mean.
– Ute
Sep 6 at 18:16
• probably, you can compute standard error as well as standard deviation assuming population mean is zero. Sep 7 at 14:28
• @SubhashC.Davar why would you assume that? Sep 7 at 15:03
• see below the answer by : Graipher allows calculating the standard deviation from the mean and the number of samples. The mean of this distribution is given by μ=np , where n is the sample size and p is the probability of success. The standard deviation is given by σ=Var−−−−√=np(1−p)−−−−−−−−√=μ(1−μ/n)−−−−−−−−−√=μ−μ2/n−−−−−−−√ There are possibly even more distributions where the standard deviation is just a function of the mean (and sample size Sep 8 at 0:25

It's impossible. Consider any vector that has a mean of $$0$$ - multiply the values by $$100$$, and the standard deviation also increases by a factor of $$100$$, but the mean and sample size are unchanged. Both vectors have the same mean and $$n$$, but different SD. In general, you cannot find the standard deviation of the data given only the mean value and number of data points.

In general this is not possible, as noted in the other answers.

But, if you know (or assume) something about the underlying distribution from which the data points have been drawn, then it is sometimes possible.

The following table shows distributions where it is indeed relatively easy to do so. Shown are the parameters, mean $$\mu$$ and variance as given in the different Wikipedia links, as well as the standard deviation $$\sigma = \sqrt{Var}$$ with the mean substituted in and simplified.

Distribution Parameters Mean $$\mu$$ Variance Standard Deviation
Poisson $$\lambda \ge 0$$ $$\lambda$$ $$\lambda$$ $$\sqrt{\mu}$$
Exponential $$\lambda > 0$$ $$1/\lambda$$ $$1/\lambda^2$$ $$\mu$$
Binomial $$n \in \mathbb{N}, 0 < p < 1$$ $$np$$ $$np(1-p)$$ $$\sqrt{\mu - \mu^2/n}$$
(Central) chi-squared $$k \in \mathbb{N}$$ $$k$$ $$2k$$ $$\sqrt{2\mu}$$
Maxwell-Boltzmann $$a>0$$ $$2a\sqrt{2/\pi}$$ $$\frac{a^2(3\pi-8)}{\pi}$$ $$\mu\sqrt{\frac{3}{8}\pi-1}$$

You may note that most of these distributions depend on only one parameter. I would conjecture that actually most single-parameter distributions for which closed-form solutions for both mean and variance exist allow you to deduce the standard deviation from the mean. So this table is probably incomplete.

Conversely, if the distribution depends on two parameters, it is quite unlikely that there is a simple relationship between mean and variance.

The following table shows some distributions where it is not possible to deduce the standard deviation just from the mean (and the sample size). Since many distributions fall into that category, this table is definitely not complete.

Distribution Parameters Mean $$\mu$$ Variance
Uniform $$a < b$$ $$\frac{1}{2}(a+b)$$ $$\frac{1}{12}(b-a)^2$$
Normal $$\mu, \sigma$$ $$\mu$$ $$\sigma^2$$
Student's-t $$\nu > 0$$ 0, for $$\nu > 1$$ $$\nu/(\nu-2)$$, for $$\nu > 2$$
Beta $$\alpha > 0, \beta > 0$$ $$\alpha/(\alpha + \beta)$$ $$\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}$$
Gamma $$\alpha>0, \beta>0$$ $$\alpha/\beta$$ $$\alpha/\beta^2$$

Note in particular the Student's t-distribution, which may be relevant due to the tag on the question.

• binomial is the common case for ecommerce etc (click through rates etc). "The best minds of my generation are thinking about how to make people click ads. That sucks." - Jeff Hammerbacher Sep 7 at 11:58

#### Mathematical Reason

The only way you can meaningfully compare groups in this situation is simply to use their raw mean estimates and go from there. Any inferential test here, as Nuclear already pointed out, will have no applicability without standard error estimates. The reason why this is critical is 1) this is not a population estimate like $$\mu$$, so it cannot speak to certainty about the mean and 2) because of this fact, you need to account for uncertainty in the sampling statistic and most practically 3) you simply can't attain standard deviations without raw data.

As a direct example, we know that standard deviation can be calculated by using the formula:

$$s = \sqrt{\frac{\sum_{i=1}^n(x_i - \bar{x})^2}{n-1}}$$

The reason we need this formula is because we need the squared distances from the mean to approximate anything related to the standard deviation (visualized below, where the red line is the mean, and the points are the raw data deviations from that mean): Without having raw data, we have no way of knowing how far away data points are from the mean or how much they fluctuate around that mean, making an estimate of $$s$$ or SE impossible.

#### Practical Example

Some of this you may already know, but as a visual example using R, lets say we have a population of people who has taken an IQ test and highlight it's mean with a red line in this histogram.

#### Simulate Population Data ####
set.seed(123)
population <- rnorm(n = 1000000,
mean = 100,
sd = 15)

#### Plot Population Data ####
hist(population,
main = "Histogram of Population IQ",
xlab = "IQ Score",
col = "steelblue")

#### Draw Abline ####
abline(v=mean(population),
col="red",
lwd=4) What if we sampled from this population at random? We can do that within R by taking 10 samples of the population data here, each sample with $$n=50$$. We can then inspect their means and SD.

#### Take 10 Samples of N = 50 ####
df <- data.frame(
replicate(
n = 10,
sample(
population,
size = 50,
replace = T
)
)
)

#### Get By-Sample Mean/SD ####
library(tidyverse)
grouped.df <- df %>%
pivot_longer(cols = contains("X"),
names_to = "Sample",
values_to = "Value") %>%
group_by(Sample) %>%
mutate(Mean = mean(Value),
SD = sd(Value))

#### Inspect ####
grouped.df


Here you can already probably see an issue:

 A tibble: 500 × 4
# Groups:   Sample 
Sample Value  Mean    SD
<chr>  <dbl> <dbl> <dbl>
1 X1      97.4  95.6  12.4
2 X2      88.8  99.8  13.4
3 X3     118.  102.   14.2
4 X4     113.  102.   11.9
5 X5     104.   98.3  16.1
6 X6      87.0 105.   15.7
7 X7     123.   99.4  14.7
8 X8      93.2 102.   13.5
9 X9     100.  101.   15.6
10 X10     69.4  97.7  15.9
# ℹ 490 more rows
# ℹ Use print(n = ...) to see more rows


Earlier we specified that the population parameters were $$\mu = 100$$ and $$\sigma = 15$$. Here our sample statistic $$\bar{x}$$ ranges from about $$96$$ to $$102$$ and our sample SD ranges from about $$12$$ to $$16$$. We can visualize this to see how much fluctuation has occurred between samples.

grouped.df %>%
ggplot(aes(x=Value))+
geom_histogram(color = "black",
fill = "steelblue")+
labs(x="IQ Scores",
y="Count",
title = "Sample IQ Scores")+
theme_bw()+
facet_wrap(~Sample,
nrow = 5,
ncol = 2)+
geom_vline(aes(xintercept = Mean),
color = "orange",
linewidth = 1)+
geom_vline(aes(xintercept = 100),
color = "red",
linewidth = 1) The red line here indicates our original population mean and the orange line represents the sample mean of each group. You can see the orange line dance around the red line, which makes sample statistics on their own fairly unreliable. This is why we need the standard error in order to have any real approximation of an inferential test.

Now you probably already knew all of this, but it probably makes clear why having the data points matters. Without actually being able to estimate variation from each sample using the data itself, its impossible to get any meaningful estimates like standard error.

Can't comment on @Graipher's answer, so....

Given mean $$\bar{x}$$ and sample size $$n$$. The following variances can be calculated.

Distribution Parameters Mean $$\mu$$ Variance
Student's-t as posterior of $$\mu$$ of $$\frac{\bar{x} - \mu}{\sqrt{s^2/n}}$$ $$\nu > 0$$ $$0 \text{, for } {\nu>1}$$ $$\frac{n-1}{n-3}=\frac{\nu}{\nu-2} \text{, for } {\nu > 2} \because {n-1=\nu}$$
Beta as posterior of p of binomial $$\alpha > 0, \beta > 0$$ $${\frac{\alpha}{n}=\frac{\alpha}{\alpha + \beta}} \because {n={\alpha+\beta}}$$ $${\frac{\bar{x}(1-\bar{x})}{n+1}=\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}} \because {n=\alpha+\beta} \land {\bar{x}=\frac{\alpha}{n}=\frac{\alpha}{\alpha+\beta}}$$
Gamma as posterior of λ of poisson $$\alpha>0, \beta>0$$ $${\frac{\alpha}{n}=\frac{\alpha}{\beta}} \because {\beta=n}$$ $${\frac{\bar{x}}{n}=\alpha/\beta^2} \because {\bar{x}=\frac{\alpha}{n}=\frac{\alpha}{\beta}}$$

These assume very simple prior distributions, such as the "improper" Haldane prior Beta(0,0) for p of the binomial distribution. With the uniform Beta(1,1) prior, then the variance becomes:

$${\frac{\bar{x}(1-\bar{x})}{n+3}=\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}} \because {{n+2}={\alpha+\beta}} \land {\bar{x}=\frac{\alpha}{n+2}=\frac{\alpha}{\alpha+\beta}}$$.

Similar adjustments for the gamma distribution.