-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,355 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Practice Exercises 6: Examining the Therapeutic Touch\n", | ||
"\n", | ||
"Welcome to Practice Exercises 6!\n", | ||
"\n", | ||
"After such an extensive introduction to programming for data science, we are finally moving into the section of the course where we can apply our new skils to answer real questions. \n", | ||
"\n", | ||
"With the following practice exercises, we'll use testing techniques that were introduced in lecture to test the idea of the therapeutic touch, the idea that some practictioners can feel and massage your human energy field. \n", | ||
"\n", | ||
"Remember, practice exercises are *not* required and will not be turned in for credit...but they are helpful for developing your YData skills!\n", | ||
"\n", | ||
"Credit: These practice exercises have been adapted from Berkeley's Data8 course.\n", | ||
"\n", | ||
"Let's begin by running the cell below." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Run this cell, but please don't change it.\n", | ||
"\n", | ||
"# These lines import the Numpy and Datascience modules.\n", | ||
"import numpy as np\n", | ||
"from datascience import *\n", | ||
"\n", | ||
"# These lines do some fancy plotting magic\n", | ||
"import matplotlib\n", | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"plt.style.use('fivethirtyeight')\n", | ||
"import warnings\n", | ||
"warnings.simplefilter('ignore', FutureWarning)\n", | ||
"from matplotlib import patches\n", | ||
"from ipywidgets import interact, interactive, fixed\n", | ||
"import ipywidgets as widgets" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### What is the Therapeutic Touch\n", | ||
"\n", | ||
"The Therapeutic Touch (TT) is the idea that everyone can feel the Human Energy Field (HEF) around individuals. Certain practictioners claim they have the ability to feel the HEF and can massage it in order to promote health and relaxation in individuals. Those who practice TT have described different people's HEFs as \"warm as Jell-O\" and \"tactile as taffy\". \n", | ||
"\n", | ||
"TT was a popular technique used throughout the 20th century that was toted to be a great way to bring balance to a person's health. \n", | ||
"\n", | ||
"### Emily Rosa\n", | ||
"\n", | ||
"Emily Rosa was a 4th grade student who had wide exposure to the world of TT due to her parents. Her parents were both medical practitioners and skeptics of the idea of TT. \n", | ||
"\n", | ||
"For her 4th grade science fair project, Emily decided to test whether or not TT practitioners could truly interact with a person's HEF. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 1:** Discuss with others in the class (and on Ed Discussions), how you would set up an experiment to test this." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"*Write your answer here, replacing this text.*" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Emily's Experiment\n", | ||
"\n", | ||
"Emily's experiment was clean, simple, and effective. Due to her parents' occupations in the medical field, she had wide access to people who claimed to be TT practitioners. \n", | ||
"\n", | ||
"Emily took 21 TT practitioners and used them for her science experiment. She would take a TT practitioner and ask them to extend their hands through a screen (through which they can't see). Emily would be on the other side and would flip a coin. Depending on how the coin landed, she would put out either her left hand or her right hand. The TT practitioner would then have to correctly answer which hand Emily put out. Overall, through 210 samples, the practitioner picked the correct hand 44% of the time. \n", | ||
"\n", | ||
"Emily's main goal here was to test whether or not the TT practicioners' guesses were random, like the flip of a coin. In most medical experiments, this is the norm. We want to test whether or not the treatment has an effect, *not* whether or not the treatment actually works. \n", | ||
"\n", | ||
"We will now begin to formulate this experiment in terms of the terminology we learned in this course. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 2**: What are the null and alternative hypothesis for Emily's experiment? For the alternative hypothesis, assume that if a TT practicioner consistently reports the incorrect hand, this is also evidence that they can feel the HEF, but that there is a mistake in how the TT practicioner is reporting the results (i.e., they accidentally say left, when they mean to say right, and vice versa). " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"for_assignment_type": "student" | ||
}, | ||
"source": [ | ||
"**Your Answer Here:**\n", | ||
"\n", | ||
"Null Hypothesis: \n", | ||
"\n", | ||
"Alternative Hypothesis: " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 3:** Remember that the practitioner got the correct answer 44% of the time. According to the null hypothesis, on average, what proportion of times do we expect the practitioner to guess the correct hand? Make sure your answer is between 0 and 1. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"expected_correct = ...\n", | ||
"expected_correct" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The goal now is to see if our deviation from this expected proportion of correct answers is due to something other than chance. \n", | ||
"\n", | ||
"**Question 4:** What is a valid test statistic we can use to test our model? Assign `valid_ts` to a list of integers representing the following options: \n", | ||
"\n", | ||
"1. The difference of the expected percent correct and the actual percent correct\n", | ||
"2. The absolute difference of the expected percent correct and the actual percent correct\n", | ||
"3. The sum of the expected percent correct and the actual percent correct\n", | ||
"\n", | ||
"There may be more than one correct answer. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"valid_ts = ...\n", | ||
"valid_ts" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 5:** Define the function `test_statistic` which takes in an expected proportion and an actual proportion, and returns the value of the test statistic chosen above. Assume that you are taking in proportions, but you want to return your answer as a percentage. \n", | ||
"\n", | ||
"*Hint:* Remember we are asking for a **percentage**, not a proportion. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def test_statistic(expected_prop, actual_prop):\n", | ||
" ...\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 6:** Use your newly defined function to calculate the observed test statistic from Emily's experiment. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"observed_test_statistic = ...\n", | ||
"observed_test_statistic" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Is this test statistic likely if the null hypothesis was true? Or is the deviation from the expected proportion due to something other than chance?**\n", | ||
"\n", | ||
"In order to answer this question, we can simulate the experiment as though the null hypothesis was true, and calculate the test statistic per each simulation.\n", | ||
"\n", | ||
"**Question 7:** To begin simulating, we should start by creating an array which has two items in it. The first item should be the proportion of times, assuming the null model is true, a TT practictioner picks the correct hand. The second item should be the proportion of times, under the same assumption, that the TT practicioner picks the incorrect hand. Assign `model_proportions` to this array. After this, simulate, using the `sample_proportions` function, Emily running through this experiment 210 times (as done in real life), and assign the proportion of correct answers to `simulation_proportion`. Lastly, define `one_test_statistic` to the test statistic of this one simulation. \n", | ||
"\n", | ||
"*Hint:* `sample_proportions` usage can be found [here](http://data8.org/sp18/python-reference.html)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model_proportions = ...\n", | ||
"simulation_proportion = ...\n", | ||
"one_test_statistic = ...\n", | ||
"one_test_statistic" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 8:** Let's now see what the distribution of test statistics is actually like under our fully specified model. Assign `simulated_test_statistics` to an array of 1000 test statistics that you simulated assuming the null hypothesis is true. \n", | ||
"\n", | ||
"*Hint:* This should follow the same pattern as normal simulations, in combination with the code you did in the previous problem. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"for_assignment_type": "student", | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"num_repetitions = 1000\n", | ||
"num_guesses = 210\n", | ||
"\n", | ||
"simulated_test_statistics = ...\n", | ||
"\n", | ||
"for ... in ...:\n", | ||
" ...\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's view the distribution of the simulated test statistics under the null, and visually compare how the observed test statistic lies against the rest. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"t = Table().with_column('Simulated Test Statistics', simulated_test_statistics)\n", | ||
"t.hist()\n", | ||
"plt.scatter(observed_test_statistic, 0, color='red', s=30)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can make a visual argument as to whether or not we believe the observed test statistic is likely to occur under the null, or we can use the definition of p-values to help us make a more formal argument. \n", | ||
"\n", | ||
"**Question 9:** Assign `p_value` to the integer corresponding to the correct definition of what a p-value really is. \n", | ||
"\n", | ||
"1. The probability, under the null hypothesis, that the test statistic is equal to the value that was observed\n", | ||
"2. The probability, under the null hypothesis, that the test statistic is equal to the value that was observed or is even further in the direction of the alternative\n", | ||
"3. Theprobability, under the alternative hypothesis, that the test statistic is equal to the value that was observed or is even further in the direction of the null \n", | ||
"4. The number of times, under the null hypothesis, that the test statistic is equal to the value that was observed or is even further in the direction of the alternative" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"p_value = ...\n", | ||
"p_value" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Question 10:** Using the definition above, calculate the p-value of Emily's observed value in this experiment. \n", | ||
"\n", | ||
"*Hint:* If our test statistic is further in the direction of the alternative, will larger value or a smaller value? \n", | ||
"\n", | ||
"*Hint:* [This section](https://www.inferentialthinking.com/chapters/11/3/decisions-and-uncertainty) of the textbook contains an example of calculating an empirical p-value." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"emily_p_val = ...\n", | ||
"emily_p_val" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If our p-value is less than or equal to .05, then this is in favor of our alternative and we reject the null hypothesis. Otherwise, we do not have enough evidence against our null hypothesis. Note that this does **not** say we side in favor with the null hypothesis and accept it, but rather, that we just fail to reject it. \n", | ||
"\n", | ||
"This should help you make your own conclusions about Emily Rosa's experiment. \n", | ||
"\n", | ||
"Think about the following questions: \n", | ||
"\n", | ||
"1. Do we reject the null hypothesis, or fail to reject it? \n", | ||
"2. What does this mean in terms of Emily's experiment? Do the TT practitioners' answers follow an even chance model or is there something else at play? " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"*Put your reponse here*" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Note: Therapeutic touch fell out of use after this experiment, which was eventually accepted into one of the premier medical journals. TT practitioners hit back and accused Emily and her family of tampering with the results, while some claimed that Emily's bad spiritual mood towards therapeutic touch made it difficult to read her HEF. Whatever it may be, Emily's experiment is a classic example about how anyone, with the right resources, can test anything they want!" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |