Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active June 13, 2022 04:05
Show Gist options
  • Save taruma/5d16baf90016d8a08c6870b674226691 to your computer and use it in GitHub Desktop.
Save taruma/5d16baf90016d8a08c6870b674226691 to your computer and use it in GitHub Desktop.
taruma_hk140_kolmogorov_smirnov.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk140_kolmogorov_smirnov.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyO1B9x1+Ro6OfWlMFlchXCh",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/taruma/5d16baf90016d8a08c6870b674226691/taruma_hk140_kolmogorov_smirnov.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Berdasarkan isu [#140](https://github.com/hidrokit/hidrokit/issues/140): **Uji Kolmogorov-Smirnov**\n",
"\n",
"Referensi Isu:\n",
"- Soetopo, W., Montarcih, L., Press, U. B., & Media, U. (2017). Rekayasa Statistika untuk Teknik Pengairan. Universitas Brawijaya Press. https://books.google.co.id/books?id=TzVTDwAAQBAJ\n",
"- Soewarno. (1995). hidrologi: Aplikasi Metode Statistik untuk Analisa Data. NOVA.\n",
"- Limantara, L. (2018). Rekayasa Hidrologi.\n",
"\n",
"Deskripsi Isu:\n",
"- Melakukan Uji Kecocokan Distribusi menggunakan Uji Kolmogorov-Smirnov.\n",
"\n",
"Strategi:\n",
"- Membuat fungsi _inverse_ atau CDF untuk masing-masing distribusi yang digunakan. (sudah diselesaikan pada isu [#179](https://github.com/hidrokit/hidrokit/issues/179))\n",
"- Tidak dibandingkan dengan fungsi `scipy.stats.kstest`."
],
"metadata": {
"id": "vTbvS7mlWHT_"
}
},
{
"cell_type": "markdown",
"source": [
"# PERSIAPAN DAN DATASET"
],
"metadata": {
"id": "wKVU8TNyWYCw"
}
},
{
"cell_type": "code",
"source": [
"try:\n",
" import hidrokit\n",
"except ModuleNotFoundError:\n",
" # saat dibuat menggunakan cabang @dev/dev0.3.7\n",
" !pip install git+https://github.com/taruma/hidrokit.git@latest -q"
],
"metadata": {
"id": "ADlBvxJ1SC5O",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "d448b121-c709-4fd3-e2fe-a6a93c1bdbfd"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" Building wheel for hidrokit (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
]
}
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "BF91rLR2V2xt"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from scipy import stats\n",
"from hidrokit.contrib.taruma import hk172, hk124, hk127, hk126 \n",
"\n",
"frek_normal, frek_lognormal, frek_gumbel, frek_logpearson3 = hk172, hk124, hk127, hk126"
]
},
{
"cell_type": "code",
"source": [
"# contoh data diambil dari buku\n",
"# limantara hal. 114\n",
"\n",
"_HUJAN = np.array([85, 92, 115, 116, 122, 52, 69, 95, 96, 105])\n",
"_TAHUN = np.arange(1998, 2008) # 1998-2007\n",
"\n",
"data = pd.DataFrame(\n",
" data=np.stack([_TAHUN, _HUJAN], axis=1),\n",
" columns=['tahun', 'hujan']\n",
")\n",
"data.tahun = pd.to_datetime(data.tahun, format='%Y')\n",
"data.set_index('tahun', inplace=True)\n",
"data"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 394
},
"id": "jfL0hzvtqfem",
"outputId": "e5b1985a-bfc6-4be5-b0c4-74a0cc538074"
},
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" hujan\n",
"tahun \n",
"1998-01-01 85\n",
"1999-01-01 92\n",
"2000-01-01 115\n",
"2001-01-01 116\n",
"2002-01-01 122\n",
"2003-01-01 52\n",
"2004-01-01 69\n",
"2005-01-01 95\n",
"2006-01-01 96\n",
"2007-01-01 105"
],
"text/html": [
"\n",
" <div id=\"df-24bd3373-7bf3-45d6-8335-8df34a7d3e9c\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>hujan</th>\n",
" </tr>\n",
" <tr>\n",
" <th>tahun</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1998-01-01</th>\n",
" <td>85</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1999-01-01</th>\n",
" <td>92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01</th>\n",
" <td>115</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01</th>\n",
" <td>116</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>122</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2003-01-01</th>\n",
" <td>52</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004-01-01</th>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005-01-01</th>\n",
" <td>95</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-01</th>\n",
" <td>96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007-01-01</th>\n",
" <td>105</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-24bd3373-7bf3-45d6-8335-8df34a7d3e9c')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-24bd3373-7bf3-45d6-8335-8df34a7d3e9c button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-24bd3373-7bf3-45d6-8335-8df34a7d3e9c');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 5
}
]
},
{
"cell_type": "markdown",
"source": [
"# TABEL\n",
"\n",
"Terdapat 2 tabel untuk modul `hk140` yaitu:\n",
"- `t_dcr_st`: Tabel nilai kritis (Dcr) Untuk Uji Kolmogorov-Smirnov dari buku _Rekayasa Statistika untuk Teknik Pengairan_ oleh Soetopo.\n",
"- `t_dcr_sw`: Tabel nilai kritis Do Untuk Uji Smirnov-Kolmogorov dari buku _hidrologi: Aplikasi Metode Statistik untuk Analisa Data_ oleh Soewarno.\n",
"\n",
"Dalam modul `hk126` nilai $\\Delta_{kritis}$ akan dibangkitkan menggunakan fungsi `scipy.stats.ksone.ppf` secara `default`. Mohon diperhatikan jika ingin menggunakan nilai $\\Delta_{kritis}$ yang berasal dari sumber lain. "
],
"metadata": {
"id": "pn3l9uqhlwOs"
}
},
{
"cell_type": "code",
"source": [
"# tabel dari soetopo hal. 139\n",
"# Tabel Nilai Kritis (Dcr) Untuk Uji Kolmogorov-Smirnov\n",
"\n",
"# KODE: ST\n",
"\n",
"_DATA_ST = [\n",
" [0.900, 0.925, 0.950, 0.975, 0.995],\n",
" [0.684, 0.726, 0.776, 0.842, 0.929],\n",
" [0.565, 0.597, 0.642, 0.708, 0.829],\n",
" [0.494, 0.525, 0.564, 0.624, 0.734],\n",
" [0.446, 0.474, 0.510, 0.563, 0.669],\n",
" [0.410, 0.436, 0.470, 0.521, 0.618],\n",
" [0.381, 0.405, 0.438, 0.486, 0.577],\n",
" [0.358, 0.381, 0.411, 0.457, 0.543],\n",
" [0.339, 0.360, 0.388, 0.432, 0.514],\n",
" [0.322, 0.342, 0.368, 0.409, 0.486],\n",
" [0.307, 0.326, 0.352, 0.391, 0.468],\n",
" [0.295, 0.313, 0.338, 0.375, 0.450],\n",
" [0.284, 0.302, 0.325, 0.361, 0.433],\n",
" [0.274, 0.292, 0.314, 0.349, 0.418],\n",
" [0.266, 0.283, 0.304, 0.338, 0.404],\n",
" [0.258, 0.274, 0.295, 0.328, 0.391],\n",
" [0.250, 0.266, 0.286, 0.318, 0.380],\n",
" [0.244, 0.259, 0.278, 0.309, 0.370],\n",
" [0.237, 0.252, 0.272, 0.301, 0.361],\n",
" [0.231, 0.246, 0.264, 0.294, 0.352],\n",
"]\n",
"\n",
"_INDEX_ST = range(1, 21)\n",
"\n",
"_COL_ST = [0.2, 0.15, 0.1, 0.05, 0.01]\n",
"\n",
"t_dcr_st = pd.DataFrame(\n",
" data=_DATA_ST, index=_INDEX_ST, columns=_COL_ST\n",
")\n",
"t_dcr_st"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 676
},
"id": "bYkR_ZhZU9um",
"outputId": "e7c825e7-9740-4c43-efb7-78e404c02e49"
},
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 0.20 0.15 0.10 0.05 0.01\n",
"1 0.900 0.925 0.950 0.975 0.995\n",
"2 0.684 0.726 0.776 0.842 0.929\n",
"3 0.565 0.597 0.642 0.708 0.829\n",
"4 0.494 0.525 0.564 0.624 0.734\n",
"5 0.446 0.474 0.510 0.563 0.669\n",
"6 0.410 0.436 0.470 0.521 0.618\n",
"7 0.381 0.405 0.438 0.486 0.577\n",
"8 0.358 0.381 0.411 0.457 0.543\n",
"9 0.339 0.360 0.388 0.432 0.514\n",
"10 0.322 0.342 0.368 0.409 0.486\n",
"11 0.307 0.326 0.352 0.391 0.468\n",
"12 0.295 0.313 0.338 0.375 0.450\n",
"13 0.284 0.302 0.325 0.361 0.433\n",
"14 0.274 0.292 0.314 0.349 0.418\n",
"15 0.266 0.283 0.304 0.338 0.404\n",
"16 0.258 0.274 0.295 0.328 0.391\n",
"17 0.250 0.266 0.286 0.318 0.380\n",
"18 0.244 0.259 0.278 0.309 0.370\n",
"19 0.237 0.252 0.272 0.301 0.361\n",
"20 0.231 0.246 0.264 0.294 0.352"
],
"text/html": [
"\n",
" <div id=\"df-498b088b-2368-4699-81e0-c717ff2eccd7\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0.20</th>\n",
" <th>0.15</th>\n",
" <th>0.10</th>\n",
" <th>0.05</th>\n",
" <th>0.01</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.900</td>\n",
" <td>0.925</td>\n",
" <td>0.950</td>\n",
" <td>0.975</td>\n",
" <td>0.995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.684</td>\n",
" <td>0.726</td>\n",
" <td>0.776</td>\n",
" <td>0.842</td>\n",
" <td>0.929</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.565</td>\n",
" <td>0.597</td>\n",
" <td>0.642</td>\n",
" <td>0.708</td>\n",
" <td>0.829</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.494</td>\n",
" <td>0.525</td>\n",
" <td>0.564</td>\n",
" <td>0.624</td>\n",
" <td>0.734</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.446</td>\n",
" <td>0.474</td>\n",
" <td>0.510</td>\n",
" <td>0.563</td>\n",
" <td>0.669</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.410</td>\n",
" <td>0.436</td>\n",
" <td>0.470</td>\n",
" <td>0.521</td>\n",
" <td>0.618</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>0.381</td>\n",
" <td>0.405</td>\n",
" <td>0.438</td>\n",
" <td>0.486</td>\n",
" <td>0.577</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>0.358</td>\n",
" <td>0.381</td>\n",
" <td>0.411</td>\n",
" <td>0.457</td>\n",
" <td>0.543</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0.339</td>\n",
" <td>0.360</td>\n",
" <td>0.388</td>\n",
" <td>0.432</td>\n",
" <td>0.514</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>0.322</td>\n",
" <td>0.342</td>\n",
" <td>0.368</td>\n",
" <td>0.409</td>\n",
" <td>0.486</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>0.307</td>\n",
" <td>0.326</td>\n",
" <td>0.352</td>\n",
" <td>0.391</td>\n",
" <td>0.468</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>0.295</td>\n",
" <td>0.313</td>\n",
" <td>0.338</td>\n",
" <td>0.375</td>\n",
" <td>0.450</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>0.284</td>\n",
" <td>0.302</td>\n",
" <td>0.325</td>\n",
" <td>0.361</td>\n",
" <td>0.433</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>0.274</td>\n",
" <td>0.292</td>\n",
" <td>0.314</td>\n",
" <td>0.349</td>\n",
" <td>0.418</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>0.266</td>\n",
" <td>0.283</td>\n",
" <td>0.304</td>\n",
" <td>0.338</td>\n",
" <td>0.404</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>0.258</td>\n",
" <td>0.274</td>\n",
" <td>0.295</td>\n",
" <td>0.328</td>\n",
" <td>0.391</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>0.250</td>\n",
" <td>0.266</td>\n",
" <td>0.286</td>\n",
" <td>0.318</td>\n",
" <td>0.380</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>0.244</td>\n",
" <td>0.259</td>\n",
" <td>0.278</td>\n",
" <td>0.309</td>\n",
" <td>0.370</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>0.237</td>\n",
" <td>0.252</td>\n",
" <td>0.272</td>\n",
" <td>0.301</td>\n",
" <td>0.361</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>0.231</td>\n",
" <td>0.246</td>\n",
" <td>0.264</td>\n",
" <td>0.294</td>\n",
" <td>0.352</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-498b088b-2368-4699-81e0-c717ff2eccd7')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-498b088b-2368-4699-81e0-c717ff2eccd7 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-498b088b-2368-4699-81e0-c717ff2eccd7');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "code",
"source": [
"# tabel dari soewarno hal. 139\n",
"# Tabel Nilai Kritis (Dcr) Untuk Uji Kolmogorov-Smirnov\n",
"\n",
"# KODE: SW\n",
"\n",
"_DATA_SW = [\n",
" [0.45, 0.51, 0.56, 0.67],\n",
" [0.32, 0.37, 0.41, 0.49],\n",
" [0.27, 0.3 , 0.34, 0.4 ],\n",
" [0.23, 0.26, 0.29, 0.35],\n",
" [0.21, 0.24, 0.26, 0.32],\n",
" [0.19, 0.22, 0.24, 0.29],\n",
" [0.18, 0.2 , 0.22, 0.27],\n",
" [0.17, 0.19, 0.21, 0.25],\n",
" [0.16, 0.18, 0.2 , 0.24],\n",
" [0.15, 0.17, 0.19, 0.23]\n",
"]\n",
"\n",
"_INDEX_SW = range(5, 51, 5)\n",
"\n",
"_COL_SW = [0.2, 0.1, 0.05, 0.01]\n",
"\n",
"t_dcr_sw = pd.DataFrame(\n",
" data=_DATA_SW, index=_INDEX_SW, columns=_COL_SW\n",
")\n",
"t_dcr_sw"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 363
},
"id": "XuNz6_5dmRxr",
"outputId": "aa494073-466c-4370-bb0b-3402cfc5e126"
},
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 0.20 0.10 0.05 0.01\n",
"5 0.45 0.51 0.56 0.67\n",
"10 0.32 0.37 0.41 0.49\n",
"15 0.27 0.30 0.34 0.40\n",
"20 0.23 0.26 0.29 0.35\n",
"25 0.21 0.24 0.26 0.32\n",
"30 0.19 0.22 0.24 0.29\n",
"35 0.18 0.20 0.22 0.27\n",
"40 0.17 0.19 0.21 0.25\n",
"45 0.16 0.18 0.20 0.24\n",
"50 0.15 0.17 0.19 0.23"
],
"text/html": [
"\n",
" <div id=\"df-9a4a30ef-2d12-4191-bf7f-05ef1c44decd\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0.20</th>\n",
" <th>0.10</th>\n",
" <th>0.05</th>\n",
" <th>0.01</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.45</td>\n",
" <td>0.51</td>\n",
" <td>0.56</td>\n",
" <td>0.67</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>0.32</td>\n",
" <td>0.37</td>\n",
" <td>0.41</td>\n",
" <td>0.49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>0.27</td>\n",
" <td>0.30</td>\n",
" <td>0.34</td>\n",
" <td>0.40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>0.23</td>\n",
" <td>0.26</td>\n",
" <td>0.29</td>\n",
" <td>0.35</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>0.21</td>\n",
" <td>0.24</td>\n",
" <td>0.26</td>\n",
" <td>0.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>0.19</td>\n",
" <td>0.22</td>\n",
" <td>0.24</td>\n",
" <td>0.29</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>0.18</td>\n",
" <td>0.20</td>\n",
" <td>0.22</td>\n",
" <td>0.27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>0.17</td>\n",
" <td>0.19</td>\n",
" <td>0.21</td>\n",
" <td>0.25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>0.16</td>\n",
" <td>0.18</td>\n",
" <td>0.20</td>\n",
" <td>0.24</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>0.15</td>\n",
" <td>0.17</td>\n",
" <td>0.19</td>\n",
" <td>0.23</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9a4a30ef-2d12-4191-bf7f-05ef1c44decd')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-9a4a30ef-2d12-4191-bf7f-05ef1c44decd button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-9a4a30ef-2d12-4191-bf7f-05ef1c44decd');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "markdown",
"source": [
"# KODE"
],
"metadata": {
"id": "6idc0EuZYb_B"
}
},
{
"cell_type": "code",
"source": [
"# KODE FUNGSI INTERPOLASI DARI TABEL\n",
"\n",
"from scipy import interpolate\n",
"\n",
"def _func_interp_bivariate(df):\n",
" \"Membuat fungsi dari tabel untuk interpolasi bilinear\"\n",
" table = df[df.columns.sort_values()].sort_index().copy()\n",
"\n",
" x = table.index\n",
" y = table.columns\n",
" z = table.to_numpy()\n",
"\n",
" # penggunaan kx=1, ky=1 untuk interpolasi linear antara 2 titik\n",
" # tidak menggunakan (cubic) spline interpolation\n",
" return interpolate.RectBivariateSpline(x, y, z, kx=1, ky=1)\n",
"\n",
"def _as_value(x, dec=4):\n",
" x = np.around(x, dec)\n",
" return x.flatten() if x.size > 1 else x.item()\n",
"\n",
"def _calc_k(x):\n",
" return (x - x.mean()) / x.std()"
],
"metadata": {
"id": "LEj79zOznHKJ"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"source": [
"table_source = {\n",
" 'soewarno': t_dcr_sw,\n",
" 'soetopo': t_dcr_st\n",
"}\n",
"\n",
"anfrek = {\n",
" 'normal': frek_normal,\n",
" 'lognormal': frek_lognormal,\n",
" 'gumbel': frek_gumbel,\n",
" 'logpearson3': frek_logpearson3\n",
"}\n",
"\n",
"def calc_dcr(alpha, n, source='scipy'):\n",
" alpha = np.array(alpha)\n",
" if source.lower() == 'scipy':\n",
" # ref: https://stackoverflow.com/questions/53509986/\n",
" return stats.ksone.ppf(1-alpha/2, n)\n",
" elif source.lower() in table_source.keys():\n",
" func_table = _func_interp_bivariate(table_source[source.lower()])\n",
" # untuk soewarno 2 angka dibelakang koma, dan soetopo = 3\n",
" dec = (source.lower() == 'soetopo') + 2\n",
" return _as_value(func_table(n, alpha, grid=False), dec)\n",
"\n",
"def kstest(\n",
" df, col=None, dist='normal', source_dist=None, \n",
" alpha=0.05, source_dcr='scipy', show_stat=True, report='result'\n",
" ):\n",
"\n",
" if source_dist is None:\n",
" source_dist = (\n",
" \"scipy\"\n",
" if dist.lower() in [\"normal\", \"lognormal\", \"logpearson3\"]\n",
" else \"gumbel\"\n",
" )\n",
"\n",
" col = df.columns[0] if col is None else col\n",
" data = df[[col]].copy()\n",
" n = len(data)\n",
" data = data.rename({col: 'x'}, axis=1)\n",
" data = data.sort_values('x')\n",
" data['no'] = np.arange(n) + 1\n",
"\n",
" # w = weibull\n",
" data['p_w'] = data.no / (n+1)\n",
" \n",
" if dist.lower() in ['normal', 'gumbel']:\n",
" data['k'] = _calc_k(data.x)\n",
" if dist.lower() in ['lognormal', 'logpearson3']:\n",
" data['log_x'] = np.log10(data.x)\n",
" data['k'] = _calc_k(data.log_x)\n",
"\n",
" func = anfrek[dist.lower()]\n",
"\n",
" if dist.lower() in ['normal', 'lognormal']:\n",
" parameter = ()\n",
" elif dist.lower() == 'gumbel':\n",
" parameter = (n,)\n",
" elif dist.lower() == 'logpearson3':\n",
" parameter = (data.log_x.skew(),)\n",
" \n",
" # d = distribusi\n",
" data['p_d'] = func.calc_prob(data.k, source=source_dist, *parameter) \n",
" data['d'] = (data.p_w - data.p_d).abs()\n",
" dmax = data.d.max()\n",
" dcr = calc_dcr(alpha, n, source=source_dcr)\n",
" result = int(dmax < dcr)\n",
" result_text = ['Distribusi Tidak Diterima', 'Distribusi Diterima']\n",
"\n",
" if show_stat:\n",
" print(f'Periksa Kecocokan Distribusi {dist.title()}')\n",
" print(f'Delta Kritikal = {dcr:.5f}')\n",
" print(f'Delta Max = {dmax:.5f}')\n",
" print(f'Result (Dmax < Dcr) = {result_text[result]}')\n",
"\n",
" if report.lower() == 'result':\n",
" return data['no x p_w p_d d'.split()]\n",
" elif report.lower() == 'full':\n",
" return data"
],
"metadata": {
"id": "i7yYxte8nkCB"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# FUNGSI"
],
"metadata": {
"id": "j9zfA3woZJHh"
}
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `calc_dcr(alpha, n, ...)`\n",
"\n",
"Function: `calc_dcr(alpha, n, source='scipy')`\n",
"\n",
"Fungsi `calc_dcr(...)` digunakan untuk mencari nilai Delta kritis (Dcr / $\\Delta_{kritis}$) dari berbagai sumber berdasarkan nilai derajat kepercayaan (_level of significance_) $\\alpha$ dan jumlah banyaknya data $n$. \n",
"\n",
"- Argumen Posisi:\n",
" - `alpha`: Nilai _level of significance_ $\\alpha$. Dalam satuan desimal ($\\left(0,1\\right) \\in \\mathbb{R}$).\n",
" - `n`: Jumlah banyaknya data. \n",
"- Argumen Opsional:\n",
" - `source`: sumber nilai `Dcr`. `'scipy'` (default). Sumber yang dapat digunakan antara lain: Soetopo (`'soetopo'`), Soewarno (`'soewarno'`).\n",
"\n",
"Perlu dicatat bahwa batas nilai $\\alpha$ dan $n$ untuk masing-masing tabel berbeda-beda.\n",
"- Untuk `soetopo` batasan dimulai dari $\\alpha = \\left[0.2,0.01\\right]$ dengan $n = \\left[1,20\\right]$\n",
"- Untuk `soewarno` batasan dimulai dari $\\alpha = \\left[0.2,0.01\\right]$ dengan $n = \\left[5,50\\right]$\n",
"\n",
"Untuk $n > 50$ disarankan menggunakan `scipy`. "
],
"metadata": {
"id": "3QMJTVF4ZKQx"
}
},
{
"cell_type": "code",
"source": [
"calc_dcr(0.2, 10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_CNKE6VffXtw",
"outputId": "e7cbe087-947d-4fe6-f26f-4b73ba36769b"
},
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.32260155962627957"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "code",
"source": [
"calc_dcr(0.15, 10, source='soetopo')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "RMXPAyD0fdae",
"outputId": "cf0ecdb4-05d2-41a9-e049-523ad00f88a1"
},
"execution_count": 11,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.342"
]
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"source": [
"# perbandingan antara nilai tabel dan fungsi scipy\n",
"\n",
"source_test = ['soewarno', 'soetopo', 'scipy']\n",
"\n",
"_n = 10\n",
"_alpha = [0.2, 0.15, 0.1, 0.07, 0.05, 0.01]\n",
"\n",
"for _source in source_test:\n",
" print(f'Dcr {_source:<12}=', calc_dcr(_alpha, _n, source=_source))\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JJf9s5GTfqoz",
"outputId": "f4b49fb8-fc97-4a10-bbfa-2a4e2c729797"
},
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Dcr soewarno = [0.32 0.35 0.37 0.39 0.41 0.49]\n",
"Dcr soetopo = [0.322 0.342 0.368 0.393 0.409 0.486]\n",
"Dcr scipy = [0.32260156 0.34250845 0.36866333 0.3901533 0.40924614 0.48893166]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `kstest(df, ...)`\n",
"\n",
"Function: `kstest(df, col=None, dist='normal', source_dist='scipy', alpha=0.05, source_dcr='scipy', show_stat=True, report='result')`\n",
"\n",
"Fungsi `kstest(...)` merupakan fungsi untuk melakukan uji kolmogorov-smirnov terhadap distribusi yang dibandingkan. Fungsi ini mengeluarkan objek `pandas.DataFrame`. \n",
"\n",
"- Argumen Posisi:\n",
" - `df`: `pandas.DataFrame`.\n",
"- Argumen Opsional:\n",
" - `col`: nama kolom, `None` (default). Jika tidak diisi menggunakan kolom pertama dalam `df` sebagai data masukan.\n",
" - `dist`: distribusi yang dibandingkan, `'normal'` (distribusi normal) (default). Distribusi yang dapat digunakan antara lain: Log Normal (`'lognormal'`), Gumbel (`'gumbel'`), Log Pearson 3 (`'logpearson3'`).\n",
" - `source_dist`: sumber perhitungan distribusi, `'scipy'` (default). Lihat masing-masing modul analisis frekuensi untuk lebih jelasnya.\n",
" - `alpha`: nilai $\\alpha$, `0.05` (default).\n",
" - `source_dcr`: sumber nilai Dcr, `'scipy'` (default). Sumber yang dapat digunakan antara lain: Soetopo (`'soetopo'`), Soewarno (`'soewarno'`).\n",
" - `show_stat`: menampilkan hasil luaran uji, `True` (default).\n",
" - `report`: opsi kolom luaran dataframe, `'result'` (default). Untuk melihat kolom perhitungan yang lainnya gunakan `'full'`. "
],
"metadata": {
"id": "pMaqh10eg97J"
}
},
{
"cell_type": "code",
"source": [
"kstest(data)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 467
},
"id": "eJUJM8fvAqAz",
"outputId": "4e609768-8aef-4dcf-8add-bf50a615a27d"
},
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Periksa Kecocokan Distribusi Normal\n",
"Delta Kritikal = 0.40925\n",
"Delta Max = 0.09609\n",
"Result (Dmax < Dcr) = Distribusi Diterima\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" no x p_w p_d d\n",
"tahun \n",
"2003-01-01 1 52 0.090909 0.025435 0.065474\n",
"2004-01-01 2 69 0.181818 0.119957 0.061862\n",
"1998-01-01 3 85 0.272727 0.328681 0.055953\n",
"1999-01-01 4 92 0.363636 0.450869 0.087233\n",
"2005-01-01 5 95 0.454545 0.505473 0.050927\n",
"2006-01-01 6 96 0.545455 0.523702 0.021753\n",
"2007-01-01 7 105 0.636364 0.681178 0.044815\n",
"2000-01-01 8 115 0.727273 0.823367 0.096095\n",
"2001-01-01 9 116 0.818182 0.834972 0.016790\n",
"2002-01-01 10 122 0.909091 0.894052 0.015039"
],
"text/html": [
"\n",
" <div id=\"df-f1a60ab4-5fbf-4243-8a19-a355a3666e7d\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>no</th>\n",
" <th>x</th>\n",
" <th>p_w</th>\n",
" <th>p_d</th>\n",
" <th>d</th>\n",
" </tr>\n",
" <tr>\n",
" <th>tahun</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2003-01-01</th>\n",
" <td>1</td>\n",
" <td>52</td>\n",
" <td>0.090909</td>\n",
" <td>0.025435</td>\n",
" <td>0.065474</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004-01-01</th>\n",
" <td>2</td>\n",
" <td>69</td>\n",
" <td>0.181818</td>\n",
" <td>0.119957</td>\n",
" <td>0.061862</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-01</th>\n",
" <td>3</td>\n",
" <td>85</td>\n",
" <td>0.272727</td>\n",
" <td>0.328681</td>\n",
" <td>0.055953</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1999-01-01</th>\n",
" <td>4</td>\n",
" <td>92</td>\n",
" <td>0.363636</td>\n",
" <td>0.450869</td>\n",
" <td>0.087233</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005-01-01</th>\n",
" <td>5</td>\n",
" <td>95</td>\n",
" <td>0.454545</td>\n",
" <td>0.505473</td>\n",
" <td>0.050927</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-01</th>\n",
" <td>6</td>\n",
" <td>96</td>\n",
" <td>0.545455</td>\n",
" <td>0.523702</td>\n",
" <td>0.021753</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007-01-01</th>\n",
" <td>7</td>\n",
" <td>105</td>\n",
" <td>0.636364</td>\n",
" <td>0.681178</td>\n",
" <td>0.044815</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01</th>\n",
" <td>8</td>\n",
" <td>115</td>\n",
" <td>0.727273</td>\n",
" <td>0.823367</td>\n",
" <td>0.096095</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01</th>\n",
" <td>9</td>\n",
" <td>116</td>\n",
" <td>0.818182</td>\n",
" <td>0.834972</td>\n",
" <td>0.016790</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>10</td>\n",
" <td>122</td>\n",
" <td>0.909091</td>\n",
" <td>0.894052</td>\n",
" <td>0.015039</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-f1a60ab4-5fbf-4243-8a19-a355a3666e7d')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-f1a60ab4-5fbf-4243-8a19-a355a3666e7d button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-f1a60ab4-5fbf-4243-8a19-a355a3666e7d');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"source": [
"kstest(data, dist='gumbel', source_dist='soetopo');"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5ReL3Yc4WX7Y",
"outputId": "4ab1b574-56dd-40a4-e3da-e5dd1b7b0dc2"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Periksa Kecocokan Distribusi Gumbel\n",
"Delta Kritikal = 0.40925\n",
"Delta Max = 0.14036\n",
"Result (Dmax < Dcr) = Distribusi Diterima\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"kstest(data, dist='logpearson3', alpha=0.2, source_dcr='soetopo', report='full')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 467
},
"id": "53Y_niHxWaIX",
"outputId": "43f09c8a-f0e9-4ca4-a83c-14c3d141b0c0"
},
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Periksa Kecocokan Distribusi Logpearson3\n",
"Delta Kritikal = 0.32200\n",
"Delta Max = 0.87290\n",
"Result (Dmax < Dcr) = Distribusi Tidak Diterima\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" x no p_w log_x k p_d d\n",
"tahun \n",
"2003-01-01 52 1 0.090909 1.716003 -2.179769 0.963805 0.872896\n",
"2004-01-01 69 2 0.181818 1.838849 -1.100345 0.868202 0.686384\n",
"1998-01-01 85 3 0.272727 1.929419 -0.304525 0.689708 0.416980\n",
"1999-01-01 92 4 0.363636 1.963788 -0.002531 0.584537 0.220900\n",
"2005-01-01 95 5 0.454545 1.977724 0.119920 0.535544 0.080999\n",
"2006-01-01 96 6 0.545455 1.982271 0.159879 0.518805 0.026650\n",
"2007-01-01 105 7 0.636364 2.021189 0.501845 0.363052 0.273312\n",
"2000-01-01 115 8 0.727273 2.060698 0.849000 0.196202 0.531070\n",
"2001-01-01 116 9 0.818182 2.064458 0.882039 0.181020 0.637161\n",
"2002-01-01 122 10 0.909091 2.086360 1.074487 0.099729 0.809362"
],
"text/html": [
"\n",
" <div id=\"df-b6b444ba-e29f-4338-85eb-d48c2a4f2508\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>x</th>\n",
" <th>no</th>\n",
" <th>p_w</th>\n",
" <th>log_x</th>\n",
" <th>k</th>\n",
" <th>p_d</th>\n",
" <th>d</th>\n",
" </tr>\n",
" <tr>\n",
" <th>tahun</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2003-01-01</th>\n",
" <td>52</td>\n",
" <td>1</td>\n",
" <td>0.090909</td>\n",
" <td>1.716003</td>\n",
" <td>-2.179769</td>\n",
" <td>0.963805</td>\n",
" <td>0.872896</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004-01-01</th>\n",
" <td>69</td>\n",
" <td>2</td>\n",
" <td>0.181818</td>\n",
" <td>1.838849</td>\n",
" <td>-1.100345</td>\n",
" <td>0.868202</td>\n",
" <td>0.686384</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-01</th>\n",
" <td>85</td>\n",
" <td>3</td>\n",
" <td>0.272727</td>\n",
" <td>1.929419</td>\n",
" <td>-0.304525</td>\n",
" <td>0.689708</td>\n",
" <td>0.416980</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1999-01-01</th>\n",
" <td>92</td>\n",
" <td>4</td>\n",
" <td>0.363636</td>\n",
" <td>1.963788</td>\n",
" <td>-0.002531</td>\n",
" <td>0.584537</td>\n",
" <td>0.220900</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005-01-01</th>\n",
" <td>95</td>\n",
" <td>5</td>\n",
" <td>0.454545</td>\n",
" <td>1.977724</td>\n",
" <td>0.119920</td>\n",
" <td>0.535544</td>\n",
" <td>0.080999</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-01</th>\n",
" <td>96</td>\n",
" <td>6</td>\n",
" <td>0.545455</td>\n",
" <td>1.982271</td>\n",
" <td>0.159879</td>\n",
" <td>0.518805</td>\n",
" <td>0.026650</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007-01-01</th>\n",
" <td>105</td>\n",
" <td>7</td>\n",
" <td>0.636364</td>\n",
" <td>2.021189</td>\n",
" <td>0.501845</td>\n",
" <td>0.363052</td>\n",
" <td>0.273312</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01</th>\n",
" <td>115</td>\n",
" <td>8</td>\n",
" <td>0.727273</td>\n",
" <td>2.060698</td>\n",
" <td>0.849000</td>\n",
" <td>0.196202</td>\n",
" <td>0.531070</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01</th>\n",
" <td>116</td>\n",
" <td>9</td>\n",
" <td>0.818182</td>\n",
" <td>2.064458</td>\n",
" <td>0.882039</td>\n",
" <td>0.181020</td>\n",
" <td>0.637161</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>122</td>\n",
" <td>10</td>\n",
" <td>0.909091</td>\n",
" <td>2.086360</td>\n",
" <td>1.074487</td>\n",
" <td>0.099729</td>\n",
" <td>0.809362</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b6b444ba-e29f-4338-85eb-d48c2a4f2508')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-b6b444ba-e29f-4338-85eb-d48c2a4f2508 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-b6b444ba-e29f-4338-85eb-d48c2a4f2508');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "markdown",
"source": [
"# Changelog\n",
"\n",
"```\n",
"- 20220613 - 1.1.0 / v0.4.1 - perbaikan, ubah source_dist jadi None dengan default scipy kecuali gumbel. \n",
"- 20220316 - 1.0.0 - Initial\n",
"```\n",
"\n",
"#### Copyright &copy; 2022 [Taruma Sakti Megariansyah](https://taruma.github.io)\n",
"\n",
"Source code in this notebook is licensed under a [MIT License](https://choosealicense.com/licenses/mit/). Data in this notebook is licensed under a [Creative Common Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). \n"
],
"metadata": {
"id": "wOWoCwSek9JG"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment