diff --git a/pyproject.toml b/pyproject.toml index 51175d22..6eb96143 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,8 +8,7 @@ dependencies = [ "plotly<6.0.0,>=5.13.1", "pandas>=2.2.3", "polarstate==0.1.8", - "smoothstate>=0.1.0", - "statsmodels>=0.14.0", + "smoothstate>=0.1.1", "polars>=1.31.0", "reactable>=0.1.5", "great-tables>=0.18.0", diff --git a/src/rtichoke/calibration/calibration.py b/src/rtichoke/calibration/calibration.py index e031ba3e..05954caf 100644 --- a/src/rtichoke/calibration/calibration.py +++ b/src/rtichoke/calibration/calibration.py @@ -11,6 +11,7 @@ import polars as pl import numpy as np from polarstate import predict_aj_estimates, prepare_event_table +from smoothstate import smooth_state_lowess from ._secondary_cox import calculate_secondary_cox_smooth # from rtichoke.helpers.send_post_request_to_r_rtichoke import send_requests_to_rtichoke_r @@ -757,8 +758,6 @@ def _calculate_smooth_curve( """ Calculate the smoothed calibration curve using lowess. """ - from statsmodels.nonparametric.smoothers_lowess import lowess - smooth_frames = [] # Helper function to process a single probability and real array @@ -772,12 +771,9 @@ def process_single_array(p, r, group_name): } ) else: - # lowess returns a 2D array where the first column is x and the second is y - smoothed = lowess(r, p, it=0) - xout = np.linspace(0, 1, 101) - yout = np.clip(np.interp(xout, smoothed[:, 0], smoothed[:, 1]), 0.0, 1.0) - return pl.DataFrame( - {"x": xout, "y": yout, "reference_group": [group_name] * len(xout)} + smoothed = smooth_state_lowess(p, r) + return smoothed.with_columns( + pl.lit(group_name).alias("reference_group") ) if isinstance(reals, dict):