nstat.FitSummary

class nstat.FitSummary(fit_results)[source]

Bases: object

Population-level summary across multiple neurons (Matlab FitResSummary).

Aggregates AIC, BIC, log-likelihood, KS statistics, and coefficients from a collection of FitResult objects, providing box-plots, coefficient histograms, and 2-D/3-D coefficient surfaces.

Parameters:

fit_results (FitResult or iterable of FitResult) – One or more per-neuron fit results to summarise.

See also

FitResult

Per-neuron fit container.

__init__(fit_results)[source]

Construct a population-level summary (Matlab FitResSummary).

Parameters:

fit_results (FitResult or iterable of FitResult) – One or more per-neuron FitResult objects to summarise. A single FitResult is wrapped in a list automatically.

Raises:

ValueError – If an empty iterable is passed.

Return type:

None

Notes

On construction the summary precomputes per-config means and standard deviations of AIC, BIC, log-likelihood, KS statistics, and the union of covariate labels across all neurons. Rows (neurons) with fewer configs than the maximum are NaN-padded so every metric matrix has shape (numNeurons, numResults).

See also

FitResult

Per-neuron fit container.

mapCovLabelsToUniqueLabels()[source]

Rebuild the union of covariate labels across all neurons.

getDiffAIC(idx=1)[source]

Return ΔAIC relative to config idx (0-based).

Parameters:

idx (int)

Return type:

ndarray

getDiffBIC(idx=1)[source]

Return ΔBIC relative to config idx (0-based).

Parameters:

idx (int)

Return type:

ndarray

getDifflogLL(idx=1)[source]

Return Δlog-likelihood relative to config idx (0-based).

Parameters:

idx (int)

Return type:

ndarray

binCoeffs(minVal=-12.0, maxVal=12.0, binSize=0.1)[source]

Histogram of regression coefficients per covariate.

Matches Matlab FitResSummary.binCoeffs: for each unique covariate, bins the significant coefficient values across all neurons/fits, normalizes to a PDF, and computes the fraction of times each covariate was significant.

Returns:

  • N ((nBins, nCovariates) per-covariate normalized histograms (PDFs))

  • edges ((nBins + 1,) bin edges)

  • percentSig ((nCovariates,) fraction of times each covariate was significant)

setCoeffRange(minVal, maxVal)[source]

Set the coefficient range used by binCoeffs.

getSigCoeffs(fitNum=0)[source]

Return (nNeurons × nCov) binary significance matrix.

Parameters:

fitNum (int)

plotIC(handle=None)[source]

Plot AIC, BIC, and log-likelihood box-plots side by side.

plotAllCoeffs(fitNum=None, plotSignificance=True, subIndex=None, handle=None)[source]

Errorbar plot of GLM coefficients across neurons (Matlab plotAllCoeffs).

Parameters:
plot3dCoeffSummary(handle=None)[source]

3D ribbon plot of binned coefficient distributions (Matlab plot3dCoeffSummary).

plot2dCoeffSummary(handle=None)[source]

Stacked line plot of binned coefficient distributions (Matlab plot2dCoeffSummary).

plotKSSummary(neurons=None, handle=None)[source]

Subplot grid of KS plots per neuron (Matlab plotKSSummary).

Parameters:

neurons (list[int] | None)

plotAIC(handle=None)[source]

Box-plot of AIC across neurons (Matlab plotAIC).

plotBIC(handle=None)[source]

Box-plot of BIC across neurons (Matlab plotBIC).

plotlogLL(handle=None)[source]

Box-plot of log-likelihood across neurons (Matlab plotlogLL).

plotResidualSummary(handle=None)[source]

Overlay all neurons’ martingale residuals (Matlab plotResidualSummary).

plotSummary(handle=None)[source]

Bar chart of mean AIC, BIC, and log-likelihood across configs.

boxPlot(X, diffIndex=1, h=None, dataLabels=None, **kwargs)[source]

General-purpose box-plot of X columns with fit-name labels.

Parameters:

diffIndex (int)

toStructure()[source]

Serialize to a JSON-compatible dict.

Return type:

dict[str, Any]

getCoeffIndex(fitNum=None)[source]

Return 0-based indices into uniqueCovLabels that are NOT history terms.

Parameters:

fitNum (int | list[int] | None)

Return type:

list[int]

plotCoeffsWithoutHistory(fitNum=None, plotSignificance=True, handle=None)[source]

Plot coefficients excluding history terms (Matlab plotCoeffsWithoutHistory).

Parameters:
getHistIndex(fitNum=None)[source]

Return 0-based indices into uniqueCovLabels that are history terms.

Parameters:

fitNum (int | list[int] | None)

Return type:

list[int]

getCoeffs(fitNum=0)[source]

Return (coeffMat, labels, seMat) aligned to unique labels.

Parameters:

fitNum (int)

getHistCoeffs(fitNum=0)[source]

Return (histMat, labels, seMat) for history coefficients.

Parameters:

fitNum (int)

plotHistCoeffs(fitNum=None, plotSignificance=True, handle=None)[source]

Plot only the history coefficients (Matlab plotHistCoeffs).

Parameters:
static fromStructure(structure)[source]

Reconstruct a FitSummary from a dict.

Parameters:

structure (dict[str, Any])

Return type:

FitSummary