For scipy.stats.ttest_ind I thought that setting the permutations parameter to any positive number would result in a permutation test being performed. I also thought that if a permutation test was being performed, no assumptions would be made regarding variance of the two populations, therefore the equal_var parameter should be ignored.
I found that the equal_var parameter does change the resulting p-value and test statistic when the permutation test is being used. A simple reproducible example is shown below:
sample1 = [34, 1200, 23, 50, 60, 50, 0, 0, 30, 89, 0, 300, 400, 20, 10, 0]
sample2 = [20, 10, 5, 0, 30, 50, 0, 100, 110, 0, 40, 10, 3, 0]
# equal_var = True
t1, p1 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000)
t2, p2 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000)
t3, p3 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000)
# equal_var = False
t4, p4 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000, equal_var=False)
t5, p5 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000, equal_var=False)
t6, p6 = stats.ttest_ind(a=sample1, b=sample2, permutations=10_000_000, equal_var=False)
The output of running the code above (test statistics and p-values) is:
3 of 3 times the permutation test with equal_var = True returns a p-value of around 0.15, while 3 of 3 times the same permutation test with equal_var = False returns a p-value of around 0.10.
Can anyone please help me understand what is happening here, and why the equal_var parameter is changing the results of the permutation test?
It was my understanding that the permutation test just randomly assigns each data to one of the two groups (because under the null we can do this) and calculates the difference in means. Then repeats the process permutations times. Then at the end calculates a p-value by dividing the number of permutations where the difference in means was as or more extreme than the sample we actually took by the total number of permutations used. Based on this, I am having a hard time understanding why the equal_var parameter would change the p-value as we see in the example above.
Thank you!
