-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for difference between tt distributions
- Loading branch information
1 parent
7459305
commit eaa25d1
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# test whether travel times are drawn from the same distribution | ||
|
||
import requests | ||
|
||
backend = 'http://localhost:8072/aggregate-travel-times' | ||
|
||
# get data for the same corridor and month, one year apart | ||
tt1 = requests.get(f'{backend}/30345882/30357505/16/19/2022-04-01/2022-05-01/false/12345').json() | ||
tt2 = requests.get(f'{backend}/30345882/30357505/16/19/2023-04-01/2023-05-01/false/12345').json() | ||
# major complete-street rebuild took place between tt2 and tt3 | ||
tt3 = requests.get(f'{backend}/30345882/30357505/16/19/2024-04-01/2024-05-01/false/12345').json() | ||
|
||
tt1_obs = [ tt['seconds'] for tt in tt1['results']['observations'] ] | ||
tt2_obs = [ tt['seconds'] for tt in tt2['results']['observations'] ] | ||
tt3_obs = [ tt['seconds'] for tt in tt3['results']['observations'] ] | ||
|
||
import scipy.stats as stats | ||
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ranksums.html | ||
# aka | ||
# https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test | ||
statistic1, pvalue1 = stats.ranksums(tt1_obs, tt2_obs,'two-sided') | ||
statistic2, pvalue2 = stats.ranksums(tt2_obs, tt3_obs,'two-sided') | ||
|
||
sig_level = 0.05 | ||
|
||
print(f'P = {pvalue1}', 'not different' if pvalue1 > sig_level else 'different') | ||
print(f'P = {pvalue2}', 'not different' if pvalue2 > sig_level else 'different') |