class: center, middle, inverse, title-slide # Hypothesis Testing ## NEUS 643 ### Ted Laderas ### 2020-05-19 --- # Learning Objectives - Understand the steps of hypothesis testing - Understand that hypothesis testing specifies a null hypothesis - Understand the importance of the *null hypothesis* in generating the null distribution - Apply *shuffling* to permute the null distribution - Interpret the p-value under permutations --- <img src="image/week7/stats_help.jpg" width=800> --- # How Special is our Data? How special is our data compared to fake data generated under the *null hypothesis*? --- ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-2-1.png)<!-- --> --- # Why Hypothesis Test? - Given our observed sample, assess whether we can make an inference about the real value given: - Limited sample size - Small Effect size - What kind of inference? Are we comfortable with our results compared to randomly generated data? --- # Hypothesis Test - Test between a *null* and *alternative* hypothesis - Alternative hypothesis (Ha) - What we're interested in - Null Hypothesis (Ho) - what we expect from just chance and noise --- # Steps in Hypothesis Testing 1. Define Test Statistic 2. Specify alternative hypothesis with test statistic 3. Use alternative hypothesis to specify null hypothesis 4. Decide on a significance level 5. Calculate observed test statstic 6. Permute Data and generate distribution 7. Calculate p-value 8. Interpret! - ??? Adapted from https://www.nedarc.org/statisticalHelp/advancedStatisticalTopics/hypothesisTesting.html --- # Our Test Statistic - Difference between means of the two groups - `bc` and `nuc` --- <img src="image/week7/stating_null.jpg" width=800> --- <img src="image/week7/why_null.jpg" width=800> --- <img src="image/week7/theoretical_null.JPG" width=800> --- # Empirical versus Theoretical - Theoretical distributions rely on assumptions - Normality is a big one! - Empirical distributions utilize data --- <img src="image/week7/observed_calc.JPG" width=800> --- <img src="image/week7/null_permute.JPG" width=800> --- <img src="image/week7/null_permute2.JPG" width=800> --- <img src="image/week7/p_permute.JPG" width=800> --- <img src="image/week7/p_value_significance.JPG" width=800> --- class: center, middle # Real Life Example --- # Our Data .pull-left[ First few rows of table
type
x_0_s_area
bc
770
bc
747
bc
939
bc
1144
bc
1210
bc
1225
] .pull-right[ Counts in each group ``` ## type n percent ## bc 1153 0.5070361 ## nucleus 1121 0.4929639 ``` ] --- # Difference between means in data .pull-left[ We observe a difference in mean area of 19.713712 pixels between the `bc` and `nuc` groups ] .pull-right[ ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-6-1.png)<!-- --> ] --- --- # A couple permutations .pull-left[
type
x_0_s_area
run
bc
770
1
nucleus
747
1
nucleus
939
1
bc
1144
1
bc
1210
1
] .pull-right[
type
x_0_s_area
run
nucleus
770
4
bc
747
4
bc
939
4
bc
1144
4
bc
1210
4
] --- # Calculate and plot our Observed Statistic ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-10-1.png)<!-- --> --- # Generate statistics from permuted data ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-11-1.png)<!-- --> --- # 100 Permutations ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-12-1.png)<!-- --> --- # 1000 Permutations ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-13-1.png)<!-- --> --- # P-Value .pull-left[ We observe 13 permuted data sets under the null distirbution have a mean difference of 19.713712 or higher. Our p-value is 13 / 1000 = 0.013 ] .pull-right[ ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-14-1.png)<!-- --> ] --- # A Smaller Data Set ``` ## type n percent ## bc 13 0.4333333 ## nucleus 17 0.5666667 ``` --- ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-16-1.png)<!-- --> ``` ## [1] 404 ``` --- ## Bigger Difference, Smaller n .pull-left[ We observe 404 permuted data sets under the null distribution have a mean difference of 19.713712 or higher. Our p-value is 404 / 1000 = 0.404 ] .pull-right[ ![](08_hypothesis_testing_files/figure-html/unnamed-chunk-18-1.png)<!-- --> ] --- # There is One Test <img src="image/week7/1_test.png" width=800> --- # Next Time - Lab: Colocalization analysis using correlation --- # Reading - [There's still only one test](http://allendowney.blogspot.com/2016/06/there-is-still-only-one-test.html) - [The Permutation Test, by Jared Wilber](https://www.jwilber.me/permutationtest/) - [A practical guide to evaluating colocalization in biological microscopy](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3074624/)