From 3ab2279c65fdd6bcb9967028c09dc1475e14065e Mon Sep 17 00:00:00 2001
From: haesleinhuepf <rhaase@mpi-cbg.de>
Date: Tue, 23 Jun 2020 13:05:50 +0200
Subject: [PATCH] added another potential solution (which is not working)

---
 .../Otsu_Method_Comparison.ipynb              | 106 ++++++++++++++++--
 1 file changed, 95 insertions(+), 11 deletions(-)

diff --git a/11_Hypothesis_testing/exercise_otsu/Otsu_Method_Comparison.ipynb b/11_Hypothesis_testing/exercise_otsu/Otsu_Method_Comparison.ipynb
index 73e1e95..025f5e6 100644
--- a/11_Hypothesis_testing/exercise_otsu/Otsu_Method_Comparison.ipynb
+++ b/11_Hypothesis_testing/exercise_otsu/Otsu_Method_Comparison.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [
     {
@@ -88,7 +88,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [
     {
@@ -123,7 +123,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [
     {
@@ -174,7 +174,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [
     {
@@ -209,7 +209,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -234,7 +234,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [
     {
@@ -265,7 +265,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 7,
    "metadata": {},
    "outputs": [
     {
@@ -292,7 +292,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 41,
+   "execution_count": 8,
    "metadata": {},
    "outputs": [
     {
@@ -303,7 +303,7 @@
        " (-0.0743754713943518, 0.47051036223078757, 48.0))"
       ]
      },
-     "execution_count": 41,
+     "execution_count": 8,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -318,7 +318,91 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 40,
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# source: https://gist.github.com/josef-pkt/3900314\n",
+    "\n",
+    "'''Test of Equivalence and Non-Inferiority\n",
+    "currently only TOST for paired sample\n",
+    "Application for example bioequivalence\n",
+    "Author: Josef Perktold\n",
+    "License: BSD-3\n",
+    "'''\n",
+    "\n",
+    "\n",
+    "import numpy as np\n",
+    "from scipy import stats\n",
+    "\n",
+    "def tost_paired(y, x, low, upp, transform=None):\n",
+    "    '''test of (non-)equivalence for paired sample\n",
+    "    TOST: two one-sided t tests\n",
+    "    null hypothesis  x - y < low or x - y > upp\n",
+    "    alternative hypothesis:  low < x - y < upp\n",
+    "    If the pvalue is smaller than a threshold, then we reject the hypothesis\n",
+    "    that there is difference between the two samples larger than the one\n",
+    "    given by low and upp.\n",
+    "    Parameters\n",
+    "    ----------\n",
+    "    y, x : array_like\n",
+    "        two paired samples\n",
+    "    low, upp : float\n",
+    "        equivalence interval low < x - y < upp\n",
+    "    transform : None or function\n",
+    "        If None (default), then the data is not transformed. Given a function\n",
+    "        sample data and thresholds are transformed. If transform is log the\n",
+    "        the equivalence interval is in ratio: low < x / y < upp\n",
+    "    Returns\n",
+    "    -------\n",
+    "    pvalue : float\n",
+    "        pvalue of the non-equivalence test\n",
+    "    t1, pv1 : tuple of floats\n",
+    "        test statistic and pvalue for lower threshold test\n",
+    "    t2, pv2 : tuple of floats\n",
+    "        test statistic and pvalue for upper threshold test\n",
+    "    Notes\n",
+    "    -----\n",
+    "    tested on only one example\n",
+    "    uses stats.ttest_1samp which doesn't have a real one-sided option\n",
+    "    '''\n",
+    "    if transform:\n",
+    "        y = transform(y)\n",
+    "        x = transform(x)\n",
+    "        low = transform(low)\n",
+    "        upp = transform(upp)\n",
+    "    t1, pv1 = stats.ttest_1samp(x - y, low)\n",
+    "    t2, pv2 = stats.ttest_1samp(x - y, upp)\n",
+    "    return max(pv1, pv2)/2., (t1, pv1 / 2.), (t2, pv2 / 2.)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(3.0607159809231846e-11,\n",
+       " (-11.104032129950907, 3.0607159809231846e-11),\n",
+       " (-12.32257205021279, 3.601584280854005e-12))"
+      ]
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "tolerance = 0.1\n",
+    "\n",
+    "tost_paired(measurement_python, measurement_imagej, -tolerance, tolerance)\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
    "metadata": {},
    "outputs": [
     {
@@ -336,7 +420,7 @@
        " [72.64029810317597, 1.19906617345889e-29]]"
       ]
      },
-     "execution_count": 40,
+     "execution_count": 11,
      "metadata": {},
      "output_type": "execute_result"
     }
-- 
GitLab