This is a rather primitive and highly simplified simulation illustrating the cost/benefit dynamic that the most common sickle cell gene produces in a population exposed to malaria at differing rates. As long as a high exposure continues, the sickle cell allele will remain in the population at substantial numbers. If initially there are high numbers of the allele, but the malaria exposure level falls below a certain critical level, that allele will begin to disappear.
This is the result of the fact that the sickle cell allele is somewhat protective against severe malaria infection, and so is evolutionarily advantageous in the presence of malaria. The gene exacts its own cost, however. As many as 20% of individuals with two copies of the allele likely died under premodern conditions from sickle cell disease. So it is an evolutionary liability when not in the presence of malaria. This is one reason why sickle cell disease is much rarer in those of African descent in the U.S. relative those living in subsaharan Africa.
This simulation needs to be run a number of times to see the overall trends clearly. The random number generator used here with such a statically small population produces occasionally eccentric results. Also, the results are accumulating averages, so the graph of the first four generations or so tends to be jagged. Over a number of runs, though, the trends tend to be consistent. If you start with a low number of individuals with the sickle cell allele and a malaria exposure rate above 1% or so, the allele will increase in the population (this is more consistent with higher rates of malaria like 10%). If you start with a large number of sickle cell alleles in the population, and a malaria rate below 1% or so, the allele will decrease in the population. This is something that is presently happening in the U.S.
The population intitially only contains individuals homozygous for the normal blood cell gene
and those heterozygous individuals containing the normal gene along with the sickle cell gene.
A large portion of individuals that are born homozygous for the sickle cell gene are able to survive into their 20s and able to reproduce, and so add to the population of heterozygous individuals. The relative numbers of the sickle cell homozygous surviving in the population remains low, though, and for simplicity is not included in the representation.
The simulation's population size will be assumed to remain steady at 100, and the simulation will run for 20 generations.