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 | 76 | 70 | 74 | 80 | |
| life_satisfaction | Mean (SD) | 4.8 (0.9) | 5.1 (0.8) | 5.2 (0.9) | 4.5 (1.0) | 4.6 (0.8) |
| Missing, n (%) | 8 (3%) | 3 (4%) | 1 (1%) | 4 (5%) | 0 (0%) | |
| income | Mean (SD) | 59844.7 (16793.5) | 62480.1 (17120.8) | 67736.6 (16403.5) | 53668.0 (13730.9) | 55987.8 (16334.2) |
| Missing, n (%) | 11 (4%) | 2 (3%) | 2 (3%) | 3 (4%) | 4 (5%) | |
| stress | Mean (SD) | 5.1 (2.2) | 4.4 (1.8) | 4.0 (2.2) | 5.9 (2.1) | 5.8 (1.9) |
| education | postgraduate | 46 (15%) | 9 (12%) | 11 (16%) | 12 (16%) | 14 (18%) |
| secondary | 123 (41%) | 30 (39%) | 25 (36%) | 31 (42%) | 37 (46%) | |
| undergraduate | 131 (44%) | 37 (49%) | 34 (49%) | 31 (42%) | 29 (36%) |