def sur_joinrho(n_eq, bigK, bSUR, varb): """Test on joint significance of spatial autoregressive coefficient in SUR Parameters ---------- n_eq : integer, number of equations bigK : n_eq x 1 array with number of variables by equation (includes constant term, exogenous and endogeneous and spatial lag) bSUR : dictionary with regression coefficients by equation, with the spatial autoregressive term as last varb : variance-covariance matrix for regression coefficients Returns ------- : tuple with test statistic, degrees of freedom, p-value """ bb = sur_dict2mat(bSUR) R = np.zeros((n_eq, varb.shape[0])) q = np.zeros((n_eq, 1)) kc = -1 for i in range(n_eq): kc = kc + bigK[i] R[i, kc] = 1 w, p = wald_test(bb, R, q, varb) return (w, n_eq, p)
def sur_setp(bigB, varb): ''' Utility to compute standard error, t and p-value Parameters ---------- bigB : dictionary of regression coefficient estimates, one vector by equation varb : variance-covariance matrix of coefficients Returns ------- surinfdict : dictionary with standard error, t-value, and p-value array, one for each equation ''' vvb = varb.diagonal() n_eq = len(bigB.keys()) bigK = np.zeros((n_eq, 1), dtype=np.int_) for r in range(n_eq): bigK[r] = bigB[r].shape[0] b = sur_dict2mat(bigB) se = np.sqrt(vvb) se.resize(len(se), 1) t = np.divide(b, se) tp = stats.norm.sf(abs(t)) * 2 surinf = np.hstack((se, t, tp)) surinfdict = sur_mat2dict(surinf, bigK) return surinfdict
def sur_chow(n_eq, bigK, bSUR, varb): """test on constancy of regression coefficients across equations in a SUR specification Note: requires a previous check on constancy of number of coefficients across equations; no other checks are carried out, so it is possible that the results are meaningless if the variables are not listed in the same order in each equation. Parameters ---------- n_eq : integer, number of equations bigK : array with the number of variables by equation (includes constant) bSUR : dictionary with the SUR regression coefficients by equation varb : array with the variance-covariance matrix for the SUR regression coefficients Returns ------- test : a list with for each coefficient (in order) a tuple with the value of the test statistic, the degrees of freedom, and the p-value """ kr = bigK[0][0] test = [] bb = sur_dict2mat(bSUR) kf = 0 nr = n_eq df = n_eq - 1 for i in range(kr): Ri = buildR1var(i, kr, kf, 0, nr) tt, p = wald_test(bb, Ri, np.zeros((df, 1)), varb) test.append((tt, df, p)) return test
def sur_joinrho(n_eq,bigK,bSUR,varb): """Test on joint significance of spatial autoregressive coefficient in SUR Parameters ---------- n_eq : integer, number of equations bigK : n_eq x 1 array with number of variables by equation (includes constant term, exogenous and endogeneous and spatial lag) bSUR : dictionary with regression coefficients by equation, with the spatial autoregressive term as last varb : variance-covariance matrix for regression coefficients Returns ------- : tuple with test statistic, degrees of freedom, p-value """ bb = sur_dict2mat(bSUR) R = np.zeros((n_eq,varb.shape[0])) q = np.zeros((n_eq,1)) kc = -1 for i in range(n_eq): kc = kc + bigK[i] R[i,kc] = 1 w,p = wald_test(bb,R,q,varb) return (w,n_eq,p)
def sur_setp(bigB,varb): ''' Utility to compute standard error, t and p-value Parameters ---------- bigB : dictionary of regression coefficient estimates, one vector by equation varb : variance-covariance matrix of coefficients Returns ------- surinfdict : dictionary with standard error, t-value, and p-value array, one for each equation ''' vvb = varb.diagonal() n_eq = len(bigB.keys()) bigK = np.zeros((n_eq,1),dtype=np.int_) for r in range(n_eq): bigK[r] = bigB[r].shape[0] b = sur_dict2mat(bigB) se = np.sqrt(vvb) se.resize(len(se),1) t = np.divide(b,se) tp = stats.norm.sf(abs(t))*2 surinf = np.hstack((se,t,tp)) surinfdict = sur_mat2dict(surinf,bigK) return surinfdict
def sur_chow(n_eq,bigK,bSUR,varb): """test on constancy of regression coefficients across equations in a SUR specification Note: requires a previous check on constancy of number of coefficients across equations; no other checks are carried out, so it is possible that the results are meaningless if the variables are not listed in the same order in each equation. Parameters ---------- n_eq : integer, number of equations bigK : array with the number of variables by equation (includes constant) bSUR : dictionary with the SUR regression coefficients by equation varb : array with the variance-covariance matrix for the SUR regression coefficients Returns ------- test : a list with for each coefficient (in order) a tuple with the value of the test statistic, the degrees of freedom, and the p-value """ kr = bigK[0][0] test = [] bb = sur_dict2mat(bSUR) kf = 0 nr = n_eq df = n_eq - 1 for i in range(kr): Ri = buildR1var(i,kr,kf,0,nr) tt,p = wald_test(bb,Ri,np.zeros((df,1)),varb) test.append((tt,df,p)) return test