p-values for non-significant results#
Version 0.5 introduces a p_zmax attribute that stores the p-value associated
with the maximum test statistic value. This p-value is available regardless of
whether the null hypothesis is rejected. A non-significant result can therefore
be reported as “failed to reach significance (p = 0.116)”. However, note that
p-value accuracy decreases as the p-value increases, and that p-values greater
than 0.5 are generally inaccurate.
Refer to Reporting p-values for non-significant results for more details.
import numpy as np
from matplotlib import pyplot as plt
import spm1d
import jikudata as jd
dataset = jd.SimulatedPataky2015a() # 1D dataset: no significant effect
ti = spm1d.stats.ttest( dataset.y, 0 ).inference( 0.05, dirn=1 ) # one-tailed
print( f'h0reject = {ti.h0reject}, p_zmax = {ti.p_zmax:.3f}' )
h0reject = False, p_zmax = 0.116
The figure below depicts a non-significant result, where the p-value associated with the test statistic maximum is shown.
plt.rc( 'font', family='sans-serif' )
plt.rc( 'font', **{'sans-serif': ['Helvetica Neue', 'Helvetica', 'Arial', 'Liberation Sans', 'DejaVu Sans']} )
fig = plt.figure( figsize=(8, 6) )
ax = fig.add_axes( [0.02, 0.08, 0.96, 0.90] )
ax.plot( ti.z, 'k', lw=3 )
ax.axhline( 0, color='0.6', ls=':' )
ax.axhline( ti.zc, color='r', ls='--', lw=2 )
q = int( np.argmax( ti.z ) )
ax.plot( q, ti.z[q], 'o', ms=16, color='#2eb0ce' )
ax.annotate( f'p = {ti.p_zmax:.3f}', xy=(q + 1.2, ti.z[q] + 0.07), xytext=(0.50, 0.74), textcoords='axes fraction',
fontsize=34, fontweight='bold', color='#2eb0ce', ha='center', va='center',
arrowprops=dict( arrowstyle='-|>', connectionstyle='arc3,rad=0.3', color='#2eb0ce', lw=2.5 ) )
ax.set_ylim( ti.z.min() - 0.2, 1.2 * ti.zc )
ax.set_yticks( [] )
ax.tick_params( labelsize=14 )
for side in ('left', 'right', 'top'):
ax.spines[side].set_visible( False )

