The following test for a difference between the centre of a sample of data and a given reference point. The one sample t-test assumes normally distributed data, whereas the Wilcoxon signed rank test can be used with any data.

## One sample t-test

```
import numpy as np
import scipy.stats as stats
# generate the data
normDist = stats.norm(loc=7.5, scale=3)
data = normDist.rvs(100)
# Define a value to check against
checkVal = 6.5
# T-test
# --- >>> START stats <<< --- t, tProb = stats.ttest_1samp(data, checkVal) # --- >>> STOP stats <<< ---
print ('P value:')
print (tProb)
OUT:
P value:
0.007269398564245046
```

## Wilcoxon signed rank test

Note the test value is subtracted from all data (test is then effectively against zero).

```
rank, pVal = stats.wilcoxon(data-checkVal)
print ('P value:')
print (pVal)
OUT:
P value:
0.006010251964988403
```

## One thought on “48. Statistics: One sample t-test and Wilcoxon signed rank test”