Esempio n. 1
0
 def scale(self, lv: str, mv: str, z_by_lv: np.ndarray,
           weights) -> pd.DataFrame:
     z_by_lv = weights.get_Z_for_mode_b(lv, mv, z_by_lv)
     to_quantify = np.array([weights.mv_grouped_by_lv(lv, mv), z_by_lv])
     quantified = util.groupby_mean(to_quantify)
     x_quantified = weights.dummies(mv).dot(quantified[1, :])
     return util.treat_numpy(x_quantified) * weights.correction()
Esempio n. 2
0
 def outer_weights_nonmetric(self, mv_grouped_by_lv: list, mv_grouped_by_lv_missing: list, Z: pd.DataFrame, lv: str,
                             correction: float) -> Tuple[np.ndarray, np.ndarray]:
     if lv in mv_grouped_by_lv_missing:
         raise Exception("Missing nonmetric data is not supported in mode B. LV with missing data: " + lv)
     weights, _, _, _ = linalg.lstsq(mv_grouped_by_lv[lv], Z)
     Y = np.dot(mv_grouped_by_lv[lv], weights)
     Y = util.treat_numpy(Y) * correction
     return weights, Y
Esempio n. 3
0
 def outer_weights_nonmetric(self, mv_grouped_by_lv: list, mv_grouped_by_lv_missing: list, Z: np.ndarray, lv: str,
                             correction: float) -> Tuple[np.ndarray, np.ndarray]:
     if lv in mv_grouped_by_lv_missing:
         weights = np.nansum(mv_grouped_by_lv[lv] * Z[:, np.newaxis], axis=0)
         weights = weights / np.sum(np.power(mv_grouped_by_lv_missing[lv] * Z[:, np.newaxis], 2), axis=0)
         Y = np.nansum(np.transpose(mv_grouped_by_lv[lv]) * weights[:, np.newaxis], axis=0)
         Y = Y / np.sum(np.power(np.transpose(mv_grouped_by_lv_missing[lv]) * weights[:, np.newaxis], 2), axis=0)
     else:   
         weights = np.dot(np.transpose(mv_grouped_by_lv[lv]), Z) / np.power(Z, 2).sum()
         Y = np.dot(mv_grouped_by_lv[lv], weights)
     Y = util.treat_numpy(Y) * correction
     return weights, Y
Esempio n. 4
0
 def scale(self, lv: str, mv: str, z_by_lv: np.ndarray,
           weights) -> pd.DataFrame:
     z_by_lv = weights.get_Z_for_mode_b(lv, mv, z_by_lv)
     to_quantify = np.array([weights.mv_grouped_by_lv(lv, mv), z_by_lv])
     quantified = util.groupby_mean(to_quantify)
     x_quant_incr, var_incr = self._ordinalize(quantified[1, :],
                                               weights.dummies(mv).copy(),
                                               z_by_lv, 1)
     x_quant_decr, var_decr = self._ordinalize(quantified[1, :],
                                               weights.dummies(mv).copy(),
                                               z_by_lv, -1)
     x_quantified = -x_quant_decr if var_incr < var_decr else x_quant_incr
     scaled = util.treat_numpy(x_quantified) * weights.correction()
     return scaled
Esempio n. 5
0
 def scale(self, lv: str, mv: str, z_by_lv: pd.Series,
           weights) -> pd.DataFrame:
     data = weights.mv_grouped_by_lv(lv, mv)
     finite_elements = np.isfinite(data).sum()
     return util.treat_numpy(data) * np.sqrt(finite_elements /
                                             (finite_elements - 1))