Skip to content

Instantly share code, notes, and snippets.

@hauselin
Last active February 23, 2020 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauselin/fcb9e1b10fa2d4f3b3fd16d84739a8e7 to your computer and use it in GitHub Desktop.
Save hauselin/fcb9e1b10fa2d4f3b3fd16d84739a8e7 to your computer and use it in GitHub Desktop.
def simulate(simulations=1000, n=500, quantile=0.80):
correlations = np.zeros(simulations)
for i in range(simulations):
data = {"personality": np.random.randn(
n), "attract": np.random.randn(n)}
df = pd.DataFrame(data)
df['personality_attract'] = df['personality'] + df['attract']
cutoff = df['personality_attract'].quantile(quantile)
df['outcome'] = np.where(
df['personality_attract'] > cutoff, 'dated', 'rejected')
dated = df.query('outcome == "dated"')
correlations[i] = dated.corr()['personality'][1]
return correlations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment