'Test the whiteness of the residuals using the Portmanteau test.
This test is described in [1]_, chapter 8.4.1.
Parameters
nlags : int > 0
signif : float, 0 < `signif` < 1
adjusted : bool, default False
Returns
result : :class:`statsmodels.tsa.vector_ar.hypothesis_test_results.WhitenessTestResults`
References
.. [1] Lutkepohl, H. 2005. *New Introduction to Multiple Time Series Analysis*. Springer.'

def test_whiteness(self, nlags=10, signif=0.05, adjusted=False):

    statistic = 0
    u = np.asarray(self.resid)
    acov_list = _compute_acov(u, nlags)
    c0_inv = inv(self.sigma_u)
    if ((c0_inv.dtype == np.complex128) and np.all((np.imag(c0_inv) == 0))):
        c0_inv = np.real(c0_inv)
    for t in range(1, (nlags + 1)):
        ct = acov_list[t]
        to_add = np.trace(chain_dot(ct.T, c0_inv, ct, c0_inv))
        if adjusted:
            to_add /= (self.nobs - t)
        statistic += to_add
    statistic *= ((self.nobs ** 2) if adjusted else self.nobs)
    df = (((self.neqs ** 2) * ((nlags - self.k_ar) + 1)) - (self.neqs * self.coint_rank))
    dist = scipy.stats.chi2(df)
    pvalue = dist.sf(statistic)
    crit_value = dist.ppf((1 - signif))
    return WhitenessTestResults(statistic, crit_value, pvalue, df, signif, nlags, adjusted)
