Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. def simulate_under_null(num_chances_to_change):
  2. """Simulates some number changing several times, with an equal
  3. chance to increase or decrease. Returns the value of our
  4. test statistic for these simulated changes.
  5.  
  6. num_chances_to_change is the number of times the number changes.
  7. """
  8. uniform = Table().with_columns(
  9. "Change", make_array('Increase', 'Decrease'),
  10. "Chance", make_array(0.5, 0.5))
  11. test_statistic = uniform.sample_from_distribution('Chance', num_chances_to_change)
  12. return abs(test_statistic.column("Chance sample").item(0) - test_statistic.column("Chance sample").item(1))
  13.  
  14. uniform_samples = make_array()
  15. for i in np.arange(5000):
  16. uniform_samples = np.append(uniform_samples, simulate_under_null(num_changes))
  17.  
  18. Table().with_column('Test statistic under null', uniform_samples).hist(0, bins=np.arange(-100, 400+25, 25))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement