Confidence intervals

Confidence intervals#

spm1d calculates confidence intervals with three procedures: ci_onesample, ci_pairedsample and ci_twosample.

For 0D data these yield usual parametric confidence intervals. For 1D data they yield random field theory-corrected intervals.


0D example#

The example below calculates a one-sample confidence interval for the first group of the sleep dataset from R (ten values).

import spm1d
import jikudata as jd

dataset = jd.R_Sleep2Test()
y       = dataset.y[ dataset.x == 0 ]  # (10,) array
ci      = spm1d.stats.ci_onesample( y, 0.05 )
print( ci )
0D Confidence Interval (95.0%)
   kind          :  One sample
   datum         :  mean  (0.75000)
   Probability
      alpha      :  0.050
      df         :  (1, 9)
      zc         :  2.26216
   Confidence interval
      hc         :  1.27978
      ci         :  (-0.52978, 2.02978)

The interval contains zero, implying that the corresponding one-sample t test does not reject the null hypothesis of zero mean:

ti = spm1d.stats.ttest( y ).inference( 0.05, dirn=0 )
print( ti.p )
0.21759778006844926

1D example#

The example below calculates a paired-sample confidence interval for the plantar arch angle data from First analyses. The interval is centered on the mean difference between the two conditions.

import numpy as np
import spm1d
import jikudata as jd

dataset = jd.PlantarArchAngle()
y, A    = dataset.y, dataset.x  # (20,101) array and (20,) array
yA, yB  = y[ A == 0 ], y[ A == 1 ]
ci      = spm1d.stats.ci_pairedsample( yA, yB, 0.05 )
print( ci )
1D Confidence Interval (95.0%)
   kind          :  Paired difference
   datum         :  mean  [(1x101) field]
   Probability
      alpha      :  0.050
      df         :  (1, 9)
      fwhm       :  23.81887
      resels     :  (1, 4.198)
      zc         :  3.82866
   Confidence interval
      hc         :  (1x101) field
      ci         :  (2x101) field

The figure below shows the interval together with the (invalid) uncorrected pointwise interval (left panel) and the paired t test result (right panel). The RFT interval excludes zero only at the end of the domain, where the t statistic exceeds the RFT critical threshold.

Paired-sample confidence interval with the pointwise interval, and the paired t statistic with its critical threshold Paired-sample confidence interval with the pointwise interval, and the paired t statistic with its critical threshold

Figure 1: The 95% confidence interval for the mean difference (left, band) with the pointwise 95% interval (dashed lines) and the paired t test result (right).


Interval types#

The interval type depends on datum and mu choices:

  • ci_onesample always returns an interval about the mean.

  • ci_pairedsample and ci_twosample with datum='difference' (default) return an interval about the mean difference.

  • ci_pairedsample and ci_twosample with datum='meanA' return the interval ciA about the mean of group A. With mu='meanB' (default) the interval asks whether the mean of group B lies inside ciA. With mu='tailB' both intervals are half-height.

The example below demonstrates non-overlapping, half-height intervals about two group means.

dataset = jd.R_PlantGrowthTest()
y, A    = dataset.y, dataset.x  # (30,) arrays of responses and group labels
yA, yB  = y[ A == 1 ], y[ A == 2 ]
ci      = spm1d.stats.ci_twosample( yA, yB, datum='meanA', mu='tailB' )
print( ci )
0D Confidence Interval (95.0%)
   kind          :  Two sample
   datum         :  meanA  (4.66100)
   criterion     :  tailB  (5.22413)
   Probability
      alpha      :  0.050
      df         :  (1, 18)
      zc         :  2.10092
   Confidence interval
      hc         :  0.60373
      ciA        :  (4.35913, 4.96287)
      ciB        :  (5.22413, 5.82787)
      h0reject   :  True (tailB outside ciA)