Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
event_observed=None,
timeline=None,
label=None,
alpha=None,
ci_labels=None,
show_progress=False,
entry=None,
weights=None,
initial_point=None,
) -> "ParametricUnivariateFitter":
label = utils.coalesce(label, self._class_name.replace("Fitter", "") + "_estimate")
n = len(utils.coalesce(*Ts))
if event_observed is not None:
utils.check_nans_or_infs(event_observed)
self.event_observed = np.asarray(event_observed, dtype=int) if event_observed is not None else np.ones(n)
self.entry = np.asarray(entry) if entry is not None else np.zeros(n)
self.weights = np.asarray(weights) if weights is not None else np.ones(n)
if timeline is not None:
self.timeline = np.sort(np.asarray(timeline).astype(float))
else:
self.timeline = np.linspace(utils.coalesce(*Ts).min(), utils.coalesce(*Ts).max(), n)
self._label = utils.coalesce(label, self._label)
self._ci_labels = ci_labels
self.alpha = utils.coalesce(alpha, self.alpha)
# create some initial values, and test them in the hazard.
def _check_values(X, T, E):
pass_for_numeric_dtypes_or_raise(X)
check_nans_or_infs(T)
check_nans_or_infs(E)
check_nans_or_infs(X)
check_low_var(X)
check_complete_separation(X, E, T)
def _check_values_pre_fitting(self, df, T, E, weights, entries):
utils.check_for_numeric_dtypes_or_raise(df)
utils.check_nans_or_infs(df)
utils.check_nans_or_infs(T)
utils.check_nans_or_infs(E)
utils.check_positivity(T)
if self.weights_col:
if (weights.astype(int) != weights).any() and not self.robust:
warnings.warn(
dedent(
"""It appears your weights are not integers, possibly propensity or sampling scores then?
It's important to know that the naive variance estimates of the coefficients are biased. Instead a) set `robust=True` in the call to `fit`, or b) use Monte Carlo to
estimate the variances. See paper "Variance estimation when using inverse probability of treatment weighting (IPTW) with survival analysis"""
),
utils.StatisticalWarning,
)
if (weights <= 0).any():
raise ValueError("values in weight column %s must be positive." % self.weights_col)
def _check_values(self, array):
check_nans_or_infs(array)
def _check_values_pre_fitting(self, X, T, E, W):
check_low_var(X)
check_for_numeric_dtypes_or_raise(X)
check_nans_or_infs(T)
check_nans_or_infs(X)
# check to make sure their weights are okay
if self.weights_col:
if (W.astype(int) != W).any() and not self.robust:
warnings.warn(
"""It appears your weights are not integers, possibly propensity or sampling scores then?
It's important to know that the naive variance estimates of the coefficients are biased. Instead a) set `robust=True` in the call to `fit`, or b) use Monte Carlo to
estimate the variances. See paper "Variance estimation when using inverse probability of treatment weighting (IPTW) with survival analysis"
""",
StatisticalWarning,
)
if (W <= 0).any():
raise ValueError("values in weight column %s must be positive." % self.weights_col)
if (self.event_col is not None)
else pd.Series(np.ones(self._n_examples, dtype=bool), index=df.index, name="E")
)
weights = (
utils.pass_for_numeric_dtypes_or_raise_array(df.pop(self.weights_col)).astype(float)
if (self.weights_col is not None)
else pd.Series(np.ones(self._n_examples, dtype=float), index=df.index, name="weights")
)
entries = (
utils.pass_for_numeric_dtypes_or_raise_array(df.pop(entry_col)).astype(float)
if (entry_col is not None)
else pd.Series(np.zeros(self._n_examples, dtype=float), index=df.index, name="entry")
)
utils.check_nans_or_infs(E)
E = E.astype(bool)
self.event_observed = E.copy()
self.entry = entries.copy()
self.weights = weights.copy()
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 = df.astype(float)
self._check_values_pre_fitting(df, utils.coalesce(Ts[1], Ts[0]), E, weights, entries)