NelsonAalenFitter

class lifelines.fitters.nelson_aalen_fitter.NelsonAalenFitter(alpha=0.05, nelson_aalen_smoothing=True, **kwargs)

Bases: lifelines.fitters.UnivariateFitter

Class for fitting the Nelson-Aalen estimate for the cumulative hazard.

NelsonAalenFitter(alpha=0.05, nelson_aalen_smoothing=True)

Parameters:
  • alpha (float, optional (default=0.05)) – The alpha value associated with the confidence intervals.
  • nelson_aalen_smoothing (bool, optional) – If the event times are naturally discrete (like discrete years, minutes, etc.) then it is advisable to turn this parameter to False. See [1], pg.84.

Notes

[1] Aalen, O., Borgan, O., Gjessing, H., 2008. Survival and Event History Analysis

cumulative_hazard_

The estimated cumulative hazard (with custom timeline if provided)

Type:DataFrame
confidence_interval_

The lower and upper confidence intervals for the cumulative hazard

Type:DataFrame
durations

The durations provided

Type:array
event_observed

The event_observed variable provided

Type:array
timeline

The time line to use for plotting and indexing

Type:array
entry

The entry array provided, or None

Type:array or None
event_table

A summary of the life table

Type:DataFrame
conditional_time_to_event_

Return a DataFrame, with index equal to survival_function_, that estimates the median duration remaining until the death event, given survival up until time t. For example, if an individual exists until age 1, their expected life remaining given they lived to time 1 might be 9 years.

cumulative_density_at_times(times, label=None)
cumulative_hazard_at_times(times, label=None)
divide(other) → pandas.core.frame.DataFrame

Divide the {0} of two {1} objects.

Parameters:other (same object as self)
fit(durations, event_observed=None, timeline=None, entry=None, label=None, alpha=None, ci_labels=None, weights=None)
Parameters:
  • durations (an array, or pd.Series, of length n) – duration subject was observed for
  • timeline (iterable) – return the best estimate at the values in timelines (positively increasing)
  • event_observed (an array, or pd.Series, of length n) – True if the the death was observed, False if the event was lost (right-censored). Defaults all True if event_observed==None
  • entry (an array, or pd.Series, of length n) – relative time when a subject entered the study. This is useful for left-truncated observations, i.e the birth event was not observed. If None, defaults to all 0 (all birth events observed.)
  • label (string) – a string to name the column of the estimate.
  • alpha (float) – the alpha value in the confidence intervals. Overrides the initializing alpha for this call to fit only.
  • ci_labels (iterable) – add custom column names to the generated confidence intervals as a length-2 list: [<lower-bound name>, <upper-bound name>]. Default: <label>_lower_<1-alpha/2>
  • weights (n array, or pd.Series, of length n) – if providing a weighted dataset. For example, instead of providing every subject as a single element of durations and event_observed, one could weigh subject differently.
Returns:

Return type:

self, with new properties like cumulative_hazard_.

fit_right_censoring(*args, **kwargs)

Alias for fit

See also

fit()

hazard_at_times(times, label=None)
median_survival_time_

Return the unique time point, t, such that S(t) = 0.5. This is the “half-life” of the population, and a robust summary statistic for the population, if it exists.

percentile(p)

Return the unique time point, t, such that S(t) = p.

Parameters:p (float)
plot(**kwargs)

Plots a pretty figure of the model

Matplotlib plot arguments can be passed in inside the kwargs, plus

Parameters:
  • show_censors (bool) – place markers at censorship events. Default: False

  • censor_styles (dict) – If show_censors, this dictionary will be passed into the plot call.

  • ci_alpha (float) – the transparency level of the confidence interval. Default: 0.3

  • ci_force_lines (bool) – force the confidence intervals to be line plots (versus default shaded areas). Default: False

  • ci_show (bool) – show confidence intervals. Default: True

  • ci_legend (bool) – if ci_force_lines is True, this is a boolean flag to add the lines’ labels to the legend. Default: False

  • at_risk_counts (bool) – show group sizes at time points. See function add_at_risk_counts for details. Default: False

  • loc (slice) – specify a time-based subsection of the curves to plot, ex:

    >>> model.plot(loc=slice(0.,10.))
    

    will plot the time values between t=0. and t=10.

  • iloc (slice) – specify a location-based subsection of the curves to plot, ex:

    >>> model.plot(iloc=slice(0,10))
    

    will plot the first 10 time points.

Returns:

a pyplot axis object

Return type:

ax

plot_cumulative_density(**kwargs)
plot_cumulative_hazard(**kwargs)
plot_density(**kwargs)
plot_hazard(bandwidth=None, **kwargs)
plot_survival_function(**kwargs)
predict(times: Union[Iterable[float], float], interpolate=False) → pandas.core.series.Series

Predict the {0} at certain point in time. Uses a linear interpolation if points in time are not in the index.

Parameters:
  • times (scalar, or array) – a scalar or an array of times to predict the value of {0} at.
  • interpolate (bool, optional (default=False)) – for methods that produce a stepwise solution (Kaplan-Meier, Nelson-Aalen, etc), turning this to True will use an linear interpolation method to provide a more “smooth” answer.
smoothed_hazard_(bandwidth)
Parameters:bandwidth (float) – the bandwith used in the Epanechnikov kernel.
Returns:a DataFrame of the smoothed hazard
Return type:DataFrame
smoothed_hazard_confidence_intervals_(bandwidth, hazard_=None)
Parameters:
  • bandwidth (float) – the bandwidth to use in the Epanechnikov kernel. > 0
  • hazard_ (numpy array) – a computed (n,) numpy array of estimated hazard rates. If none, uses smoothed_hazard_
subtract(other) → pandas.core.frame.DataFrame

Subtract the {0} of two {1} objects.

Parameters:other (same object as self)
survival_function_at_times(times, label=None)