How to use the linearmodels.utility.missing_warning function in linearmodels

To help you get started, we’ve selected a few linearmodels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bashtage / linearmodels / linearmodels / system / model.py View on Github external
def _drop_missing(self):
        k = len(self._dependent)
        nobs = self._dependent[0].shape[0]
        self._original_index = self._dependent[0].rows.copy()
        missing = np.zeros(nobs, dtype=np.bool)

        values = [self._dependent, self._exog, self._endog, self._instr, self._weights]
        for i in range(k):
            for value in values:
                nulls = value[i].isnull
                if nulls.any():
                    missing |= nulls

        missing_warning(missing)
        if np.any(missing):
            for i in range(k):
                self._dependent[i].drop(missing)
                self._exog[i].drop(missing)
                self._endog[i].drop(missing)
                self._instr[i].drop(missing)
                self._weights[i].drop(missing)
github bashtage / linearmodels / linearmodels / panel / model.py View on Github external
y = self._y = self.dependent.values2d
        x = self._x = self.exog.values2d
        w = self._w = self.weights.values2d
        if y.shape[0] != x.shape[0]:
            raise ValueError('dependent and exog must have the same number of '
                             'observations.')
        if y.shape[0] != w.shape[0]:
            raise ValueError('weights must have the same number of '
                             'observations as dependent.')

        all_missing = np.any(np.isnan(y), axis=1) & np.all(np.isnan(x), axis=1)
        missing = (np.any(np.isnan(y), axis=1) |
                   np.any(np.isnan(x), axis=1) |
                   np.any(np.isnan(w), axis=1))

        missing_warning(all_missing ^ missing)
        if np.any(missing):
            self.dependent.drop(missing)
            self.exog.drop(missing)
            self.weights.drop(missing)

            x = self.exog.values2d
            self._not_null = ~missing

        w = self.weights.dataframe
        if np.any(np.asarray(w) <= 0):
            raise ValueError('weights must be strictly positive.')
        w = w / w.mean()
        self.weights = PanelData(w)
        rank_of_x = self._check_exog_rank()
        self._constant, self._constant_index = has_constant(x, rank_of_x)
github bashtage / linearmodels / linearmodels / asset_pricing / model.py View on Github external
def _drop_missing(self):
        data = (self.portfolios, self.factors)
        missing = np.any(np.c_[[dh.isnull for dh in data]], 0)
        if any(missing):
            if all(missing):
                raise ValueError('All observations contain missing data. '
                                 'Model cannot be estimated.')
            self.portfolios.drop(missing)
            self.factors.drop(missing)
        missing_warning(missing)

        return missing
github bashtage / linearmodels / linearmodels / iv / model.py View on Github external
def _drop_missing(self) -> ndarray:
        data = (self.dependent, self.exog, self.endog, self.instruments, self.weights)
        missing = any(c_[[dh.isnull for dh in data]], 0)  # type: ndarray
        if any(missing):
            if npall(missing):
                raise ValueError('All observations contain missing data. '
                                 'Model cannot be estimated.')
            self.dependent.drop(missing)
            self.exog.drop(missing)
            self.endog.drop(missing)
            self.instruments.drop(missing)
            self.weights.drop(missing)

        missing_warning(missing)
        return missing
github bashtage / linearmodels / linearmodels / iv / absorbing.py View on Github external
def _drop_missing(self) -> ndarray:
        missing = to_numpy(self.dependent.isnull)
        missing |= to_numpy(self.exog.isnull)
        missing |= to_numpy(self._absorb_inter.cat.isnull().any(1))
        missing |= to_numpy(self._absorb_inter.cont.isnull().any(1))
        for interact in self._interaction_list:
            missing |= to_numpy(interact.isnull)
        if npany(missing):
            self.dependent.drop(missing)
            self.exog.drop(missing)
            self._absorb_inter.drop(missing)
            for interact in self._interaction_list:
                interact.drop(missing)
        missing_warning(missing)
        return missing