Skip to content

Instantly share code, notes, and snippets.

@liudong
Created September 27, 2021 12:31
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 liudong/2933622dba9018eb11cf1a5cc2110f7e to your computer and use it in GitHub Desktop.
Save liudong/2933622dba9018eb11cf1a5cc2110f7e to your computer and use it in GitHub Desktop.
Python: t-test
import numpy as np
from scipy import stats
differences = [B[i] - A[i] for i in range(len(A))]
# one sample t-test
stats.ttest_1samp(differences, popmean=0)
# assess the equality of variances
stats.levene(A, B)
# independent t-test
stats.ttest_ind(A, B, equal_var=True)
# t-test on TWO RELATED samples
stats.ttest_rel(A, B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment