nstat.ConfidenceInterval

class nstat.ConfidenceInterval(time, bounds, *args, color=None, value=0.95)[source]

Bases: object

Confidence interval for a time series or Covariate.

Stores a pair of (lower, upper) bound traces over a shared time axis, with plotting support for both line and shaded-patch styles.

Parameters:
  • time (array_like) – Time vector.

  • bounds (array_like, shape (n, 2)) – Lower and upper bounds at each time point.

  • *args – Positional metadata: (name, xlabelval, xunits, yunits, dataLabels, plotProps). If a single short string is passed it is interpreted as the colour (Matlab compatibility).

  • color (str or None) – Line / patch colour. Default 'b'.

  • value (float, default 0.95) – Confidence level (e.g. 0.95 for 95 %).

__init__(time, bounds, *args, color=None, value=0.95)[source]
Parameters:
Return type:

None

property lower: ndarray
property upper: ndarray
setColor(color)[source]

Set the plot colour.

Parameters:

color (str)

Return type:

None

setValue(value)[source]

Set the confidence level (e.g. 0.95 for 95 %).

Parameters:

value (float)

Return type:

None

dataToMatrix()[source]

Return the bounds as an (n, 2) numpy array.

Return type:

ndarray

dataToStructure()[source]

Serialise to a plain dictionary (matches Matlab dataToStructure).

Return type:

dict

getSigInTimeWindow(wMin, wMax, holdVals=0)[source]

Return a new ConfidenceInterval restricted to [wMin, wMax].

Parameters:
windowedSignal(windowTimes)[source]

Return a ConfidenceInterval restricted to the given time window.

shift(deltaT, updateLabels=False)[source]

Return a time-shifted copy.

Parameters:
resample(sample_rate)[source]

Resample the CI bounds to a new sample rate via linear interpolation.

Parameters:

sample_rate (float)

property derivative

Numerical derivative of both bounds.

merge(other, holdVals=0)[source]

Merge with another ConfidenceInterval along the time axis.

Parameters:

holdVals (int)

copySignal()[source]

Return a deep copy.

getSubSignal(identifier)[source]

Return a single column (lower=0 or upper=1) as a 1-column CI.

setMinTime(minTime=None, holdVals=0)[source]

Restrict to times >= minTime.

Parameters:

holdVals (int)

setMaxTime(maxTime=None, holdVals=0)[source]

Restrict to times <= maxTime.

Parameters:

holdVals (int)

toStructure()[source]

Alias for dataToStructure().

Return type:

dict

plot(color=None, alphaVal=0.2, drawPatches=0, ax=None)[source]

Plot the confidence interval.

Parameters:
  • color (str or None) – Override colour (default: self.color).

  • alphaVal (float, default 0.2) – Transparency for shaded patches.

  • drawPatches (int, default 0) – If 1, draw a shaded fill_between region instead of lines.

  • ax (Axes or None) – Matplotlib axes. If None, uses plt.gca().

Returns:

Plot handles.

Return type:

PolyCollection or list of Line2D

static fromStructure(structure)[source]

Reconstruct a ConfidenceInterval from a dictionary.

Parameters:

structure (dict)

Return type:

ConfidenceInterval