if regressors is not None:
// the .intersection preserves order, important!
self.regressors = {name: list(df.columns.intersection(cols)) for name, cols in regressors.items()}
else:
self.regressors = {name: df.columns.tolist() for name in self._fitted_parameter_names}
assert all(
len(cols) > 0 for cols in self.regressors.values()
), "All parameters must have at least one column associated with it. Did you mean to include a constant column?"
df = self._filter_dataframe_to_covariates(df).astype(float)
self._check_values_pre_fitting(df, utils.coalesce(Ts[1], Ts[0]), E, weights, entries)
_index = pd.MultiIndex.from_tuples(
sum(([(name, col) for col in columns] for name, columns in self.regressors.items()), [])
)
self._norm_mean = df.mean(0)
if (
self._KNOWN_MODEL
and hasattr(self, "_ancillary_parameter_name")
and hasattr(self, "_primary_parameter_name")
):
// Known AFT model
self._norm_mean_ = df[self.regressors[self._primary_parameter_name]].mean(0)
self._norm_mean_ancillary = df[self.regressors[self._ancillary_parameter_name]].mean(0)
_norm_std = df.std(0)
self._constant_cols = pd.Series(
[(_norm_std.loc[variable_name] < 1e-8) for (_, variable_name) in _index], index=_index
)
self._norm_std = pd.Series([_norm_std.loc[variable_name] for (_, variable_name) in _index], index=_index)
self._norm_std[self._constant_cols] = 1.0
_norm_std[_norm_std < 1e-8] = 1.0
After Change
if regressors is not None:
// the .intersection preserves order, important!
self.regressors = {name: list(df.columns.intersection(cols)) for name, cols in sorted(regressors.items())}
else:
self.regressors = {name: df.columns.tolist() for name in sorted(self._fitted_parameter_names)}
assert all(
len(cols) > 0 for cols in self.regressors.values()
), "All parameters must have at least one column associated with it. Did you mean to include a constant column?"
df = self._filter_dataframe_to_covariates(df).astype(float)
self._check_values_pre_fitting(df, utils.coalesce(Ts[1], Ts[0]), E, weights, entries)
_index = pd.MultiIndex.from_tuples(
sum(([(name, col) for col in columns] for name, columns in self.regressors.items()), [])
)
self._norm_mean = df.mean(0)
if (
self._KNOWN_MODEL
and hasattr(self, "_ancillary_parameter_name")
and hasattr(self, "_primary_parameter_name")
):
// Known AFT model
self._norm_mean_ = df[self.regressors[self._primary_parameter_name]].mean(0)
self._norm_mean_ancillary = df[self.regressors[self._ancillary_parameter_name]].mean(0)
_norm_std = df.std(0)
self._constant_cols = pd.Series(
[(_norm_std.loc[variable_name] < 1e-8) for (_, variable_name) in _index], index=_index
)
self._norm_std = pd.Series([_norm_std.loc[variable_name] for (_, variable_name) in _index], index=_index)
self._norm_std[self._constant_cols] = 1.0
_norm_std[_norm_std < 1e-8] = 1.0