Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hantswilliams committed Sep 7, 2022
1 parent 01763db commit 460e1ce
Show file tree
Hide file tree
Showing 11 changed files with 833 additions and 1 deletion.
1 change: 1 addition & 0 deletions descriptive/example1/code/descriptive.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions descriptive/example1/code/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pandas
scipy
tableone
researchpy
157 changes: 157 additions & 0 deletions descriptive/example1/code/researchpy_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Yuib-1s1YRlt",
"outputId": "687cb64c-995a-43b1-ed47-185cb32e2008"
},
"outputs": [],
"source": [
"!pip install researchpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Tz1qKEMxYTCT"
},
"outputs": [],
"source": [
"import researchpy as rp\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "NHJ4xg5DYXZx",
"outputId": "03263426-2e84-4445-f952-8d10fbdff94e"
},
"outputs": [],
"source": [
"df = pd.read_csv('./data.csv')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2HyFY1tKgwDk",
"outputId": "f3c62ea7-52e8-463c-cf34-f1febaf833c0"
},
"outputs": [],
"source": [
"rp.codebook(df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "IBby_YNohrHl",
"outputId": "da650c24-9910-47e5-c8f4-7b0c65bbb7e7"
},
"outputs": [],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 179
},
"id": "fF8x6Hvdh5Tr",
"outputId": "34642f22-9b01-46fc-8940-4e7f32d09334"
},
"outputs": [],
"source": [
"## example of getting descriptives for single or group of continuous variables\n",
"\n",
"rp.summary_cont(df[['Age', 'HR', 'sBP']])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "7dUKqxsOiXkQ",
"outputId": "f4b7fa5e-473f-4407-b749-975623aae1e0"
},
"outputs": [],
"source": [
"rp.summary_cat(df[['Group', 'Smoke']])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "g3kA2jJoijzO",
"outputId": "f8556125-835f-43c4-b9e6-6f4878fc450d"
},
"outputs": [],
"source": [
"df['Group'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "sYipIGGximTA",
"outputId": "dc23d990-1a4d-45ac-b53c-79d743334215"
},
"outputs": [],
"source": [
"df['Smoke'].value_counts()"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
36 changes: 36 additions & 0 deletions descriptive/example1/code/tableone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd
from tableone import TableOne, load_dataset

##### DATASET 1 #####
example_data = load_dataset('pn2012')
# # littlerecode death where 0 is alive and 1 is dead
# example_data['death'] = example_data['death'].replace(0, 'alive')
example_data.dtypes
example_data_columns = ['Age', 'SysABP', 'Height', 'Weight', 'ICU', 'death']
example_data_categorical = ['ICU', 'death']
example_data_groupby = ['death']
example_data_labels={'death': 'mortality'}
exampleTab1 = TableOne(example_data, columns=example_data_columns,
categorical=example_data_categorical, groupby=example_data_groupby,
rename=example_data_labels, pval=False)
exampleTab1
print(exampleTab1.tabulate(tablefmt = "fancy_grid"))
exampleTab1.to_csv('descriptive/example1/data/test.csv')



##### DATASET 2 #####
my_data = pd.read_csv('descriptive/example1/data/data.csv')
df2 = my_data.copy()
df2.dtypes
list(df2)
df2.head(5)
df2['Smoke']
df2_columns = ['Age', 'HR', 'Group', 'sBP', 'Smoke']
df2_categories = ['Smoke', 'Group']
df2_groupby = ['Smoke']
# df2['Vocation'].value_counts()
df2_table1 = TableOne(df2, columns=df2_columns,
categorical=df2_categories, groupby=df2_groupby, pval=False)
print(df2_table1.tabulate(tablefmt = "fancy_grid"))
df2_table1.to_csv('descriptive/example1/data/test2.csv')
101 changes: 101 additions & 0 deletions descriptive/example1/data/Altair.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
SampleID,Type,Grade,MeasureA,MeasureB,MeasureC
1,I,2,25,31.3,110.1891467
2,II,4,22,23.8,99.61951223
3,I,3,22,27.6,87.55160191
4,II,2,28,33.2,85.56734707
5,II,4,30,31.8,110.2700532
6,I,3,26,26.4,99.84167892
7,I,2,26,33.7,76.78406754
8,II,3,28,35.8,92.68980598
9,I,4,23,25,105.3292932
10,II,2,25,26.9,102.7667628
11,II,4,26,32.8,103.1580788
12,I,3,22,28.9,99.63755467
13,I,2,28,36.5,93.36849383
14,II,4,24,27.3,104.725783
15,I,3,22,27.9,87.67951762
16,II,2,23,25.4,93.92992221
17,II,3,24,28.5,102.3853207
18,I,4,27,36.7,100.0448647
19,I,2,21,29.5,96.14677609
20,II,4,25,25.5,90.0584909
21,I,3,26,33.2,106.2905857
22,II,2,20,26.7,110.9012447
23,II,4,24,29,102.9123925
24,I,3,26,34.6,109.5989193
25,I,2,20,25.6,120.3092205
26,II,3,29,30.7,80.76294849
27,I,4,25,27.4,90.33607983
28,II,2,23,25.1,111.3001142
29,II,4,22,30.4,111.3810443
30,I,3,29,36.5,113.3473012
31,I,2,21,27,99.29337329
32,II,4,30,30.3,102.409397
33,I,3,21,24.9,94.59506272
34,II,2,23,29.5,105.072395
35,II,3,27,29.4,95.22285424
36,I,4,28,31.9,115.8428138
37,I,2,29,33.8,93.20039257
38,II,4,26,34.5,91.80364222
39,I,3,28,28.7,105.1201517
40,II,2,20,20.9,89.95307887
41,II,4,25,29.4,100.082686
42,I,3,20,23.8,105.1388602
43,I,2,25,27.7,96.57069437
44,II,3,29,31,89.02825048
45,I,4,27,28.1,115.9905033
46,II,2,24,33.1,109.6808062
47,II,4,25,25.5,97.9233459
48,I,3,23,27.4,91.43744805
49,I,2,24,29.4,89.17425205
50,II,4,23,30.9,104.5168731
51,I,3,23,31.3,120.8590099
52,II,2,26,34.5,103.1805883
53,II,3,20,22.7,92.01241296
54,I,4,26,33.8,98.24382294
55,I,2,28,37.9,112.6216806
56,II,4,30,32.5,114.5057637
57,I,3,29,32.1,85.65551755
58,II,2,21,22.6,99.92775192
59,II,4,20,29.4,101.7370707
60,I,3,29,32.3,104.6963938
61,I,2,30,35.1,90.68274837
62,II,3,22,28.6,104.945687
63,I,4,27,35.2,100.5862524
64,II,2,22,28.3,101.9664154
65,II,4,30,37.5,117.9238576
66,I,3,24,32.7,99.11348868
67,I,2,28,34.6,87.66866232
68,II,4,22,29.5,103.8499839
69,I,3,27,37,105.52171
70,II,2,28,29.2,98.54170359
71,II,3,23,24.1,102.9014881
72,I,4,30,33.6,96.67562447
73,I,2,27,32,103.6666286
74,II,4,23,27.4,96.26970859
75,I,3,25,33.6,97.88947741
76,II,2,26,33.4,89.36824634
77,II,4,27,29.8,79.41290868
78,I,3,25,31.9,111.6602743
79,I,2,23,30.5,118.6330966
80,II,3,28,37.8,102.7833759
81,I,4,27,29.1,105.0360624
82,II,2,28,34.2,92.0825595
83,II,4,29,35.9,95.7516333
84,I,3,23,26.5,92.06924539
85,I,2,20,23.1,86.0933612
86,II,4,25,25.5,112.4517925
87,I,3,22,25,104.4103507
88,II,2,29,34.3,98.8985973
89,II,3,23,26.1,96.47799202
90,I,4,24,30.4,101.1108615
91,I,2,27,33.4,98.05828612
92,II,4,24,25.9,112.3727757
93,I,3,24,30.1,91.94633635
94,II,2,21,28.5,115.3320592
95,II,4,29,29.2,96.69564868
96,I,3,21,25,103.2237425
97,I,2,26,26.4,101.1300201
98,II,3,21,24,117.7524212
99,I,4,30,36.3,101.5227999
100,II,2,23,29.3,80.16592453
Loading

0 comments on commit 460e1ce

Please sign in to comment.