Ecological fallacy

The ecological fallacy, sometimes referred to as the ecological inference fallacy, describes a fallacious inference made about a particular individual/group from aggregate statistical data in reference to whatever population that individual(or group) is part of. It's a fallacy very similar to the fallacy of composition/division or category mistake. It can also be said to apply in contexts where someone assumes that a statistical property for a population applies to subgroups of that population. It would be similar to making a mathematical error in assuming properties of an entire set also apply to subsets within the set, and/or particular elements within said set.

Form
The ecological fallacy can take several forms:

Alternatively:

Examples
This is a fallacy because the inference about an individual doesn't necessarily follow from the group generalization. In statistics, the average is the sum of all the scores in a given set divided by the number of scores. Sarah's true score does not need to reflect or even be close to the average in order for the population average to hold. So it doesn't necessarily follow that Sarah will be better at math than Jack. Similar reasoning applies to the two examples that follow.

Again doesn't necessarily follow.

In the hypothetical case that New York City had a high crime rate overall it doesn't rule out the possibility that Jane lives in a part of the city that experiences a much lower crime rate than the overall average for the city.

In each of these examples given the inference is logically invalid this makes the ecological fallacy a formal fallacy.