def initialize(self): """ Preprocesses the data for MNLogit. Turns the endogenous variable into an array of dummies and assigns J and K. """ super(MNLogit, self).initialize() #This is also a "whiten" method as used in other models (eg regression) wendog, self.names = tools.categorical(self.endog, drop=True, dictnames=True) self.wendog = wendog # don't drop first category self.J = float(wendog.shape[1]) self.K = float(self.exog.shape[1]) self.df_model *= (self.J-1) # for each J - 1 equation. self.df_resid = self.exog.shape[0] - self.df_model - (self.J-1)
def initialize(self): """ Preprocesses the data for MNLogit. Turns the endogenous variable into an array of dummies and assigns J and K. """ super(MNLogit, self).initialize() #This is also a "whiten" method as used in other models (eg regression) wendog, self.names = tools.categorical(self.endog, drop=True, dictnames=True) self.wendog = wendog # don't drop first category self.J = float(wendog.shape[1]) self.K = float(self.exog.shape[1]) self.df_model *= (self.J - 1) # for each J - 1 equation. self.df_resid = self.exog.shape[0] - self.df_model - (self.J - 1)
def test_recarray1d(self): instr = self.structdes['str_instr'].view(np.recarray) dum = tools.categorical(instr) test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names[-5:]])) assert_array_equal(test_dum, self.dummy) assert_equal(len(dum.dtype.names), 6)
def test_array1d_drop(self): des = tools.categorical(self.string_var, drop=True) assert_array_equal(des, self.dummy) assert_equal(des.shape[1],5)
def test_recarray2d(self): des = tools.categorical(self.recdes, col='str_instr') # better way to do this? test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]])) assert_array_equal(test_des, self.dummy) assert_equal(len(des.dtype.names), 9)
def test_recarray1d_drop(self): instr = self.structdes['instrument'].view(np.recarray) dum = tools.categorical(instr, drop=True) test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names])) assert_array_equal(test_dum, self.dummy) assert_equal(len(dum.dtype.names), 5)
def test_structarray1d(self): instr = self.structdes['instrument'].view(dtype=[('var1', 'f4')]) dum = tools.categorical(instr) test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names[-5:]])) assert_array_equal(test_dum, self.dummy) assert_equal(len(dum.dtype.names), 6)
def test_structarray1d_drop(self): instr = self.structdes['str_instr'].view(dtype=[('var1', 'a10')]) dum = tools.categorical(instr, drop=True) test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names])) assert_array_equal(test_dum, self.dummy) assert_equal(len(dum.dtype.names), 5)
def test_array1d_drop(self): des = tools.categorical(self.string_var, drop=True) assert_array_equal(des, self.dummy) assert_equal(des.shape[1], 5)
def test_array2d(self): des = np.column_stack((self.des, self.instr, self.des)) des = tools.categorical(des, col=2) assert_array_equal(des[:, -5:], self.dummy) assert_equal(des.shape[1], 10)
def test_array1d(self): des = tools.categorical(self.instr) assert_array_equal(des[:, -5:], self.dummy) assert_equal(des.shape[1], 6)
def test_structarray2d_drop(self): des = tools.categorical(self.structdes, col='str_instr', drop=True) test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]])) assert_array_equal(test_des, self.dummy) assert_equal(len(des.dtype.names), 8)
def test_structarray2dint(self): des = tools.categorical(self.structdes, col=3) test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]])) assert_array_equal(test_des, self.dummy) assert_equal(len(des.dtype.names), 9)
def test_array2d_drop(self): des = np.column_stack((self.des, self.instr, self.des)) des = tools.categorical(des, col=2, drop=True) assert_array_equal(des[:,-5:], self.dummy) assert_equal(des.shape[1],9)
def test_array1d(self): des = tools.categorical(self.instr) assert_array_equal(des[:,-5:], self.dummy) assert_equal(des.shape[1],6)