code: def test_small_sample_serial_correlation_test():
      # Test the Ljung Box serial correlation test for small samples with df
      # adjustment using the Nile dataset. Ljung-Box statistic and p-value
      # are compared to R's Arima() and checkresiduals() functions in forecast
      # package:
      # library(forecast)
      # fit <- Arima(y, order=c(1,0,1), include.constant=FALSE)
      # checkresiduals(fit, lag=10)
      from statsmodels.tsa.statespace.sarimax import SARIMAX
  
      niledata = nile.data.load_pandas().data
      niledata.index = pd.date_range(
          "1871-01-01", "1970-01-01", freq="YS"
      )
      mod = SARIMAX(
          endog=niledata["volume"],
          order=(1, 0, 1),
          trend="n",
          freq=niledata.index.freq,
      )
      res = mod.fit()
  
      actual = res.test_serial_correlation(
          method="ljungbox", lags=10, df_adjust=True
      )[0, :, -1]
      assert_allclose(actual, [14.116, 0.0788], atol=1e-3)
  
imports: from statsmodels.compat.pandas import MONTH_END
  import os
  import re
  import warnings
  import numpy
  from numpy.testing import assert_, assert_allclose, assert_almost_equal, assert_equal, assert_raises
  import pandas
  import pytest
  from statsmodels.datasets import nile
  from statsmodels.tsa.statespace import kalman_filter, kalman_smoother, sarimax, varmax
  from statsmodels.tsa.statespace.mlemodel import MLEModel, MLEResultsWrapper
  from statsmodels.tsa.statespace.tests.results import results_sarimax, results_var_misc
label_desc: Use image node_id 23 for calling a global function with example usage: test_small_sample_serial_correlation_test() without return types