residual¶
MATLAB equivalent:
sidResidual
residual ¶
Model residual analysis and diagnostic tests.
residual ¶
residual(model: object, y: ndarray, u: ndarray | None = None, *, max_lag: int | None = None, plot: bool = False) -> ResidualResult
Compute model residuals and perform diagnostic tests.
This is the Python port of sidResidual.m.
Computes residuals from an estimated model and performs whiteness (autocorrelation) and independence (cross-correlation) tests to assess model quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
object
|
Result from any |
required |
y
|
ndarray, shape ``(N, ny)`` or ``(N+1, p, L)``
|
Measured output data. For state-space models the array contains
state trajectories |
required |
u
|
ndarray or None
|
Input data, shape |
None
|
max_lag
|
int or None
|
Maximum lag for correlation tests.
Default: |
None
|
plot
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ResidualResult
|
Frozen dataclass with attributes:
|
Raises:
| Type | Description |
|---|---|
SidError
|
If the model type cannot be determined (code: |
Examples:
Notes
Specification: (Model residual analysis -- not yet in SPEC.md)
The whiteness test checks that the normalised autocorrelation
|r_ee(tau)| < 2.58 / sqrt(N) for tau = 1, ..., max_lag.
The independence test checks the same bound for the normalised
cross-correlation between residuals and inputs at all lags in
[-max_lag, max_lag]. Both tests use a 99% confidence level.
See Also
sid.compare : Model output comparison. sid._internal.cov.sid_cov : Biased cross-covariance estimator.
Changelog
2026-04-09 : First version (Python port) by Pedro Lourenco.