def var_loglike(resid, omega, nobs): r""" Returns the value of the VAR(p) log-likelihood. Parameters ---------- resid : ndarray (T x K) omega : ndarray Sigma hat matrix. Each element i,j is the average product of the OLS residual for variable i and the OLS residual for variable j or np.dot(resid.T,resid)/nobs. There should be no correction for the degrees of freedom. nobs : int Returns ------- llf : float The value of the loglikelihood function for a VAR(p) model Notes ----- The loglikelihood function for the VAR(p) is .. math:: -\left(\frac{T}{2}\right) \left(\ln\left|\Omega\right|-K\ln\left(2\pi\right)-K\right) """ logdet = util.get_logdet(np.asarray(omega)) neqs = len(omega) part1 = - (nobs * neqs / 2) * np.log(2 * np.pi) part2 = - (nobs / 2) * (logdet + neqs) return part1 + part2
def info_criteria(self): "information criteria for lagorder selection" nobs = self.nobs neqs = self.neqs lag_order = self.k_ar free_params = lag_order * neqs ** 2 + neqs * self.k_trend ld = util.get_logdet(self.sigma_u_mle) # See Lutkepohl pp. 146-150 aic = ld + (2.0 / nobs) * free_params bic = ld + (np.log(nobs) / nobs) * free_params hqic = ld + (2.0 * np.log(np.log(nobs)) / nobs) * free_params fpe = ((nobs + self.df_model) / self.df_resid) ** neqs * np.exp(ld) return {"aic": aic, "bic": bic, "hqic": hqic, "fpe": fpe}
def info_criteria(self): "information criteria for lagorder selection" nobs = self.nobs neqs = self.neqs lag_order = self.k_ar free_params = lag_order * neqs ** 2 + neqs * self.k_trend ld = util.get_logdet(self.sigma_u_mle) # See Lutkepohl pp. 146-150 aic = ld + (2. / nobs) * free_params bic = ld + (np.log(nobs) / nobs) * free_params hqic = ld + (2. * np.log(np.log(nobs)) / nobs) * free_params fpe = ((nobs + self.df_model) / self.df_resid) ** neqs * np.exp(ld) return { 'aic' : aic, 'bic' : bic, 'hqic' : hqic, 'fpe' : fpe }