Example #1
0
 def test_weibull_aft_plot_partial_effects_on_outcome_with_multiple_columns(self, block):
     df = load_rossi()
     aft = WeibullAFTFitter()
     aft.fit(df, "week", "arrest")
     aft.plot_partial_effects_on_outcome(["age", "prio"], [[10, 0], [50, 10], [80, 50]])
     self.plt.tight_layout()
     self.plt.title("test_weibull_aft_plot_partial_effects_on_outcome_with_multiple_columns")
     self.plt.show(block=block)
Example #2
0
 def test_weibull_aft_plot_partial_effects_on_outcome(self, block):
     df = load_rossi()
     aft = WeibullAFTFitter()
     aft.fit(df, "week", "arrest")
     aft.plot_partial_effects_on_outcome("age", [10, 50, 80])
     self.plt.tight_layout()
     self.plt.title("test_weibull_aft_plot_partial_effects_on_outcome")
     self.plt.show(block=block)
Example #3
0
 def test_aft_plot_partial_effects_on_outcome_with_categorical(self, block):
     df = load_rossi()
     df["cat"] = np.random.choice(["a", "b", "c"], size=df.shape[0])
     aft = WeibullAFTFitter()
     aft.fit(df, "week", "arrest", formula="cat + age + fin")
     aft.plot_partial_effects_on_outcome("cat", values=["a", "b", "c"])
     self.plt.title("test_aft_plot_partial_effects_on_outcome_with_categorical")
     self.plt.show(block=block)
def home_vary_survival(df, DURATION, EVENT, option):
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 7))
    #plt.ylim(0, 1.01)
    #plt.xlim(0, 60)
    times = np.arange(0, 120)
    if option == "Baseline":
        kmf = KaplanMeierFitter().fit(df[DURATION], df[EVENT])
        kmf.survival_function_.plot(ax=ax)
    else:
        min_value = min(df[option].values)
        max_value = max(df[option].values) + 1
        interval = math.ceil((max_value - min_value) / 4)
        value_range = range(min_value, max_value, interval)
        wft = WeibullAFTFitter().fit(df,
                                     DURATION,
                                     EVENT,
                                     ancillary=True,
                                     timeline=times)
        wft.plot_partial_effects_on_outcome(option,
                                            value_range,
                                            cmap='coolwarm',
                                            ax=ax)
    st.pyplot(plt)
        duration_col="mainline_vol",
        event_col="failure",
        formula=
        "ramp_metering+length_of_acceleration_lane+ffs_cap_df+number_of_mainline_lane_downstream+simple_merge",
    )

    aft.print_summary()
    aft.plot()
    aft.median_survival_time_
    aft.mean_survival_time_

    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(5, 4))
    aft.plot_partial_effects_on_outcome(
        "ramp_metering",
        [0, 1],
        cmap="coolwarm",
        ax=ax,
        plot_baseline=False,
        times=range(1000, 3200, 50),
    )

    fig2, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(5, 4))
    aft.plot_partial_effects_on_outcome(
        "length_of_acceleration_lane",
        [500, 1000, 1500],
        plot_baseline=False,
        cmap="coolwarm",
        ax=ax1,
        times=range(1000, 3200, 50),
    )

    fig2, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(5, 4))