The ecological fallacy is a widely recognized error in the interpretation of statistical data in an ecological study, whereby inferences about the nature of individuals are based solely upon aggregate statistics collected for the group to which those individuals belong. A statistic (singular is the result of applying a function (statistical Algorithm) to a set of data. An ecological study is an Epidemiological study in which the unit of analysis is a population rather than an individual This fallacy assumes that all members of a group exhibit characteristics of the group at large. A fallacy is a component of an Argument which being demonstrably flawed in its Logic or form renders the argument invalid in whole Stereotypes are one form of ecological fallacy. In statistical terminology the equivalent term used is biased sampling and is avoided by using methods such as stratified sampling. In Statistics, stratified sampling is a method of sampling from a population
Example 1. A study is done that shows people from Springfield score higher on the SATs, on average, than people from Shelbyville. The SAT Reasoning Test (formerly Scholastic Aptitude Test and Scholastic Assessment Test) is a standardized test for College admissions in the Making an assumption that a randomly selected individual from Springfield would have scored higher on the SATs than a randomly selected individual from Shelbyville would be an ecological fallacy. Since the SAT scores given in the study were an average, it is indeed possible that the individual from Springfield scored in the bottom ten percent on the SATs and the individual from Shelbyville just happened to score in the top ten percent.
Example 2. Imagine two communities, Chiptown and Pittsville. Within each community there is a divide between the rich and poor, the rich living in gated communities on the hills and the poor living adjacent to the industrial districts that pump carcinogens into their backyards. In both communities, the poor people have a cancer incidence that is many times that of the wealthy people. In Chiptown, where the dominant industry is high-tech computer manufacturing, the overall salaries are higher for both rich and poor people, but the carcinogens spewed into the environment are particularly nasty, giving cancer to nearly all those exposed (almost entirely poor people). Prof. Newbie comes along and decides to examine the risk factors for cancer. A risk factor is a variable associated with an increased risk of Disease or Infection. He looks up the cancer rates and median incomes of these two towns on the CDC and U. S. Census webpages. He finds, to everyone's surprise, that the cancer incidence is higher in the wealthier community, Chiptown. He concludes that higher income is a risk factor for cancer. In fact, we know that exactly the opposite is true: In the wealthier community of Chiptown, being poor is especially dangerous to one's health.
The ecological fallacy was a factor in the judge's decision to uphold the election of Christine Gregoire in the court challenge to the Washington gubernatorial election, 2004. Christine O'Grady "Chris" Gregoire (born March 24, 1947) is the Democratic Governor of the state of Washington The election for governor of the US state of Washington on November 2 2004 gained national attention for its legal twists turns and extremely close finish The challengers had attempted to argue that illegal votes cast in the election would have followed the voting patterns of the precincts in which they had been cast, which they contended would have favored Gregoire. The judge determined that this constituted an ecological fallacy, and disallowed the evidence. An expert witness for Gregoire explained the ecological fallacy as trying to figure out Ichiro Suzuki's batting average by looking at the batting average of the entire Seattle Mariners team. 
The ecological fallacy is exceptionally common in population research.
Hasty generalization is the opposite of the ecological fallacy. Hasty generalization is a Logical fallacy of Faulty generalization by reaching an inductive Generalization based on insufficient Evidence It occurs when one makes a generalization about a group based on insufficient data. For example, if one made a generalization about an entire group based only on a few members of that group, then one would be making a hasty generalization.
The term comes from a 1950 paper by William S. Robinson. William Robinson, or Will Robinson or Bill Robinson or other nicknames may refer to Persons Historical William Benjamin  For each of the 48 states in the US as of the 1930 census, he computed the literacy rate and the proportion of the population born outside the US. The United States Census is a decennial Census mandated by the United States Constitution. He showed that these two figures were associated with a positive correlation of 0. 53 — in other words, the greater the proportion of immigrants in a state, the higher its average literacy. However, when individuals are considered, the correlation was −0. 11 — immigrants were on average less literate than native citizens. Robinson showed that the positive correlation at the level of state populations was because immigrants tended to settle in states where the native population was more literate. He cautioned against deducing conclusions about individuals on the basis of population-level, or "ecological" data.