Skip to content

BUG: KalmanFilter.loglike() disagrees with loglikeobs().sum() and result.llf under exact diffuse initialization with concentrated scale #10741

Description

@Swapnil-J20

Describe the bug

When combining exact diffuse initialization (model.initialize_diffuse()) with concentrated scale (model.filter_concentrated = True), KalmanFilter.loglike() computes a different likelihood from model.loglikeobs().sum(), result.llf, and an unconcentrated model evaluated at the fitted scale (model.fixed_scale(...)).

In a minimal 2-observation, 1-state model:

  • model.loglike()returns-4.906342`
  • model.loglikeobs().sum()returns-4.004213`
  • result.llfreturns-4.004213`
  • model.fixed_scale(...)returns-4.004213`

This discrepancy (~0.902 log-likelihood units) arises because KalmanFilter.loglike() in kalman_filter.py:

  1. Omits finite innovations occurring during diffuse periods from the quadratic log-likelihood penalty.
  2. Subtracts kfilter.nobs_kendog_diffuse_nonsingular from the finite innovation count instead of adding it.
  3. Does not account for loglikelihood_burn when burn ends inside the diffuse initialization period.

Code Sample, a copy-pastable example

import numpy as np
from statsmodels.tsa.statespace.kalman_smoother import KalmanSmoother

model = KalmanSmoother(2, 1)
model.bind(np.asfortranarray([[1.0, 0.0], [0.0, 1.0]]))
model["design"] = [[1.0], [0.5]]
model["obs_cov"] = np.diag([1.0, 1.5])
model["transition"] = [[0.75]]
model["selection"] = [[1.0]]
model["state_cov"] = [[0.25]]
model.initialize_diffuse()
model.filter_concentrated = True

result = model.smooth()
with model.fixed_scale(result.scale):
    explicit_scale_loglike = model.loglike()

print(f"model.loglike():          {model.loglike():.6f}")
print(f"model.loglikeobs().sum(): {model.loglikeobs().sum():.6f}")
print(f"result.llf:               {result.llf:.6f}")
print(f"explicit scale loglike:   {explicit_scale_loglike:.6f}")

Expected Output

model.loglike(): -4.004213
model.loglikeobs().sum(): -4.004213
result.llf: -4.004213
explicit scale loglike: -4.004213

Actual Output

model.loglike():          -4.906342
model.loglikeobs().sum(): -4.004213
result.llf:               -4.004213
explicit scale loglike:   -4.004213

Versions

INSTALLED VERSIONS
------------------
Python: 3.14.2.final.0
OS: Windows 11 10.0.26300 AMD64
statsmodels: 0.15.0 (and main @ 88aec26)
numpy: 2.4.4
scipy: 1.18.1
pandas: 3.0.6

Checklist

  • I have searched the issue tracker for a similar issue and did not find one.

  • I have confirmed this bug exists on the latest released version of statsmodels, or on the main branch.

Activity

  1. added a commit that references this issue on Nov 13, 2026
    f7a7ed4
  2. added a commit that references this issue on Nov 15, 2026
    64a46f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions