#### Note

:Pros: - Highly accurate\n - No additional computation complexity added\n - Not many assumptions of the data (only must be i.i.d.)\n - Has fast implementations (for ``indep_test=\"Dcorr\"`` and\n ``indep_test=\"Hsic\"``)\n :Cons: - Can be a little slower than some of the other tests in the package

\n\nThe ``indep_test`` parameter accepts a string corresponding to the name of the class\nin the :mod:`hyppo.independence`.\nOther parameters are those in the corresponding independence test.\nSince this this process is nearly the same for all independence tests, we are going\nto use :class:`hyppo.independence.MGC` as the example independence test.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from hyppo.ksample import KSample\nfrom hyppo.tools import rot_ksamp\n\n# 100 samples, 1D cubic independence simulation, 3 groups sim, 60 degree rotation, no\n# noise\nsims = rot_ksamp(\"linear\", n=100, p=1, k=3, degree=[60, -60], noise=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The data are points simulating a 1D linear relationship between random variables\n$X$ and $Y$. It the concatenates these two matrices, and then rotates\nthe simulation by 60 degrees, generating the second and, in this case, the third\nsample. It returns realizations as :class:`numpy.ndarray`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport seaborn as sns\n\n# make plots look pretty\nsns.set(color_codes=True, style=\"white\", context=\"talk\", font_scale=1)\n\n# look at the simulation\nplt.figure(figsize=(5, 5))\nfor sim in sims:\n plt.scatter(sim[:, 0], sim[:, 1])\nplt.xticks([])\nplt.yticks([])\nsns.despine(left=True, bottom=True, right=True)\nplt.show()\n\n# run k-sample test on the provided simulations. Note that *sims just unpacks the list\n# we got containing our simulated data\nstat, pvalue = KSample(indep_test=\"Dcorr\").test(*sims)\nprint(stat, pvalue)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This was a general use case for the test, but there are a number of intricacies that\ndepend on the type of independence test chosen. Those same parameters can be modified\nin this class. For a full list of the parameters, see the desired test in\n:mod:`hyppo.independence` and for examples on how to use it, see `indep`.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Distance (and Kernel) Equivalencies\n\nIt turns out that a number of test statistics are multiples of one another and so,\ntheir p-values are equivalent to the above `nonpar manova`. `[1]`_ goes through\nthe distance and kernel equivalencies and `[2]`_ goes through the independence and\ntwo-sample (and by extension `k`-sample) equivalences in far more detail.\n\n**Energy** is a powerful distance-based two sample test,\n**Distance components (DISCO)** is the `k`-sample analogue to Energy,\nand **Maximal mean discrepency (MMD)** is a powerful kernel-based two sample test,\nThese are equivalent to :class:`hyppo.ksample.KSample` using ``indep_test=\"Dcorr\"``\nfor Energy and DISCO and ``indep_test=\"Hsic\"`` for MMD.\nMore information can be found at :class:`hyppo.ksample.Energy`,\n:class:`hyppo.ksample.DISCO`, and\n:class:`hyppo.ksample.MMD`.\nHowever, the test statistics have been modified to make it more in tune with other\nimplementations.\n\n