Skip to content

Commit

Permalink
Merge pull request #167 from tompollard/tp/continuous
Browse files Browse the repository at this point in the history
Add argument for continuous variables
  • Loading branch information
tompollard authored Jun 5, 2024
2 parents e6c4ad6 + 226ed2d commit ce32c82
Show file tree
Hide file tree
Showing 5 changed files with 1,778 additions and 64 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,33 @@ columns = ['Age', 'SysABP', 'Height', 'Weight', 'ICU', 'death']
categorical = ['ICU', 'death']
```

5. Optionally, a categorical variable for stratification, a list of non-normal variables, and a dictionary of alternative labels:
5. Optionally, a list of columns containing continuous variables:

```python
continuous = ['Age', 'SysABP', 'Height', 'Weight']
```

6. Optionally, a categorical variable for stratification, a list of non-normal variables, and a dictionary of alternative labels:

```python
groupby = 'death'
nonnormal = ['Age']
labels={'death': 'mortality'}
```

6. Create an instance of TableOne with the input arguments:
7. Create an instance of TableOne with the input arguments:

```python
mytable = TableOne(data, columns=columns, categorical=categorical, groupby=groupby, nonnormal=nonnormal, rename=labels, pval=False)
mytable = TableOne(data, columns=columns, categorical=categorical, continuous=continuous, groupby=groupby, nonnormal=nonnormal, rename=labels, pval=False)
```

7. Display the table using the `tabulate` method. The `tablefmt` argument allows the table to be displayed in multiple formats, including "github", "grid", "fancy_grid", "rst", "html", and "latex".
8. Display the table using the `tabulate` method. The `tablefmt` argument allows the table to be displayed in multiple formats, including "github", "grid", "fancy_grid", "rst", "html", and "latex".

```python
print(mytable.tabulate(tablefmt = "fancy_grid"))
```

8. ...which prints the following table to screen:
9. ...which prints the following table to screen:

Grouped by mortality:

Expand All @@ -128,7 +134,7 @@ Grouped by mortality:
| mortality | 0 | 0 | 864 (100.0) | |
| | 1 | | | 136 (100.0) |

9. Tables can be exported to file in various formats, including LaTeX, CSV, and HTML. Files are exported by calling the ``to_format`` method on the tableone object. For example, mytable can be exported to an Excel spreadsheet named 'mytable.xlsx' with the following command:
10. Tables can be exported to file in various formats, including LaTeX, CSV, and HTML. Files are exported by calling the ``to_format`` method on the tableone object. For example, mytable can be exported to an Excel spreadsheet named 'mytable.xlsx' with the following command:

```python
mytable.to_excel('mytable.xlsx')
Expand Down
6 changes: 5 additions & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ Example

categorical = ['ascites','hepato','edema','sex','spiders','trt']

#. Optionally, a list of columns containing continuous variables::

continuous = ['age','bili','albumin','ast','platelet','protime']

#. Optionally, a categorical variable for stratification and a list of non-normal variables::

groupby = 'trt'
nonnormal = ['bili']

#. Create an instance of TableOne with the input arguments::

mytable = TableOne(data, columns, categorical, groupby, nonnormal)
mytable = TableOne(data, columns, categorical, continuous, groupby, nonnormal)

#. Display the table using the ``tabulate`` method. The ``tablefmt`` argument allows the table to be displayed in multiple formats, including "github", "grid", "fancy_grid", "rst", "html", and "latex".::

Expand Down
Loading

0 comments on commit ce32c82

Please sign in to comment.