Exploring data¶
A first look at a dataset, all in one theme: distributions, categories, correlations, cumulative distributions and a missing-data map. Every figure below is produced by running the code shown.
import depictr as dp
wb = dp.wellbeing_survey()
ld = dp.lexical_decision()
Cumulative distribution by group¶
An empirical cumulative distribution, with the legend tucked into the bottom-right the curves leave empty once they saturate.
p = dp.ecdf_plot(ld, "RT", group="condition", legend_inside=True)
print(show(p))
A categorical comparison¶
One categorical column as a proportion within the levels of another, here education across the regions.
p = dp.explore_categorical(wb, "education", group="region")
print(show(p))
Two variables, any types¶
explore_bivariate chooses the plot from the column types, here a numeric
response across a category.
p = dp.explore_bivariate(ld, "condition", "RT")
print(show(p))
For two numeric columns it draws a scatter with a fitted trend, and a group splits the trend line.
cy = dp.crop_yield()
p = dp.scatter_trend(cy, "fertiliser", "yield", group="treatment")
print(show(p))
Correlation heatmap¶
Every pairwise Pearson correlation among the numeric columns, on one diverging scale running from -1 to 1.
p = dp.correlation_heatmap(wb)
print(show(p))
Scatter-plot matrix¶
The pairwise relationships the heatmap condenses, drawn in full.
p = dp.explore_pairs(cy, cols=["rainfall", "fertiliser", "soil_ph", "yield"])
print(show(p, width=8, height=7))
Raincloud¶
Density, box and raw points together.
p = dp.raincloud_plot(ld, "RT", group="condition")
print(show(p))
Missing-data map¶
Columns are ordered most- to least-missing, so the legend sits inside the top-right over the most-complete columns.
p = dp.missingness_map(wb, legend_inside=True)
print(show(p))
Group means over the raw data¶
Each group's mean with a confidence interval, drawn over its jittered observations.
p = dp.group_comparison_plot(ld, "RT", "condition")
print(show(p))
Ridgeline¶
Stacked densities, one ridge per region, ordered by median.
p = dp.ridgeline_plot(wb, "life_satisfaction", "region")
print(show(p))
Dumbbell¶
Two age groups across the regions, each pair joined by a segment whose length is the gap between them.
import numpy as np
wb_age = wb.assign(age_group=np.where(wb["age"] < 50, "under 50", "50 or over"))
p = dp.dumbbell_plot(wb_age, "region", "life_satisfaction", "age_group",
legend_inside=True)
print(show(p))
Outliers¶
A single variable's box plot with points beyond 1.5 times the interquartile range flagged in the accent colour.
p = dp.outlier_plot(cy, "yield")
print(show(p))
A descriptive summary table¶
A 'Table 1' of means, counts and missingness by group, returned as a data frame ready for any formatter. Variables with missing values gain their own row.
tab = dp.summary_table(
wb,
vars=["life_satisfaction", "income", "stress", "education"],
group="region")
print(table(tab))
| variable | statistic | Overall | East | North | South | West |
|---|---|---|---|---|---|---|
| N | 300 | 69 | 82 | 67 | 82 | |
| life_satisfaction | Mean (SD) | 4.3 (1.1) | 4.7 (0.9) | 4.8 (1.0) | 3.6 (1.0) | 4.1 (1.0) |
| Missing, n (%) | 7 (2%) | 1 (1%) | 3 (4%) | 1 (1%) | 2 (2%) | |
| income | Mean (SD) | 31343.7 (14099.0) | 32410.2 (13381.5) | 36070.5 (15999.9) | 25508.6 (11332.3) | 30094.6 (12902.8) |
| Missing, n (%) | 23 (8%) | 6 (9%) | 4 (5%) | 9 (13%) | 4 (5%) | |
| stress | Mean (SD) | 4.1 (1.4) | 3.7 (1.2) | 3.4 (1.5) | 5.0 (1.1) | 4.3 (1.3) |
| education | secondary | 140 (47%) | 31 (45%) | 37 (45%) | 33 (49%) | 39 (48%) |
| undergraduate | 113 (38%) | 28 (41%) | 29 (35%) | 22 (33%) | 34 (41%) | |
| postgraduate | 47 (16%) | 10 (14%) | 16 (20%) | 12 (18%) | 9 (11%) |