nstat.FitResult
- class nstat.FitResult(neuralSpikeTrain, *args, **kwargs)[source]
Bases:
objectGLM fit results for one neuron across one or more model configs (Matlab
FitResult).Stores coefficients, deviance, AIC/BIC, log-likelihood, fitted λ signal, and KS-test diagnostics for each configuration in a
ConfigCollection. Provides coefficient accessors, residual analysis, and Matlab-compatible plot methods.- Parameters:
neuralSpikeTrain (nspikeTrain or sequence of nspikeTrain) – The observed spike train(s) that were fitted.
*args – Positional / keyword construction matching the Matlab
FitResult(nst, covLabels, numHist, …)signature, or the simplifiedFitResult(nst, lambdaCov, fits)form.**kwargs – Positional / keyword construction matching the Matlab
FitResult(nst, covLabels, numHist, …)signature, or the simplifiedFitResult(nst, lambdaCov, fits)form.
See also
FitSummaryAggregate summary across multiple neurons.
Analysis.RunAnalysisForAllNeuronsMain entry point that produces
FitResultobjects.
- __init__(neuralSpikeTrain, *args, **kwargs)[source]
Construct a per-neuron GLM fit result (Matlab
FitResult).Supports two construction patterns:
Simplified Python form
FitResult(nst, lambda_signal, fits)wherelambda_signalis aCovariateandfitsis a sequence of internal_SingleFitrecords.MATLAB-faithful form matching the
FitResult(nst, covLabels, numHist, histObjects, ensHistObj, lambda_signal, b, dev, stats, AIC, BIC, logLL, configColl, XvalData, XvalTime, distribution)signature.
- Parameters:
neuralSpikeTrain (nspikeTrain or sequence of nspikeTrain) – The observed spike train(s) that were fitted. When a sequence is provided, the result represents a pooled / multi-trial fit (Matlab parity).
*args –
Positional / keyword arguments dispatched to either
_init_simplified()or_init_matlab_style()based on whetherargs[0]is aCovariate.Notable keyword fields:
covLabels(list of list of str) — per-config covariate labels in the design matrix.b(list of array_like) — per-config coefficient vectors.dev,AIC,BIC,logLL(array_like) — goodness-of-fit scalars (one entry per config).stats(list of dict) — per-config diagnostic dicts.lambda_signal(Covariate) — fitted intensity in spikes/s.configColl(ConfigCollection) — the configuration collection used to drive the fits.distribution(str) —"poisson"(default) or"binomial".
**kwargs –
Positional / keyword arguments dispatched to either
_init_simplified()or_init_matlab_style()based on whetherargs[0]is aCovariate.Notable keyword fields:
covLabels(list of list of str) — per-config covariate labels in the design matrix.b(list of array_like) — per-config coefficient vectors.dev,AIC,BIC,logLL(array_like) — goodness-of-fit scalars (one entry per config).stats(list of dict) — per-config diagnostic dicts.lambda_signal(Covariate) — fitted intensity in spikes/s.configColl(ConfigCollection) — the configuration collection used to drive the fits.distribution(str) —"poisson"(default) or"binomial".
- Return type:
None
See also
FitSummaryAggregate summary across multiple neurons.
Analysis.RunAnalysisForAllNeuronsMain entry point that produces
FitResultobjects.
- property lambdaSignal: Covariate
MATLAB-style alias for
lambda_signal.
- property lambda_obj: Covariate
- property lambda_model: Covariate
- property lambda_result: Covariate
- property lambdaObj: Covariate
- property lambdaCov: Covariate
- property lambda_sig: Covariate
- setNeuronName(name)[source]
Rename the neuron on the underlying spike train(s).
- Parameters:
name (str)
- getSubsetFitResult(subfits)[source]
Return a new
FitResultwith only the selected fit indices (0-based).- Return type:
- addParamsToFit(neuronNum, lambda_signal, b, dev, stats, AIC, BIC, logLL, configColl)[source]
Append a new fit configuration’s results (Matlab
addParamsToFit).
- computeValLambda()[source]
Compute the conditional intensity on validation data (Matlab
computeValLambda).
- getPlotParams()[source]
Alias for
computePlotParams().
- getHistCoeffsWithLabels(fit_num=0)[source]
Return
(histMat, labels, SEMat)— Matlab multi-output form.Matlab:
[histMat, labels, SEMat] = getHistCoeffs(fitObj, fitNum)
- computeKSStats(fit_num=0, *, dt_correction=1)[source]
Return KS statistic, p-value, and within-CI flag for fit_num.
- computeInvGausTrans(fit_num=0)[source]
Return Gaussianized (inverse-normal-transformed) rescaled ISIs.
- computeFitResidual(fit_num=0, *, windowSize=None)[source]
Compute the martingale residual M(t) = N(t) − Λ(t) (Matlab
computeFitResidual).
- evalLambda(fit_num=0, newData=None)[source]
Evaluate λ(t) = exp(X·β) · sampleRate on newData (Matlab
evalLambda).
- computePlotParams(fit_num=None)[source]
Compute the aligned coefficient / SE / significance arrays for plotting.
- Parameters:
fit_num (int | None)
- getCoeffIndex(fit_num=0, sortByEpoch=0)[source]
Return
(indices, epochIds, numEpochs)for non-history coefficients.
- plotCoeffsWithoutHistory(fit_num=0, sortByEpoch=0, plotSignificance=1, handle=None)[source]
Plot non-history (stimulus/baseline) coefficients only.
- getHistIndex(fit_num=0, sortByEpoch=0)[source]
Return
(indices, epochIds, numEpochs)for history coefficients.
- getCoeffs(fit_num=0)[source]
Return
(coeffMat, labels, SEMat)for fit_num (0-based).Matches MATLAB:
[coeffMat, labels, SEMat] = getCoeffs(fitObj, fitNum).
- getHistCoeffs(fit_num=0)[source]
Return
(histMat, labels, SEMat)for fit_num (0-based).Matches MATLAB:
[histMat, labels, SEMat] = getHistCoeffs(fitObj, fitNum).
- plotHistCoeffs(fit_num=0, sortByEpoch=0, plotSignificance=1, handle=None)[source]
Plot history-filter coefficients (Matlab
plotHistCoeffs).
- plotCoeffs(fit_num=None, handle=None, plotSignificance=1)[source]
Plot GLM coefficients with error bars and significance markers.
Matches Matlab FitResult.plotCoeffs: when fit_num is
None(default) all fits are overlaid with per-fit colours, errorbar plots with ±1 SE, and asterisks (*) above significant coefficients (p < 0.05). Includes a legend matching Matlab’s lambda dataLabels.
- plotResults(fit_num=0, handle=None)[source]
Matlab-matching 2x4 subplot layout with 5 diagnostic panels.
- Layout (matching Matlab
subplot(2,4,...)): [1,2] KSPlot (double-wide) [3] InvGausTrans [4] SeqCorr [5,6] plotCoeffs (double-wide) [7,8] plotResidual (double-wide)
- Parameters:
fit_num (int)
- Layout (matching Matlab
- KSPlot(fit_num=None, handle=None)[source]
KS goodness-of-fit plot with 95 % confidence bands (Matlab
KSPlot).- Parameters:
fit_num (int, list of int, or None) – Which model(s) to plot.
None(default) plots all models (1:numResults), matching the MATLAB default behaviour. A single int plots one model; a list plots the specified subset.handle (matplotlib Axes, optional) – Axes to draw on. A new figure is created when None.
- plotSeqCorr(fit_num=None, handle=None)[source]
Plot U_j vs U_{j+1} scatter with correlation coefficient and p-value.
Matlab: plotSeqCorr plots the sequential correlation scatter of U_j (uniform-transformed rescaled ISIs) to detect serial dependence. When multiple models are present, each is plotted with a different colour and a legend entry showing
label, ρ=X.XX (p=Y.YY).
- plotInvGausTrans(fit_num=None, handle=None)[source]
Plot ACF of gaussianized rescaled ISIs with 95% CIs.
Matlab: plotInvGausTrans computes X_j = Φ⁻¹(U_j) and plots the autocorrelation function of X_j with 95% confidence bounds. Supports multi-fit overlay with per-fit colours matching KS/SeqCorr.
- plotResidual(fit_num=None, handle=None)[source]
Plot the martingale residual M(t) for one or more fits.
Matches Matlab
plotResidual: plots all residuals with per-fit colours and a legend usinglambda.dataLabels.
- setKSStats(Z, U, xAxis, KSSorted, ks_stat)[source]
Store pre-computed KS-test arrays (Matlab
setKSStats).
- setInvGausStats(X, rhoSig, confBoundSig)[source]
Store pre-computed inverse-Gaussian transform statistics.
- getParam(paramNames, fit_num=0)[source]
Return
(coeffs, SE, significance)for named parameters.- Parameters:
fit_num (int)