Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_format_p_values():
assert utils.format_p_value(2)(0.004) == "<0.005"
assert utils.format_p_value(3)(0.004) == "0.004"
assert utils.format_p_value(3)(0.000) == "<0.0005"
assert utils.format_p_value(3)(0.005) == "0.005"
assert utils.format_p_value(3)(0.2111) == "0.211"
assert utils.format_p_value(3)(0.2119) == "0.212"
def test_redundant_cv_columns_are_dropped(self, seed_df):
seed_df = seed_df[seed_df["id"] == 1]
cv = pd.DataFrame.from_records(
[
{"id": 1, "t": 0, "var3": 0, "var4": 1},
{"id": 1, "t": 1, "var3": 0, "var4": 1}, # redundant, as nothing changed during the interval
{"id": 1, "t": 3, "var3": 0, "var4": 1}, # redundant, as nothing changed during the interval
{"id": 1, "t": 6, "var3": 1, "var4": 1},
{"id": 1, "t": 9, "var3": 1, "var4": 1}, # redundant, as nothing changed during the interval
]
)
df = seed_df.pipe(utils.add_covariate_to_timeline, cv, "id", "t", "E")
assert df.shape[0] == 2
integer weights per observation
initial_point: (d,) numpy array, optional
initialize the starting point of the iterative
algorithm. Default is the zero vector.
Returns
-------
self
self with new properties like ``cumulative_hazard_``, ``survival_function_``
"""
self.upper_bound = np.atleast_1d(utils.pass_for_numeric_dtypes_or_raise_array(upper_bound))
self.lower_bound = np.atleast_1d(utils.pass_for_numeric_dtypes_or_raise_array(lower_bound))
utils.check_nans_or_infs(self.lower_bound)
utils.check_positivity(self.upper_bound)
if (self.upper_bound < self.lower_bound).any():
raise ValueError("All upper_bound times must be greater than or equal to lower_bound times.")
if event_observed is None:
event_observed = self.upper_bound == self.lower_bound
if ((self.lower_bound == self.upper_bound) != event_observed).any():
raise ValueError(
"For all rows, lower_bound == upper_bound if and only if event observed = 1 (uncensored). Likewise, lower_bound < upper_bound if and only if event observed = 0 (censored)"
)
return self._fit(
(np.clip(self.lower_bound, 1e-20, 1e25), np.clip(self.upper_bound, 1e-20, 1e25)),
event_observed=event_observed,
timeline=timeline,
def _create_Xs_dict(self, df):
return utils.DataframeSliceDict(df, self.regressors)
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)
if self.entry_col:
utils.check_entry_times(T, entries)