{"action":"created","issue":{"url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/250","repository_url":"https://api.github.com/repos/CamDavidsonPilon/lifelines","labels_url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/250/comments","events_url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/250/events","html_url":"https://github.com/CamDavidsonPilon/lifelines/issues/250","id":174447315,"number":250,"title":"Failure function plotting","user":{"login":"bennoleslie","id":308519,"avatar_url":"https://avatars.githubusercontent.com/u/308519?v=3","gravatar_id":"","url":"https://api.github.com/users/bennoleslie","html_url":"https://github.com/bennoleslie","followers_url":"https://api.github.com/users/bennoleslie/followers","following_url":"https://api.github.com/users/bennoleslie/following{/other_user}","gists_url":"https://api.github.com/users/bennoleslie/gists{/gist_id}","starred_url":"https://api.github.com/users/bennoleslie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bennoleslie/subscriptions","organizations_url":"https://api.github.com/users/bennoleslie/orgs","repos_url":"https://api.github.com/users/bennoleslie/repos","events_url":"https://api.github.com/users/bennoleslie/events{/privacy}","received_events_url":"https://api.github.com/users/bennoleslie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-01T06:36:33Z","updated_at":"2016-09-01T12:36:35Z","closed_at":null,"body":"I'd like to be able to plot the F(t) rather than S(t) as it is a more informative way at looking at the data in my use case.\r\n\r\nIt's not clear what the best way of doing this would be with the current API. I ended up modifying the \r\n\r\n```diff\r\n--- a/lifelines/fitters/kaplan_meier_fitter.py\r\n+++ b/lifelines/fitters/kaplan_meier_fitter.py\r\n@@ -20,7 +20,7 @@ class KaplanMeierFitter(UnivariateFitter):\r\n     \"\"\"\r\n\r\n     def fit(self, durations, event_observed=None, timeline=None, entry=None, label='KM_estimate',\r\n-            alpha=None, left_censorship=False, ci_labels=None):\r\n+            alpha=None, left_censorship=False, ci_labels=None, survival=True):\r\n         \"\"\"\r\n         Parameters:\r\n           duration: an array, or pd.Series, of length n -- duration subject was observed for\r\n@@ -63,8 +63,10 @@ class KaplanMeierFitter(UnivariateFitter):\r\n                 raise StatError(\"\"\"There are too few early truncation times and too many events. S(t)==0 for all t>%.1f. Recommend BreslowFlemingHarringtonFitter.\"\"\" % ix)\r\n\r\n         # estimation\r\n-        setattr(self, estimate_name, pd.DataFrame(np.exp(log_survival_function), columns=[self._label]))\r\n-        self.__estimate = getattr(self, estimate_name)\r\n+        self.__estimate = pd.DataFrame(np.exp(log_survival_function), columns=[self._label])\r\n+        if not survival:\r\n+            self.__estimate = 1 - self.__estimate\r\n+        setattr(self, estimate_name, self.__estimate)\r\n         self.confidence_interval_ = self._bounds(cumulative_sq_[:, None], alpha, ci_labels)\r\n         self.median_ = median_survival_times(self.__estimate)\r\n```\r\n\r\nIs there a more straight forward way of achieving this?"},"comment":{"url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/comments/244065298","html_url":"https://github.com/CamDavidsonPilon/lifelines/issues/250#issuecomment-244065298","issue_url":"https://api.github.com/repos/CamDavidsonPilon/lifelines/issues/250","id":244065298,"user":{"login":"CamDavidsonPilon","id":884032,"avatar_url":"https://avatars.githubusercontent.com/u/884032?v=3","gravatar_id":"","url":"https://api.github.com/users/CamDavidsonPilon","html_url":"https://github.com/CamDavidsonPilon","followers_url":"https://api.github.com/users/CamDavidsonPilon/followers","following_url":"https://api.github.com/users/CamDavidsonPilon/following{/other_user}","gists_url":"https://api.github.com/users/CamDavidsonPilon/gists{/gist_id}","starred_url":"https://api.github.com/users/CamDavidsonPilon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CamDavidsonPilon/subscriptions","organizations_url":"https://api.github.com/users/CamDavidsonPilon/orgs","repos_url":"https://api.github.com/users/CamDavidsonPilon/repos","events_url":"https://api.github.com/users/CamDavidsonPilon/events{/privacy}","received_events_url":"https://api.github.com/users/CamDavidsonPilon/received_events","type":"User","site_admin":false},"created_at":"2016-09-01T12:36:35Z","updated_at":"2016-09-01T12:36:35Z","body":"The most basic way is to not modify anything and do:\r\n```\r\nkmf.fit(T, E)\r\n(1-kmf.survival_function_).plot()\r\n```\r\n\r\nIf you wanted to use the internal lifelines plotting library, then I'm afraid it's a bit more complicated. "}}
{"actor":{"display_login":"CamDavidsonPilon"}}