Skip to content

Commit

Permalink
updated class_esrd_outcomes documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lshpaner committed Jul 27, 2024
1 parent 0af910b commit b967346
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 82 deletions.
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/.doctrees/usage_guide.doctree
Binary file not shown.
107 changes: 79 additions & 28 deletions docs/_sources/usage_guide.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,65 @@ Classifying ESRD Outcome by 2 and 5 Year Outcomes
:param str col: The column name with ESRD (should be eGFR < 15 flag).
:param int years: The number of years to use in the condition.
:param str duration_col: The name of the column containing the duration data.
:param str prefix: (`optional`) Custom prefix for the new column name. If None, no prefix is added.
:param str prefix: (`optional`) Custom prefix for the new column name. If ``None``, no prefix is added.
:param bool create_years_col: (`optional`) Whether to create the 'years' column. Default is True.

:returns: ``pd.DataFrame``: The modified DataFrame with the new column added.

This function creates a new column in the DataFrame which is populated with a 1 or a 0 based on whether the ESRD condition (eGFR < 15) is met within the specified number of years. If `create_years_col` is set to True, it calculates the 'years' column based on the `duration_col` provided. If False, it uses the `duration_col` directly. The new column is named using the specified prefix and number of years, or just the number of years if no prefix is provided.
This function creates a new column in the DataFrame which is populated with a ``1`` or a ``0`` based on whether the ESRD condition (eGFR < 15) is met within the specified number of years. If ``create_years_col`` is set to ``True``, it calculates the 'years' column based on the ``duration_col`` provided. If ``False``, it uses the ``duration_col`` directly. The new column is named using the specified prefix and number of years, or just the number of years if no prefix is provided.


**Example Usage**

.. code-block:: python
from kfre import class_esrd_outcome
.. code-block:: python
# 2-year outcome
df = class_esrd_outcome(
df=df,
col="ESRD",
years=2,
duration_col="Follow-up YEARS",
prefix=None,
create_years_col=False,
)
# 5-year outcome
df = class_esrd_outcome(
df=df,
col="ESRD",
years=5,
duration_col="Follow-up YEARS",
prefix=None,
create_years_col=False,
)
.. raw:: html

<div style="text-align: left; margin-bottom: 10px;">
<i>
First 5 Rows of Outcome Data
</i>
</div>

.. table::
:align: left


====== =============== ===============
Index 2_year_outcome 5_year_outcome
====== =============== ===============
0 0 0
1 1 1
2 0 0
3 1 1
4 0 0
====== =============== ===============



Batch Risk Calculation for Multiple Patients
Expand Down Expand Up @@ -435,6 +488,30 @@ This function is designed to compute the risk of chronic kidney disease (CKD) ov
The ``sex_col`` must contain strings (case-insensitive) indicating either `female` or `male`.


**Example Usage**

.. code-block:: python
df = add_kfre_risk_col(
df=df,
age_col="Age",
sex_col="SEX",
eGFR_col="eGFR-EPI",
uACR_col="uACR",
dm_col="Diabetes (1=yes; 0=no)",
htn_col="Hypertension (1=yes; 0=no)",
albumin_col="Albumin_g_dl",
phosphorous_col="Phosphate_mg_dl",
bicarbonate_col="Bicarbonate (mmol/L)",
calcium_col="Calcium_mg_dl",
num_vars=8,
years=(2, 5),
is_north_american=False,
copy=False # Modify the original DataFrame directly
)
# The resulting DataFrame 'df' now includes new columns with risk
# predictions for each model and time frame
.. raw:: html

<div style="text-align: left;">
Expand All @@ -459,29 +536,3 @@ This function is designed to compute the risk of chronic kidney disease (CKD) ov
69.92 Male 0 0 12.0 74.299919 1 1 0.524577 0.174712 0.190458 0.551506 0.305670 0.806220
81.14 Female 1 1 15.0 59.683881 0 0 0.255029 0.073213 0.068968 0.237542 0.060353 0.244235
======== ====== ======================== ========================== ========= ============ ================ ================ ================ ================ ================ ================ ================ ================


**Example Usage**

.. code-block:: python
df = add_kfre_risk_col(
df=df,
age_col="Age",
sex_col="SEX",
eGFR_col="eGFR-EPI",
uACR_col="uACR",
dm_col="Diabetes (1=yes; 0=no)",
htn_col="Hypertension (1=yes; 0=no)",
albumin_col="Albumin_g_dl",
phosphorous_col="Phosphate_mg_dl",
bicarbonate_col="Bicarbonate (mmol/L)",
calcium_col="Calcium_mg_dl",
num_vars=8,
years=(2, 5),
is_north_american=False,
copy=False # Modify the original DataFrame directly
)
# The resulting DataFrame 'df' now includes new columns with risk
# predictions for each model and time frame
df
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

108 changes: 83 additions & 25 deletions docs/usage_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ <h1>Classifying ESRD Outcome by 2 and 5 Year Outcomes<a class="headerlink" href=
<li><p><strong>col</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a>) – The column name with ESRD (should be eGFR &lt; 15 flag).</p></li>
<li><p><strong>years</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><em>int</em></a>) – The number of years to use in the condition.</p></li>
<li><p><strong>duration_col</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a>) – The name of the column containing the duration data.</p></li>
<li><p><strong>prefix</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a>) – (<cite>optional</cite>) Custom prefix for the new column name. If None, no prefix is added.</p></li>
<li><p><strong>prefix</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a>) – (<cite>optional</cite>) Custom prefix for the new column name. If <code class="docutils literal notranslate"><span class="pre">None</span></code>, no prefix is added.</p></li>
<li><p><strong>create_years_col</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><em>bool</em></a>) – (<cite>optional</cite>) Whether to create the ‘years’ column. Default is True.</p></li>
</ul>
</dd>
Expand All @@ -518,7 +518,66 @@ <h1>Classifying ESRD Outcome by 2 and 5 Year Outcomes<a class="headerlink" href=
</dl>
</dd></dl>

<p>This function creates a new column in the DataFrame which is populated with a 1 or a 0 based on whether the ESRD condition (eGFR &lt; 15) is met within the specified number of years. If <cite>create_years_col</cite> is set to True, it calculates the ‘years’ column based on the <cite>duration_col</cite> provided. If False, it uses the <cite>duration_col</cite> directly. The new column is named using the specified prefix and number of years, or just the number of years if no prefix is provided.</p>
<p>This function creates a new column in the DataFrame which is populated with a <code class="docutils literal notranslate"><span class="pre">1</span></code> or a <code class="docutils literal notranslate"><span class="pre">0</span></code> based on whether the ESRD condition (eGFR &lt; 15) is met within the specified number of years. If <code class="docutils literal notranslate"><span class="pre">create_years_col</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, it calculates the ‘years’ column based on the <code class="docutils literal notranslate"><span class="pre">duration_col</span></code> provided. If <code class="docutils literal notranslate"><span class="pre">False</span></code>, it uses the <code class="docutils literal notranslate"><span class="pre">duration_col</span></code> directly. The new column is named using the specified prefix and number of years, or just the number of years if no prefix is provided.</p>
<p><strong>Example Usage</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">kfre</span> <span class="kn">import</span> <span class="n">class_esrd_outcome</span>
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># 2-year outcome</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">class_esrd_outcome</span><span class="p">(</span>
<span class="n">df</span><span class="o">=</span><span class="n">df</span><span class="p">,</span>
<span class="n">col</span><span class="o">=</span><span class="s2">&quot;ESRD&quot;</span><span class="p">,</span>
<span class="n">years</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="n">duration_col</span><span class="o">=</span><span class="s2">&quot;Follow-up YEARS&quot;</span><span class="p">,</span>
<span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">create_years_col</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="p">)</span>

<span class="c1"># 5-year outcome</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">class_esrd_outcome</span><span class="p">(</span>
<span class="n">df</span><span class="o">=</span><span class="n">df</span><span class="p">,</span>
<span class="n">col</span><span class="o">=</span><span class="s2">&quot;ESRD&quot;</span><span class="p">,</span>
<span class="n">years</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
<span class="n">duration_col</span><span class="o">=</span><span class="s2">&quot;Follow-up YEARS&quot;</span><span class="p">,</span>
<span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">create_years_col</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<div style="text-align: left; margin-bottom: 10px;">
<i>
First 5 Rows of Outcome Data
</i>
</div><table class="docutils align-left">
<thead>
<tr class="row-odd"><th class="head"><p>Index</p></th>
<th class="head"><p>2_year_outcome</p></th>
<th class="head"><p>5_year_outcome</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p>1</p></td>
<td><p>1</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p>3</p></td>
<td><p>1</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p>4</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
</tr>
</tbody>
</table>
</section>
<section id="batch-risk-calculation-for-multiple-patients">
<h1>Batch Risk Calculation for Multiple Patients<a class="headerlink" href="#batch-risk-calculation-for-multiple-patients" title="Link to this heading"></a></h1>
Expand Down Expand Up @@ -581,6 +640,28 @@ <h1>Batch Risk Calculation for Multiple Patients<a class="headerlink" href="#bat
<p class="admonition-title">Important</p>
<p>The <code class="docutils literal notranslate"><span class="pre">sex_col</span></code> must contain strings (case-insensitive) indicating either <cite>female</cite> or <cite>male</cite>.</p>
</div>
<p><strong>Example Usage</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">df</span> <span class="o">=</span> <span class="n">add_kfre_risk_col</span><span class="p">(</span>
<span class="n">df</span><span class="o">=</span><span class="n">df</span><span class="p">,</span>
<span class="n">age_col</span><span class="o">=</span><span class="s2">&quot;Age&quot;</span><span class="p">,</span>
<span class="n">sex_col</span><span class="o">=</span><span class="s2">&quot;SEX&quot;</span><span class="p">,</span>
<span class="n">eGFR_col</span><span class="o">=</span><span class="s2">&quot;eGFR-EPI&quot;</span><span class="p">,</span>
<span class="n">uACR_col</span><span class="o">=</span><span class="s2">&quot;uACR&quot;</span><span class="p">,</span>
<span class="n">dm_col</span><span class="o">=</span><span class="s2">&quot;Diabetes (1=yes; 0=no)&quot;</span><span class="p">,</span>
<span class="n">htn_col</span><span class="o">=</span><span class="s2">&quot;Hypertension (1=yes; 0=no)&quot;</span><span class="p">,</span>
<span class="n">albumin_col</span><span class="o">=</span><span class="s2">&quot;Albumin_g_dl&quot;</span><span class="p">,</span>
<span class="n">phosphorous_col</span><span class="o">=</span><span class="s2">&quot;Phosphate_mg_dl&quot;</span><span class="p">,</span>
<span class="n">bicarbonate_col</span><span class="o">=</span><span class="s2">&quot;Bicarbonate (mmol/L)&quot;</span><span class="p">,</span>
<span class="n">calcium_col</span><span class="o">=</span><span class="s2">&quot;Calcium_mg_dl&quot;</span><span class="p">,</span>
<span class="n">num_vars</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
<span class="n">years</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span>
<span class="n">is_north_american</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">copy</span><span class="o">=</span><span class="kc">False</span> <span class="c1"># Modify the original DataFrame directly</span>
<span class="p">)</span>
<span class="c1"># The resulting DataFrame &#39;df&#39; now includes new columns with risk</span>
<span class="c1"># predictions for each model and time frame</span>
</pre></div>
</div>
<div style="text-align: left;">

<i>
Expand Down Expand Up @@ -685,29 +766,6 @@ <h1>Batch Risk Calculation for Multiple Patients<a class="headerlink" href="#bat
</tr>
</tbody>
</table>
<p><strong>Example Usage</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">df</span> <span class="o">=</span> <span class="n">add_kfre_risk_col</span><span class="p">(</span>
<span class="n">df</span><span class="o">=</span><span class="n">df</span><span class="p">,</span>
<span class="n">age_col</span><span class="o">=</span><span class="s2">&quot;Age&quot;</span><span class="p">,</span>
<span class="n">sex_col</span><span class="o">=</span><span class="s2">&quot;SEX&quot;</span><span class="p">,</span>
<span class="n">eGFR_col</span><span class="o">=</span><span class="s2">&quot;eGFR-EPI&quot;</span><span class="p">,</span>
<span class="n">uACR_col</span><span class="o">=</span><span class="s2">&quot;uACR&quot;</span><span class="p">,</span>
<span class="n">dm_col</span><span class="o">=</span><span class="s2">&quot;Diabetes (1=yes; 0=no)&quot;</span><span class="p">,</span>
<span class="n">htn_col</span><span class="o">=</span><span class="s2">&quot;Hypertension (1=yes; 0=no)&quot;</span><span class="p">,</span>
<span class="n">albumin_col</span><span class="o">=</span><span class="s2">&quot;Albumin_g_dl&quot;</span><span class="p">,</span>
<span class="n">phosphorous_col</span><span class="o">=</span><span class="s2">&quot;Phosphate_mg_dl&quot;</span><span class="p">,</span>
<span class="n">bicarbonate_col</span><span class="o">=</span><span class="s2">&quot;Bicarbonate (mmol/L)&quot;</span><span class="p">,</span>
<span class="n">calcium_col</span><span class="o">=</span><span class="s2">&quot;Calcium_mg_dl&quot;</span><span class="p">,</span>
<span class="n">num_vars</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
<span class="n">years</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span>
<span class="n">is_north_american</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">copy</span><span class="o">=</span><span class="kc">False</span> <span class="c1"># Modify the original DataFrame directly</span>
<span class="p">)</span>
<span class="c1"># The resulting DataFrame &#39;df&#39; now includes new columns with risk</span>
<span class="c1"># predictions for each model and time frame</span>
<span class="n">df</span>
</pre></div>
</div>
</section>


Expand Down
Loading

0 comments on commit b967346

Please sign in to comment.