{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  Compare samples using Smirnov test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example we are going to estimate whether two samples follow the same distribution using the Smirnov test."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generate 3 samples, sample1 and sample2 according the same distribution\n",
    "distribution1 = ot.Gumbel(5.5, 0.5)\n",
    "distribution2 = ot.Uniform()\n",
    "\n",
    "sample1 = distribution1.getSample(30)\n",
    "sample2 = distribution1.getSample(30)\n",
    "sample3 = distribution2.getSample(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Samples follow the same distribution? True p-value=0.135004 threshold=0.05\n"
     ]
    }
   ],
   "source": [
    "# Test sample1 against sample2\n",
    "test_result = ot.HypothesisTest.Smirnov(sample1, sample2)\n",
    "print('Samples follow the same distribution?', test_result.getBinaryQualityMeasure(),\n",
    "      'p-value=%.6g' % test_result.getPValue(),\n",
    "      'threshold=%.6g' % test_result.getThreshold())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Samples follow the same distribution? False p-value=1.27501e-06 threshold=0.05\n"
     ]
    }
   ],
   "source": [
    "# Test sample1 against sample3\n",
    "test_result = ot.HypothesisTest.Smirnov(sample1, sample3)\n",
    "print('Samples follow the same distribution?', test_result.getBinaryQualityMeasure(),\n",
    "      'p-value=%.6g' % test_result.getPValue(),\n",
    "      'threshold=%.6g' % test_result.getThreshold())"
   ]
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
