I want to know how I can calculate the Z-scores for groups with different sizes?

Let me try to explain: We have a city with 100.000 inhabitans. The city is divided in 10 neighborhoods, all with different size, say 1 neighborhood has 5000 inh., and another has 15.000 inh. etc. All the inhabitans can score a Yes or No as value => we translate this to 1 or 0

So we have a mean for the city as a whole (say 26% of the city scores a yes) and whe have scores per neighborhood (neighborhood 1 = 15%, neighborhood 2 = 31% etc)

Now I want to calculate at the Z-scores for each neighborhood referenced to the city mean (26%), how do I calculate this and how about the proportions of the neighborhoods and how do I calculate the standard deviation (I need SD for Z-scores)

  • 1
    $\begingroup$ What would be the purpose of computing these Z-scores? What do you hope they will tell you? $\endgroup$
    – whuber
    Commented May 24, 2019 at 14:06
  • $\begingroup$ I want to see how much all the neighborhoods are different from the mean in Z-scores, standardized $\endgroup$
    – MacMax
    Commented May 24, 2019 at 19:58
  • 2
    $\begingroup$ Comparing Z-scores lacks any scientific meaning--it's not an objective in its own right. It sounds like you want to compare the mean values among neighborhoods. The standard method, which is easy and should work well, is ANOVA. $\endgroup$
    – whuber
    Commented May 24, 2019 at 20:28

4 Answers 4



This is not really intended as an Answer, because your purpose is unclear. Maybe the comparison below will help you focus on your answer to the question in @whuber's Comment.

Suppose the city has population 100,000, with 26% Yes's; that's $X = 2600$ Yes's.

Suppose neighborhood A has population 5000 with 15% Yes's; that's $Y = 750$ Yes's.

It would make sense to compare neighborhood A with the rest of the city, which has population 95,000 and $26,000-750 = 25,250$ Yes's.

That can be done with a 'test of two proportions'. Minitab output follows, where Sample 1 is from neighborhood A (15% Yes's) and Sample 2 is for the rest of the city (26.58% Yes's).

Test and CI for Two Proportions 

Sample      X      N  Sample p
1         750   5000  0.150000
2       25250  95000  0.265789

Difference = p (1) - p (2)
Estimate for difference:  -0.115789
95% CI for difference:  (-0.126078, -0.105501)
Test for difference = 0 (vs ≠ 0):  
    Z = -22.06  P-Value = 0.000

It is usually bad practice to compare part of a population with the population as a whole: that way some individuals are double-counted. That is why I compared neighborhood A with the rest of the city.

With numbers as large as these, even some 'fairly small' differences in percentages will turn out to be significant (as happened in this example). That is, the null hypothesis that the two percentages are equal, will be rejected at the 5% level (P-value less than 5%).

You might also want to compare two different neighborhoods using such a test. Not all comparisons will be significant: If neighborhood B has population 10,000 with 16% Yes's, that's not significantly different from neighborhood A.

 Test and CI for Two Proportions 

Sample     X      N  Sample p
1        750   5000  0.150000     # Nbd A
2       1600  10000  0.160000     # Nbd B

Difference = p (1) - p (2)
Estimate for difference:  -0.01
95% CI for difference:  (-0.0222306, 0.00223055)
Test for difference = 0 (vs ≠ 0):  
    Z = -1.60  P-Value = 0.109

Another idea: Maybe you want to make a list of neighborhoods and their observed percentages of Yes answers, along with a confidence interval showing what the true percentages might be.

For neighborhood A, a 95% confidence interval would be $$ .15 \pm 1.96\sqrt{\frac{(.15)(1-.15)}{5000}},$$ That amounts to a percentage of $15 \pm 0.1.$

For neighborhood B, its a percentage of $16 \pm 0.07.$


In a comment you say you want to see if "the neighborhoods are different in z scores" but if you want to see if the neighborhoods are different, z scores are not the way to go. In his answer, BruceET made a few good suggestions. I have one more: You can do logistic regression with "neighborhood" as an independent variable and whatever it is you are working with as a dependent variable. This lets you compare all the neighborhoods at the same time.


The problem with comparing the mean of each neighbourhood with the overall mean is that the observations won't be independent.

With this I mean that, for a comparison between neighbourhood A and the overall mean, the results from neighbourhood A are influencing the overall mean (which is not supposed to happen when doing population comparison). For that reason, as pointed out by @whuber and @BruceET, an ANOVA test is preferred.

The idea behind ANOVA is to fit a very simple type of regression model where the variables are "belonging to neighbourhood A", "belonging to neighbourhood B" and so on... Then check how much of an effect those artificial variables have


I think I understand the motivation of the original question because I find myself in a similar situation.

In my case I want to come up with a map visualisation that helps interpreting the data. Z-scores would give a measure on whether each neighbourhood is above or below the mean and how many standard-deviations above/below.

While this may lack scientific value (as pointed out by @whuber in the comments) it can help with the interpretation of the data. For example we could use z-scores to create a choropleth map. Coloring a map using the z-scores would allow the viewer to quickly identify which neighbourhoods are above/below the mean and how far away from it. I am not sure if it is scientific but I think it's still valuable (but please do let me know if you think this is wrong :)

However, as @MacMax was pointing out in their question, each neighbourhood would have a different population, and this may raise some issues. To illustrate let me take to the extreme.

Imagine that for a neighbourhood only 1 person participated in the survey and they answered "Yes". This tiny neighbourhood would achieve the maximum possible z-score, but it would fail to account for the fact that we have very little information (because the sample size of that neighbourhood is tiny). It would be great if in our score we could account for the sample size of each neighbourhood. I believe @MacMax was trying to find a way to deal with this issue.

The solution that I found (but I am not sure how sound this is), is based on this formula I found on wikipedia: https://en.wikipedia.org/wiki/Standard_score#Standardizing_in_mathematical_statistics

enter image description here

Which is essentially the same as multiplying your z-score by the square root of n (where n is the sample size of each neighbourhood).

The caveat is that by doing so we have somewhat obscured the interpretability of the z-score value. We can still easily tell whether a neighbourhood is above (z-score > 0) or below (z-score < 0) the mean, but now is hard to tell how far away from the mean it is.


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.