#!/usr/bin/env python # coding: utf-8 # In[1]: # to go from 10% to 90% of the population # is a log difference of 4.5 import numpy as np import pandas as pd logdiff990 = np.log(9/.1) logdiff990 # In[2]: # at a 1% survival advantage per generation with 100% # assortative mating and a 25-year generation takes... time990_1percent = logdiff990/.01 * 25 time990_1percent # In[10]: Reproductive_Advantage = [.0005, .001, .002, .005, .01, .02, .05, .10, .20] Time_990 = [] for i in range(9): Time_990 = Time_990 + [25 * logdiff990/Reproductive_Advantage[i]] Scratch = (Reproductive_Advantage, Time_990) Rep_Adv_array = np.array(Scratch) # In[11]: Scratch = pd.DataFrame(Rep_Adv_array) Rep_Adv_df = Scratch.transpose() Rep_Adv_df.columns=['Reproductive Advantage', 'Time to Go from 9 to 90 Percent'] Rep_Adv_df # In[13]: # Suppose we start out with a 7.4-fold difference—exp(2), that is, # between population X and Y... # for how long a duration of time will the frequency for X be greater # than 50% and the frequency for Y be less than 50%? # # the answer, where r is the generational reproductive advantage # and g is the length of a generation, is: g * ln(2)/r Reproductive_Advantage = [.0005, .001, .002, .005, .01, .02, .05, .10, .20] Duration = [] for i in range(9): Duration = Duration + [25 * np.log(2)/Reproductive_Advantage[i]] Scratch = (Reproductive_Advantage, Duration) Duration_array = np.array(Scratch) Scratch = pd.DataFrame(Duration_array) Duration_df = Scratch.transpose() Duration_df.columns=['Reproductive Advantage', 'Duration'] Duration_df # In[15]: # Time to grow from 1% to 50% Reproductive_Advantage = [.0005, .001, .002, .005, .01, .02, .05, .10, .20] Time_to_Grow_from_1_Percent = [] for i in range(9): Time_to_Grow_from_1_Percent = Time_to_Grow_from_1_Percent + [25 * np.log(50)/Reproductive_Advantage[i]] Scratch = (Reproductive_Advantage, Time_to_Grow_from_1_Percent) Time_to_Grow_from_1_Percent_array = np.array(Scratch) Scratch = pd.DataFrame(Time_to_Grow_from_1_Percent_array) Time_to_Grow_from_1_Percent_df = Scratch.transpose() Time_to_Grow_from_1_Percent_df.columns=['Reproductive Advantage', 'Time to Grow from 1 Percent'] Time_to_Grow_from_1_Percent_df