Skip to content

Commit a8d2c41

Browse files
committed
Refactoring notebooks for the documentation
1 parent 7b2ef13 commit a8d2c41

3 files changed

Lines changed: 49 additions & 63 deletions

File tree

nbs/tutorials/01-basics.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
"\"unpaired mean difference\"). The confidence interval is reported as:\n",
463463
"[*confidenceIntervalWidth* *LowerBound*, *UpperBound*]\n",
464464
"\n",
465-
"This confidence interval is generated through bootstrap resampling. See :doc:`bootstraps` for more details.\n",
465+
"This confidence interval is generated through bootstrap resampling. See [`bootstraps`](/blog/posts/bootstraps/bootstraps.html) for more details.\n",
466466
"\n",
467467
"Since v0.3.0, DABEST will report the p-value of the [non-parametric two-sided approximate permutation t-test](https://en.wikipedia.org/wiki/Resampling_(statistics)#Permutation_tests). This is also known as *the Monte Carlo permutation test*.\n",
468468
"\n",
@@ -875,7 +875,7 @@
875875
"source": [
876876
"To generate a **Gardner-Altman estimation plot**, simply use the\n",
877877
"``.plot()`` method. You can learn more about its genesis and design\n",
878-
"inspiration at :doc:`robust-beautiful`.\n",
878+
"inspiration at [`robust-beautiful`](/blog/posts/robust-beautiful/robust-beautiful.html).\n",
879879
"\n",
880880
"Each instance of an effect size has access to the ``.plot()`` method. This allows you to quickly create plots for different effect sizes with ease."
881881
]

nbs/tutorials/05-delta_delta.ipynb

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "cf1612f8",
66
"metadata": {},
77
"source": [
8-
"# Delta - Delta\n",
8+
"# Delta-Delta\n",
99
"\n",
1010
"> Explanation of how to calculate delta-delta using DABEST.\n",
1111
"\n",
@@ -17,11 +17,11 @@
1717
"id": "cfdb7e31",
1818
"metadata": {},
1919
"source": [
20-
"Since version 2023.02.14, DABEST also supports the calculation of delta-delta, an experimental function that enables the comparison between two bootstrapped effect sizes computed from two independent categorical variables. \n",
20+
"Since version 2023.02.14, DABEST also supports the calculation of delta-delta, an experimental function that facilitates the comparison between two bootstrapped effect sizes computed from two independent categorical variables. \n",
2121
"\n",
22-
"Many experimental designs investigate the effects of two interacting independent variables on a dependent variable. The delta-delta effect size lets us distill the net effect of the two variables. To illustrate this, let's explore the following problem. \n",
22+
"Many experimental designs investigate the effects of two interacting independent variables on a dependent variable. The delta-delta effect size enables us distill the net effect of the two variables. To illustrate this, let's explore the following problem. \n",
2323
"\n",
24-
"Consider an experiment where we test the efficacy of a drug named ``Drug`` on a disease-causing mutation ``M`` based on disease metric ``Y``. The greater value ``Y`` has the more severe the disease phenotype is. Phenotype ``Y`` has been shown to be caused by a gain of function mutation ``M``, so we expect a difference between wild type (``W``) subjects and mutant subjects (``M``). Now, we want to know whether this effect is ameliorated by the administration of ``Drug`` treatment. We also administer a placebo as a control. In theory, we only expect ``Drug`` to have an effect on the ``M`` group, although in practice many drugs have non-specific effects on healthy populations too.\n",
24+
"Consider an experiment where we test the efficacy of a drug named ``Drug`` on a disease-causing mutation ``M`` based on disease metric ``Y``. The greater the value ``Y`` has, the more severe the disease phenotype is. Phenotype ``Y`` has been shown to be caused by a gain-of-function mutation ``M``, so we expect a difference between wild type (``W``) subjects and mutant subjects (``M``). Now, we want to know whether this effect is ameliorated by the administration of ``Drug`` treatment. We also administer a placebo as a control. In theory, we only expect ``Drug`` to have an effect on the ``M`` group, although in practice, many drugs have non-specific effects on healthy populations too.\n",
2525
"\n",
2626
"Effectively, we have four groups of subjects for comparison."
2727
]
@@ -243,12 +243,8 @@
243243
"id": "f4315e6f",
244244
"metadata": {},
245245
"source": [
246-
"To make a delta-delta plot, you need to simply set ``delta2 = True`` in the \n",
247-
"``dabest.load()`` function. However, here ``x`` needs to be declared as a list\n",
248-
"consisting of 2 elements rather than 1 in most of the cases. The first element\n",
249-
"in ``x`` will be the variable plotted along the horizontal axis, and the second\n",
250-
"one will determine the colour of dots for scattered plots or the colour of lines\n",
251-
"for slopegraphs. We use the ``experiment`` input to specify grouping of the data.\n"
246+
"To create a delta-delta plot, you simply need to set ``delta2=True`` in the \n",
247+
"``dabest.load()`` function. However, in this case,``x`` needs to be declared as a list consisting of 2 elements, unlike most cases where it is a single element. The first element in ``x`` will represent the variable plotted along the horizontal axis, and the second one will determine the color of dots for scattered plots or the color of lines for slope graphs. We use the ``experiment`` input to specify the grouping of the data."
252248
]
253249
},
254250
{
@@ -386,11 +382,11 @@
386382
"and ``Drug`` group are plotted at the right bottom with a separate y-axis from other bootstrap plots. \n",
387383
"This effect size, at about -0.903 [95%CI -1.28, -0.513], is the net effect size of the drug treatment. That is to say that treatment with drug A reduced disease phenotype by 0.903.\n",
388384
"\n",
389-
"Mean difference between mutants and wild types given the placebo treatment is:\n",
385+
"The mean difference between mutants and wild types given the placebo treatment is:\n",
390386
"\n",
391387
"$\\Delta_{1} = \\overline{X}_{P, M} - \\overline{X}_{P, W}$\n",
392388
"\n",
393-
"Mean difference between mutants and wild types given the drug treatment is:\n",
389+
"The mean difference between mutants and wild types given the drug treatment is:\n",
394390
"\n",
395391
"\n",
396392
"$\\Delta_{2} = \\overline{X}_{D, M} - \\overline{X}_{D, W}$\n",
@@ -418,7 +414,7 @@
418414
"id": "58c98331",
419415
"metadata": {},
420416
"source": [
421-
"In the example above, we used the convention of \"test - control' but you can manipulate the orders of experiment groups as well as the horizontal axis variable by setting ``experiment_label`` and ``x1_level``.\n"
417+
"In the example above, we used the convention of *test - control* but you can manipulate the orders of the experiment groups as well as the horizontal axis variable by setting the paremeters ``experiment_label`` and ``x1_level``.\n"
422418
]
423419
},
424420
{
@@ -461,7 +457,7 @@
461457
"id": "fdc663cb",
462458
"metadata": {},
463459
"source": [
464-
"The delta - delta function also supports paired data, which is useful for us to visualise the data in an alternate way. Assuming that the placebo and drug treatment were done on the same subjects, our data is paired between the treatment conditions. We can specify this by using ``Treatment`` as ``x`` and ``Genotype`` as ``experiment``, and we further specify that ``id_col`` is ``ID``, linking data from the same subject with each other. Since we have done two replicates of the experiments, we can also colour the slope lines according to ``Rep``. \n"
460+
"The delta-delta function also supports paired data, providing a useful alternative visualization of the data. Assuming that the placebo and drug treatment were administered to the same subjects, our data is paired between the treatment conditions. We can specify this by using ``Treatment`` as ``x`` and ``Genotype`` as ``experiment``, and we further specify that ``id_col`` is ``ID``, linking data from the same subject with each other. Since we have conducted two replicates of the experiments, we can also colour the slope lines according to ``Rep``. "
465461
]
466462
},
467463
{
@@ -502,11 +498,11 @@
502498
"id": "3b07192c",
503499
"metadata": {},
504500
"source": [
505-
"Mean difference between drug and placebo treatments in wild type subjects is:\n",
501+
"The mean difference between drug and placebo treatments in wild type subjects is:\n",
506502
"\n",
507503
"$$\\Delta_{1} = \\overline{X}_{D, W} - \\overline{X}_{P, W}$$\n",
508504
"\n",
509-
"Mean difference between drug and placebo treatments in mutant subjects is:\n",
505+
"The mean difference between drug and placebo treatments in mutant subjects is:\n",
510506
"\n",
511507
"$$\\Delta_{2} = \\overline{X}_{D, M} - \\overline{X}_{P, M}$$\n",
512508
"\n",
@@ -530,11 +526,10 @@
530526
"id": "1429f772",
531527
"metadata": {},
532528
"source": [
533-
"Standardized mean difference statistics like Cohen's d and Hedges' g quantify effect sizes in terms of the sample variance. We devised a metric, Deltas' g, to standardize delta-delta effects. This metric then can allow the comparison between measurements of different dimensions.\n",
529+
"Standardized mean difference statistics like Cohen's d and Hedges' g quantify effect sizes in terms of the sample variance. We have introduced a metric, *Deltas' g*, to standardize delta-delta effects. This metric enables the comparison between measurements of different dimensions.\n",
534530
"\n",
535531
"The standard deviation of the delta-delta value is calculated from a pooled variance of the 4 samples:\n",
536532
"\n",
537-
"\n",
538533
"$$s_{\\Delta_{\\Delta}} = \\sqrt{\\frac{(n_{D, W}-1)s_{D, W}^2+(n_{P, W}-1)s_{P, W}^2+(n_{D, M}-1)s_{D, M}^2+(n_{P, M}-1)s_{P, M}^2}{(n_{D, W} - 1) + (n_{P, W} - 1) + (n_{D, M} - 1) + (n_{P, M} - 1)}}$$\n",
539534
"\n",
540535
"where $s$ is the standard deviation and $n$ is the sample size.\n",
@@ -583,16 +578,15 @@
583578
}
584579
],
585580
"source": [
586-
"unpaired_delta2.delta_g\n",
587-
"\n"
581+
"unpaired_delta2.delta_g"
588582
]
589583
},
590584
{
591585
"cell_type": "markdown",
592586
"id": "e53154bb",
593587
"metadata": {},
594588
"source": [
595-
"We see that the standardised delta-delta value of -2.11 standard deviations [95%CI -2.98, -1.2] as the net effect of the drug accounting for non-specific actions in healthy individuals. \n"
589+
"We see the standardised delta-delta value of -2.11 standard deviations [95%CI -2.98, -1.2] as the net effect of the drug accounting for non-specific actions in healthy individuals. "
596590
]
597591
},
598592
{
@@ -613,7 +607,7 @@
613607
}
614608
],
615609
"source": [
616-
"unpaired_delta2.delta_g.plot();"
610+
"unpaired_delta2.delta_g.plot();\n"
617611
]
618612
},
619613
{
@@ -721,8 +715,7 @@
721715
"id": "4ed26036",
722716
"metadata": {},
723717
"source": [
724-
"You can find all outputs of the delta - delta calculation by assessing the attribute named ``delta_delta`` of the \n",
725-
"effect size object."
718+
"You can find all outputs of the delta-delta calculation by assessing the attribute named ``delta_delta`` of the effect size object."
726719
]
727720
},
728721
{
@@ -771,7 +764,7 @@
771764
"id": "3ba800cc",
772765
"metadata": {},
773766
"source": [
774-
"``delta_delta`` has its own attributes, containing various information of delta - delta.\n",
767+
"The ``delta_delta`` object has its own attributes, containing various information of delta - delta.\n",
775768
"\n",
776769
" - ``difference``: the mean bootstrapped differences between the 2 groups of bootstrapped mean differences \n",
777770
" - ``bootstraps``: the 2 groups of bootstrapped mean differences \n",
@@ -780,7 +773,7 @@
780773
" - ``permutations_var``: the pooled group variances of two groups of bootstrapped mean differences calculated based on permutation data\n",
781774
" - ``permutations_delta_delta``: the delta-delta calculated based on the permutation data\n",
782775
"\n",
783-
"``delta_delta.to_dict()`` will return to you all the attributes in a dictionary format."
776+
"``delta_delta.to_dict()`` will return all the attributes in a dictionary format."
784777
]
785778
},
786779
{

nbs/tutorials/06-plot_aesthetics.ipynb

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"id": "eea91eac",
9191
"metadata": {},
9292
"source": [
93-
"Changing the y-axes labels."
93+
"## Changing y-axes labels"
9494
]
9595
},
9696
{
@@ -120,7 +120,10 @@
120120
"id": "8d0f7aed",
121121
"metadata": {},
122122
"source": [
123-
"Color the rawdata according to another column in the dataframe."
123+
"## Changing the graph colours\n",
124+
"\n",
125+
"### Colour categories from another variable\n",
126+
"Use the parameter `color_col` to specify which column in the dataframe will be used to create the different colours for your graph."
124127
]
125128
},
126129
{
@@ -175,7 +178,8 @@
175178
"id": "bccd01be",
176179
"metadata": {},
177180
"source": [
178-
"Changing the palette used with `custom_palette`. Any valid matplotlib or seaborn color palette is accepted."
181+
"### Adding a custom palette\n",
182+
"The colour palette for the graph can be changed using the parameter `custom_palette`. All values from matplotlib or seaborn color palettes are accepted."
179183
]
180184
},
181185
{
@@ -225,13 +229,9 @@
225229
"id": "5d1c2921",
226230
"metadata": {},
227231
"source": [
228-
"You can also create your own color palette. Create a dictionary where\n",
229-
"the keys are group names, and the values are valid matplotlib colors.\n",
232+
"Additionally, a customized color palette can be defined by creating a dictionary where the keys are group names, and the values are valid matplotlib colours.\n",
230233
"\n",
231-
"You can specify matplotlib colors in a [variety of\n",
232-
"ways](https://matplotlib.org/users/colors.html). Here, I demonstrate\n",
233-
"using named colors, hex strings (commonly used on the web), and RGB\n",
234-
"tuples."
234+
"There are [many ways](https://matplotlib.org/users/colors.html) to specify matplotlib colours. Find one example below using accepted colour names, hex strings (commonly used on the web), and RGB tuples."
235235
]
236236
},
237237
{
@@ -266,13 +266,12 @@
266266
"id": "032b975b",
267267
"metadata": {},
268268
"source": [
269-
"By default, ``dabest.plot()`` will\n",
270-
"[desaturate](https://en.wikipedia.org/wiki/Colorfulness#Saturation)\n",
271-
"the color of the dots in the swarmplot by 50%. This draws attention to\n",
272-
"the effect size bootstrap curves.\n",
269+
"## Changing colour saturation\n",
270+
"\n",
271+
"By default, ``dabest.plot()`` [desaturates](https://en.wikipedia.org/wiki/Colorfulness#Saturation)\n",
272+
"the colour of the dots in the swarmplot by 50%. This draws attention to the effect size bootstrap curves.\n",
273273
"\n",
274-
"You can alter the default values with the ``swarm_desat`` and\n",
275-
"``halfviolin_desat`` keywords.\n"
274+
"You can alter the default values with the parameters ``swarm_desat`` and ``halfviolin_desat``.\n"
276275
]
277276
},
278277
{
@@ -303,8 +302,8 @@
303302
"id": "9547d1aa",
304303
"metadata": {},
305304
"source": [
306-
"You can also change the sizes of the dots used in the rawdata swarmplot,\n",
307-
"and those used to indicate the effect sizes.\n"
305+
"## Changing size\n",
306+
"It is possible change the size of the dots used in the rawdata swarmplot, as well as those to indicate the effect sizes, by using the parameters `raw_marker_size` and `es_marker_size` respectively.\n"
308307
]
309308
},
310309
{
@@ -334,7 +333,9 @@
334333
"id": "21949c5f",
335334
"metadata": {},
336335
"source": [
337-
"Changing the y-limits for the rawdata axes, and for the contrast axes."
336+
"## Changing axes\n",
337+
"\n",
338+
"To change the y-limits for the rawdata axes, and the contrast axes, use the parameters `swarm_ylim` and `contrast_ylim`."
338339
]
339340
},
340341
{
@@ -364,7 +365,7 @@
364365
"id": "4688b5c9",
365366
"metadata": {},
366367
"source": [
367-
"If your effect size is qualitatively inverted (ie. a smaller value is a\n",
368+
"If the effect size is qualitatively inverted (ie. a smaller value is a\n",
368369
"better outcome), you can simply invert the tuple passed to\n",
369370
"``contrast_ylim``."
370371
]
@@ -396,8 +397,7 @@
396397
"id": "5c0f96f8",
397398
"metadata": {},
398399
"source": [
399-
"The contrast axes share the same y-limits as that of the delta - delta plot\n",
400-
"and thus the y axis of the delta - delta plot changes as well."
400+
"The contrast axes share the same y-limits as those of the delta-delta plot. Thus, the y axis of the delta-delta plot changes as well."
401401
]
402402
},
403403
{
@@ -472,7 +472,7 @@
472472
"id": "7682de82",
473473
"metadata": {},
474474
"source": [
475-
"You can also change the y-limits and y-label for the delta - delta plot."
475+
"You can also change the `*y-limits* and *y-label* for the delta-delta plot."
476476
]
477477
},
478478
{
@@ -502,11 +502,12 @@
502502
"id": "a60c4367",
503503
"metadata": {},
504504
"source": [
505+
"### Axes ticks\n",
505506
"You can add minor ticks and also change the tick frequency by accessing\n",
506507
"the axes directly.\n",
507508
"\n",
508-
"Each estimation plot produced by ``dabest`` has 2 axes. The first one\n",
509-
"contains the rawdata swarmplot; the second one contains the bootstrap\n",
509+
"Each estimation plot produced by ``dabest`` has two axes. The first one\n",
510+
"contains the rawdata swarmplot while the second one contains the bootstrap\n",
510511
"effect size differences.\n"
511512
]
512513
},
@@ -578,8 +579,8 @@
578579
"id": "ec7f5271",
579580
"metadata": {},
580581
"source": [
581-
"For mini-meta plots, you can hide the weighted avergae plot by setting \n",
582-
"``show_mini_meta=False`` in the ``plot()`` function."
582+
"## Hiding options \n",
583+
"For mini-meta plots, it is possible to hide the weighted average plot by setting the parameter ``show_mini_meta=False`` in the ``plot()`` function."
583584
]
584585
},
585586
{
@@ -677,7 +678,7 @@
677678
"source": [
678679
"*Implemented in v0.2.6 by Adam Nekimken*.\n",
679680
"\n",
680-
"``dabest.plot`` has an ``ax`` keyword that accepts any Matplotlib\n",
681+
"``dabest.plot`` has an ``ax`` parameter that accepts Matplotlib\n",
681682
"``Axes``. The entire estimation plot will be created in the specified\n",
682683
"``Axes``.\n"
683684
]
@@ -762,14 +763,6 @@
762763
"topleft_axes.set_ylabel(\"New y-axis label for rawdata\")\n",
763764
"topleft_axes.contrast_axes.set_ylabel(\"New y-axis label for effect size\")"
764765
]
765-
},
766-
{
767-
"cell_type": "code",
768-
"execution_count": null,
769-
"id": "4872a5d1",
770-
"metadata": {},
771-
"outputs": [],
772-
"source": []
773766
}
774767
],
775768
"metadata": {

0 commit comments

Comments
 (0)