yat  0.21pre
KaplanMeier.h
1 #ifndef _theplu_yat_statistics_kaplan_meier
2 #define _theplu_yat_statistics_kaplan_meier
3 
4 // $Id: KaplanMeier.h 4255 2022-12-16 03:11:14Z peter $
5 
6 /*
7  Copyright (C) 2022 Peter Johansson
8 
9  This file is part of the yat library, https://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <https://www.gnu.org/licenses/>.
23 */
24 
25 #include <map>
26 
27 namespace theplu {
28 namespace yat {
29 namespace statistics {
30 
43  {
44  public:
48  class TimePoint
49  {
50  public:
54  TimePoint(void);
55 
61  TimePoint(unsigned int event, unsigned int censored);
62 
68  unsigned int at_risk(void) const;
69 
73  unsigned int censored(void) const;
74 
78  unsigned int event(void) const;
79 
88  double survival_proportion(void) const;
89  private:
90  friend class KaplanMeier;
91  unsigned int censored_;
92  unsigned int event_;
93  unsigned int n_;
94  double s_;
95  };
96 
101  typedef std::map<double, TimePoint>::const_iterator const_iterator;
102 
106  KaplanMeier(void);
107 
115  void add(double time, bool event);
116 
123  void add(double time, unsigned int event, unsigned int censored);
124 
128  const_iterator begin(void) const;
129 
133  void clear(void);
134 
138  const_iterator end(void) const;
139 
144  const_iterator find(double time) const;
145 
149  const_iterator lower_bound(double time) const;
150 
154  const_iterator upper_bound(double time) const;
155  private:
156  // Calculated data in data_ is not calculated every time data is
157  // added, but calculated lazily first when needed, i.e., when user
158  // is accessing the data.
159  mutable bool updated_;
160  mutable std::map<double, TimePoint> data_;
161  void update(void) const;
162  unsigned int n_;
163  };
164 
165 }}} // of namespace statistics, yat, and theplu
166 
167 #endif
const_iterator find(double time) const
const_iterator begin(void) const
The Department of Theoretical Physics namespace as we define it.
void add(double time, bool event)
Kaplan-Meier estimator.
Definition: KaplanMeier.h:42
const_iterator upper_bound(double time) const
const_iterator lower_bound(double time) const
const_iterator end(void) const
std::map< double, TimePoint >::const_iterator const_iterator
Definition: KaplanMeier.h:101

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14