Skip to content

Commit cfafe02

Browse files
committed
stylistic changes on nb3 and 4 - exercise label
1 parent 45d10fe commit cfafe02

6 files changed

Lines changed: 61 additions & 141 deletions

images/bacteria_model.jpg

30.7 KB
Loading

images/bacteria_model.pdf

6.18 KB
Binary file not shown.

notebooks/03-instructor-two-group-iq.ipynb

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@
120120
"\n",
121121
"Now that we have a first-pass generative model for the data, let's do some quick sanity checks against the data.\n",
122122
"\n",
123-
"#### Exercise 1\n",
124-
"\n",
125-
"Load the dataset into a pandas DataFrame. It is available at the path `../data/iq.csv`."
123+
"Let's get started by loading the data!"
126124
]
127125
},
128126
{
@@ -139,9 +137,7 @@
139137
"cell_type": "markdown",
140138
"metadata": {},
141139
"source": [
142-
"#### Exercise 2\n",
143-
"\n",
144-
"Plot the number of samples for drug and for treatment."
140+
"**Exercise:** Plot the number of samples for drug and for treatment."
145141
]
146142
},
147143
{
@@ -159,9 +155,7 @@
159155
"source": [
160156
"More important than the number of samples per treatment is the distribution of IQ, which will give us a hint as to whether we can expect a difference in effect.\n",
161157
"\n",
162-
"#### Exercise 3\n",
163-
"\n",
164-
"Plot the ECDF of the treatments vs. control. If you need to inspect the source code of ECDF, it is available below."
158+
"**Exercise:** Plot the ECDF of the treatments vs. control. If you need to inspect the source code of ECDF, it is available below."
165159
]
166160
},
167161
{
@@ -197,9 +191,7 @@
197191
"cell_type": "markdown",
198192
"metadata": {},
199193
"source": [
200-
"#### Discuss\n",
201-
"\n",
202-
"Does it look like the treatment had an effect on the IQ of the participants? What numbers from the chart above can help support your conclusions?"
194+
"**Discuss:** Does it look like the treatment had an effect on the IQ of the participants? What numbers from the chart above can help support your conclusions?"
203195
]
204196
},
205197
{
@@ -208,9 +200,7 @@
208200
"source": [
209201
"### Step 3: Fit Model\n",
210202
"\n",
211-
"#### Exercise\n",
212-
"\n",
213-
"We will specify the model below. Fill in the distributions as we go along in class. We are proceeding slowly here, simply to give you repetition practice with PyMC3's syntax."
203+
"**Exercise:** We will specify the model below. Fill in the distributions as we go along in class. We are proceeding slowly here, simply to give you repetition practice with PyMC3's syntax."
214204
]
215205
},
216206
{
@@ -310,9 +300,7 @@
310300
"\n",
311301
"We use posterior predictive checks (PPC) as one tool in our toolkit to evaluate and critique the model. The overarching goal of the PPC is to check that the data generating model generates simulated data that matches closely to the actual data. If this is the case, then we have a model that probably describes the data generating process well. If this is not the case, then we have evidence to go guide us towards re-doing the model.\n",
312302
"\n",
313-
"#### Exercise\n",
314-
"\n",
315-
"To do a PPC, PyMC3 provides a `sample_ppc` function, which allows us to draw samples from the posterior distribution as a check. Run the following cell, filling in the appropriate `trace` and `model`."
303+
"**Exercise:** To do a PPC, PyMC3 provides a `sample_ppc` function, which allows us to draw samples from the posterior distribution as a check. Run the following cell, filling in the appropriate `trace` and `model`."
316304
]
317305
},
318306
{
@@ -328,9 +316,7 @@
328316
"cell_type": "markdown",
329317
"metadata": {},
330318
"source": [
331-
"#### Exercise\n",
332-
"\n",
333-
"Let's now plot the ECDF of the sampled data against the original data."
319+
"**Exercise:** Let's now plot the ECDF of the sampled data against the original data."
334320
]
335321
},
336322
{
@@ -375,11 +361,14 @@
375361
"source": [
376362
"It looks like we have a model that, just by eyeballing the charts, models pretty well the distribution of the observed data.\n",
377363
"\n",
378-
"For pedagogical brevity, we did not dive into a case where the model was plausibly but nonetheless incorrectly specified. Under an incorrect model, we would expect the PPC and data distributions to be anywhere from moderately to wildly off. Having detected this from a visual comparison of the PPC samples and data, we would go back and try to see where we went wrong. We might also opt to quantify this difference using the tools provided in PyMC3. \n",
379-
"\n",
380-
"#### Exercise\n",
381-
"\n",
382-
"Now, let us evaluate whether the drug actually did have an effect. Recall that we computed the difference in means, as well as an effect size, both with uncertainty. Using this information, plot the posterior distribution of the difference in means and effect sizes."
364+
"For pedagogical brevity, we did not dive into a case where the model was plausibly but nonetheless incorrectly specified. Under an incorrect model, we would expect the PPC and data distributions to be anywhere from moderately to wildly off. Having detected this from a visual comparison of the PPC samples and data, we would go back and try to see where we went wrong. We might also opt to quantify this difference using the tools provided in PyMC3. "
365+
]
366+
},
367+
{
368+
"cell_type": "markdown",
369+
"metadata": {},
370+
"source": [
371+
"**Exercise:** Now, let us evaluate whether the drug actually did have an effect. Recall that we computed the difference in means, as well as an effect size, both with uncertainty. Using this information, plot the posterior distribution of the difference in means and effect sizes."
383372
]
384373
},
385374
{
@@ -405,9 +394,7 @@
405394
"cell_type": "markdown",
406395
"metadata": {},
407396
"source": [
408-
"#### Exercise\n",
409-
"\n",
410-
"Compute the p-value of the t-test for this dataset."
397+
"**Excercise:** Compute the p-value of the t-test for this dataset."
411398
]
412399
},
413400
{
@@ -425,8 +412,7 @@
425412
"cell_type": "markdown",
426413
"metadata": {},
427414
"source": [
428-
"#### Discuss\n",
429-
"\n",
415+
"**Discuss**:\n",
430416
"1. Is there a significant difference between the drug-treated and placebo-treated participants of the intervention? (This question is intentionally vague on the definition of \"significant\", to encourage discussion of the difference between statistical and practical significance.)\n",
431417
"1. Would you recommend the intervention as a method to raise people's IQ? How much money would you be willing to pay for this intervention?"
432418
]
@@ -435,7 +421,7 @@
435421
"cell_type": "markdown",
436422
"metadata": {},
437423
"source": [
438-
"### Further Reading/Watching\n",
424+
"## Further Reading/Watching\n",
439425
"\n",
440426
"- PyMC3's documentation contains an example of how to do [model selection][model_selection], which we did not touch on here. \n",
441427
"- John Kruschke's paper on [Bayesian Estimation][bayes_est] is what this notebook's example is based on. There is also a [YouTube video][bayes_yt] available.\n",

notebooks/03-student-two-group-iq.ipynb

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@
120120
"\n",
121121
"Now that we have a first-pass generative model for the data, let's do some quick sanity checks against the data.\n",
122122
"\n",
123-
"#### Exercise 1\n",
124-
"\n",
125-
"Load the dataset into a pandas DataFrame. It is available at the path `../data/iq.csv`."
123+
"Let's get started by loading the data!"
126124
]
127125
},
128126
{
@@ -139,9 +137,7 @@
139137
"cell_type": "markdown",
140138
"metadata": {},
141139
"source": [
142-
"#### Exercise 2\n",
143-
"\n",
144-
"Plot the number of samples for drug and for treatment."
140+
"**Exercise:** Plot the number of samples for drug and for treatment."
145141
]
146142
},
147143
{
@@ -159,9 +155,7 @@
159155
"source": [
160156
"More important than the number of samples per treatment is the distribution of IQ, which will give us a hint as to whether we can expect a difference in effect.\n",
161157
"\n",
162-
"#### Exercise 3\n",
163-
"\n",
164-
"Plot the ECDF of the treatments vs. control. If you need to inspect the source code of ECDF, it is available below."
158+
"**Exercise:** Plot the ECDF of the treatments vs. control. If you need to inspect the source code of ECDF, it is available below."
165159
]
166160
},
167161
{
@@ -204,9 +198,7 @@
204198
"cell_type": "markdown",
205199
"metadata": {},
206200
"source": [
207-
"#### Discuss\n",
208-
"\n",
209-
"Does it look like the treatment had an effect on the IQ of the participants? What numbers from the chart above can help support your conclusions?"
201+
"**Discuss:** Does it look like the treatment had an effect on the IQ of the participants? What numbers from the chart above can help support your conclusions?"
210202
]
211203
},
212204
{
@@ -215,9 +207,7 @@
215207
"source": [
216208
"### Step 3: Fit Model\n",
217209
"\n",
218-
"#### Exercise\n",
219-
"\n",
220-
"We will specify the model below. Fill in the distributions as we go along in class. We are proceeding slowly here, simply to give you repetition practice with PyMC3's syntax."
210+
"**Exercise:** We will specify the model below. Fill in the distributions as we go along in class. We are proceeding slowly here, simply to give you repetition practice with PyMC3's syntax."
221211
]
222212
},
223213
{
@@ -310,9 +300,7 @@
310300
"\n",
311301
"We use posterior predictive checks (PPC) as one tool in our toolkit to evaluate and critique the model. The overarching goal of the PPC is to check that the data generating model generates simulated data that matches closely to the actual data. If this is the case, then we have a model that probably describes the data generating process well. If this is not the case, then we have evidence to go guide us towards re-doing the model.\n",
312302
"\n",
313-
"#### Exercise\n",
314-
"\n",
315-
"To do a PPC, PyMC3 provides a `sample_ppc` function, which allows us to draw samples from the posterior distribution as a check. Run the following cell, filling in the appropriate `trace` and `model`."
303+
"**Exercise:** To do a PPC, PyMC3 provides a `sample_ppc` function, which allows us to draw samples from the posterior distribution as a check. Run the following cell, filling in the appropriate `trace` and `model`."
316304
]
317305
},
318306
{
@@ -329,9 +317,7 @@
329317
"cell_type": "markdown",
330318
"metadata": {},
331319
"source": [
332-
"#### Exercise\n",
333-
"\n",
334-
"Let's now plot the ECDF of the sampled data against the original data."
320+
"**Exercise:** Let's now plot the ECDF of the sampled data against the original data."
335321
]
336322
},
337323
{
@@ -376,11 +362,14 @@
376362
"source": [
377363
"It looks like we have a model that, just by eyeballing the charts, models pretty well the distribution of the observed data.\n",
378364
"\n",
379-
"For pedagogical brevity, we did not dive into a case where the model was plausibly but nonetheless incorrectly specified. Under an incorrect model, we would expect the PPC and data distributions to be anywhere from moderately to wildly off. Having detected this from a visual comparison of the PPC samples and data, we would go back and try to see where we went wrong. We might also opt to quantify this difference using the tools provided in PyMC3. \n",
380-
"\n",
381-
"#### Exercise\n",
382-
"\n",
383-
"Now, let us evaluate whether the drug actually did have an effect. Recall that we computed the difference in means, as well as an effect size, both with uncertainty. Using this information, plot the posterior distribution of the difference in means and effect sizes."
365+
"For pedagogical brevity, we did not dive into a case where the model was plausibly but nonetheless incorrectly specified. Under an incorrect model, we would expect the PPC and data distributions to be anywhere from moderately to wildly off. Having detected this from a visual comparison of the PPC samples and data, we would go back and try to see where we went wrong. We might also opt to quantify this difference using the tools provided in PyMC3. "
366+
]
367+
},
368+
{
369+
"cell_type": "markdown",
370+
"metadata": {},
371+
"source": [
372+
"**Exercise:** Now, let us evaluate whether the drug actually did have an effect. Recall that we computed the difference in means, as well as an effect size, both with uncertainty. Using this information, plot the posterior distribution of the difference in means and effect sizes."
384373
]
385374
},
386375
{
@@ -407,9 +396,7 @@
407396
"cell_type": "markdown",
408397
"metadata": {},
409398
"source": [
410-
"#### Exercise\n",
411-
"\n",
412-
"Compute the p-value of the t-test for this dataset."
399+
"**Excercise:** Compute the p-value of the t-test for this dataset."
413400
]
414401
},
415402
{
@@ -427,17 +414,16 @@
427414
"cell_type": "markdown",
428415
"metadata": {},
429416
"source": [
430-
"#### Discuss\n",
431-
"\n",
432-
"1. Is there a significant difference between the drug-treated and placebo-treated participants of the intervention?\n",
417+
"**Discuss**:\n",
418+
"1. Is there a significant difference between the drug-treated and placebo-treated participants of the intervention? (This question is intentionally vague on the definition of \"significant\", to encourage discussion of the difference between statistical and practical significance.)\n",
433419
"1. Would you recommend the intervention as a method to raise people's IQ? How much money would you be willing to pay for this intervention?"
434420
]
435421
},
436422
{
437423
"cell_type": "markdown",
438424
"metadata": {},
439425
"source": [
440-
"### Further Reading/Watching\n",
426+
"## Further Reading/Watching\n",
441427
"\n",
442428
"- PyMC3's documentation contains an example of how to do [model selection][model_selection], which we did not touch on here. \n",
443429
"- John Kruschke's paper on [Bayesian Estimation][bayes_est] is what this notebook's example is based on. There is also a [YouTube video][bayes_yt] available.\n",

notebooks/04-instructor-multi-group-comparsion-sterilization.ipynb

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@
109109
"cell_type": "markdown",
110110
"metadata": {},
111111
"source": [
112-
"### Exercise \n",
113-
"\n",
114-
"View a random sample of 5 rows to get a feel for the structure of the data."
112+
"**Exercise:** View a random sample of 5 rows to get a feel for the structure of the data."
115113
]
116114
},
117115
{
@@ -127,9 +125,7 @@
127125
"cell_type": "markdown",
128126
"metadata": {},
129127
"source": [
130-
"### Exercise \n",
131-
"\n",
132-
"To help you visualize what data are available and missing in the dataframe, run the cell below to get a visual matrix (using MissingNo). (By the way, be sure to make use of this awesome tool in your data analysis!)"
128+
"**Exercise:** To help you visualize what data are available and missing in the dataframe, run the cell below to get a visual matrix (using MissingNo). (By the way, be sure to make use of this awesome tool in your data analysis!)"
133129
]
134130
},
135131
{
@@ -146,9 +142,7 @@
146142
"cell_type": "markdown",
147143
"metadata": {},
148144
"source": [
149-
"#### Exercise \n",
150-
"\n",
151-
"Plot the average percentage reduction in colonies for each treatment."
145+
"**Exercise:** Plot the average percentage reduction in colonies for each treatment."
152146
]
153147
},
154148
{
@@ -167,9 +161,11 @@
167161
"source": [
168162
"### Step 3: Implement and Fit Model\n",
169163
"\n",
170-
"#### Exercise\n",
164+
"**Exercise:** Write the generative model for the data. \n",
165+
"\n",
166+
"To help you, this is a diagrammed version of the model below.\n",
171167
"\n",
172-
"Write the generative model for the data. "
168+
"![](../images/bacteria_model.jpg)"
173169
]
174170
},
175171
{
@@ -218,8 +214,6 @@
218214
"cell_type": "markdown",
219215
"metadata": {},
220216
"source": [
221-
"### Exercise\n",
222-
"\n",
223217
"Check the traces to make sure that sampling has converged."
224218
]
225219
},
@@ -237,20 +231,9 @@
237231
"cell_type": "markdown",
238232
"metadata": {},
239233
"source": [
240-
"### Exercise\n",
241-
"\n",
242234
"Visualize the posterior distributions of percentage reduction"
243235
]
244236
},
245-
{
246-
"cell_type": "code",
247-
"execution_count": null,
248-
"metadata": {},
249-
"outputs": [],
250-
"source": [
251-
"sorted(mapping)"
252-
]
253-
},
254237
{
255238
"cell_type": "code",
256239
"execution_count": null,
@@ -265,9 +248,7 @@
265248
"cell_type": "markdown",
266249
"metadata": {},
267250
"source": [
268-
"### Discussion\n",
269-
"\n",
270-
"Find a neighbour who is working on the same notebook, and discuss this together.\n",
251+
"**Discussion:** Find a neighbour who is working on the same notebook, and discuss this together.\n",
271252
"\n",
272253
"- Which method of sterilization is the most effective? \n",
273254
"- Given the data, is there any uncertainty surrounding this? Could we still be wrong about the uncertainty?"
@@ -283,17 +264,6 @@
283264
"- We estimate parameter of interest for each group, and then compare the parameter posterior distributions."
284265
]
285266
},
286-
{
287-
"cell_type": "markdown",
288-
"metadata": {},
289-
"source": [
290-
"# Hints\n",
291-
"\n",
292-
"A graphical version of one possible model implementation is provided below.\n",
293-
"\n",
294-
"![](../images/bacteria_model.jpg)"
295-
]
296-
},
297267
{
298268
"cell_type": "code",
299269
"execution_count": null,

0 commit comments

Comments
 (0)