The ecological fallacy is committed when improper claims about individual characteristics are made on the basis of data about collections of individuals. The error is fundamentally a statistical one, as statements that apply to groups do not necessarily apply to individual members of that group. A simple example would be the following: “A study showed that people who wear glasses have above-average intelligence. You wear glasses, so you must be intelligent.” This argument is fallacious because it is not possible to infer an individual’s characteristics on the basis of the fact that they are part of a group (spectacle wearers) which has particular characteristics. The individual in question may or may not share the characteristic – there is no way to tell by considering only information about the group as a whole.
This fallacy is often found in relation to interpretation and application of statistical data. It is common to claim that because a certain individual is a member of a particular group, and overall this group tends to have a certain trait, this person will also have that trait. Any such claim is fallacious unless it is made probabilistically (e.g. saying “it is more likely that they will have this trait” rather than “they will have this trait”), and even then one must exercise caution, since many biases hamper our ability to make probability judgements of this sort.
Ecological fallacy: overview from Changing Minds
Ecological fallacy: overview from Encyclopedia.com