| \n", - " | 1star | \n", - "2star | \n", - "3star | \n", - "4star | \n", - "5star | \n", - "|||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "49 | \n", "70 | \n", "119 | \n", @@ -249,7 +163,9 @@ "245 | \n", "||||||||||||||||||||||||||
| 1 | \n", + "1 | \n", + "2 | \n", + "Priceless | \n", "67 | \n", "22 | \n", "22 | \n", @@ -257,7 +173,9 @@ "574 | \n", "|||||||||||||||||||||||
| 2 | \n", + "2 | \n", + "3 | \n", + "Allied | \n", "59 | \n", "76 | \n", "102 | \n", @@ -265,7 +183,9 @@ "406 | \n", "|||||||||||||||||||||||
| 3 | \n", + "3 | \n", + "4 | \n", + "The Infiltrator | \n", "173 | \n", "216 | \n", "518 | \n", @@ -273,7 +193,9 @@ "2073 | \n", "|||||||||||||||||||||||
| 4 | \n", + "4 | \n", + "5 | \n", + "Miss Sloane | \n", "180 | \n", "60 | \n", "48 | \n", @@ -285,12 +207,12 @@ "" ], "text/plain": [ - " 1star 2star 3star 4star 5star\n", - "0 49 70 119 217 245\n", - "1 67 22 22 60 574\n", - "2 59 76 102 203 406\n", - "3 173 216 518 1339 2073\n", - "4 180 60 48 120 793" + " ID Descrip n1 n2 n3 n4 n5\n", + "0 1 The Whole Truth 49 70 119 217 245\n", + "1 2 Priceless 67 22 22 60 574\n", + "2 3 Allied 59 76 102 203 406\n", + "3 4 The Infiltrator 173 216 518 1339 2073\n", + "4 5 Miss Sloane 180 60 48 120 793" ] }, "execution_count": 5, @@ -299,47 +221,44 @@ } ], "source": [ - "# Convert the precentages to counts with help of N column. Order the columns.\n", - "y = (data.iloc[:,2:7]\n", - " .divide(100)\n", - " .multiply(data.iloc[:,1], axis=0)\n", - " .round()\n", - " .astype(int)\n", - " .iloc[:,::-1])\n", - "# Strip \"Prcnt\" from the column names\n", - "y.columns = y.columns.map(lambda x: x[:5])\n", - "y.head()" + "data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "# Columns n1 - n5\n", + "y = data.iloc[:,2:]" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0 700\n", - "1 745\n", - "2 846\n", - "3 4319\n", - "4 1201\n", - "dtype: int64" + "5" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "z = y.sum(axis=1)\n", - "z.head()" + "# Number of outcomes\n", + "nYlevels = y.columns.size\n", + "nYlevels" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -348,50 +267,54 @@ "36" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "Ncases = data.index.size\n", + "Ncases = y.index.size\n", "Ncases" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "5" + "0 700\n", + "1 745\n", + "2 846\n", + "3 4319\n", + "4 1201\n", + "dtype: int64" ] }, - "execution_count": 8, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# Number of outcomes\n", - "nYlevels = y.columns.size\n", - "nYlevels" + "z = y.sum(1)\n", + "z.head()" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(2.6180339887498949, 0.53934466291663163)" + "(2.618033988749895, 0.5393446629166316)" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -410,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -420,7 +343,7 @@ "
| \n", + " | mean | \n", + "sd | \n", + "mc_error | \n", + "hpd_2.5 | \n", + "hpd_97.5 | \n", + "n_eff | \n", + "Rhat | \n", + "
|---|---|---|---|---|---|---|---|
| theta_missing__0 | \n", + "2.246005 | \n", + "0.006341 | \n", + "0.000088 | \n", + "2.233922 | \n", + "2.258625 | \n", + "5238.737408 | \n", + "1.000006 | \n", + "
| theta_missing__1 | \n", + "3.094291 | \n", + "0.005603 | \n", + "0.000084 | \n", + "3.083331 | \n", + "3.105244 | \n", + "4734.599038 | \n", + "1.000204 | \n", + "
Note that the code is in Jupyter Notebook format and requires modification to use with other datasets.
Some of the general concepts from the book are discussed in papers by Kruschke & Liddell. See references below.
-**2018-08-16 (ongoing):** +**2018-08-16:** Updating the notebooks with PyMC3 v3.5 and general code clean-up. Inserting plots of the PyMC models in plate notation (v3.5 feature). Fixing some deprecation warnings. -
-Chapter 9 - Hierarchical Models (PyMC3 3.5)
-Chapter 10 - Model Comparison and Hierarchical Modelling (PyMC3 3.5)
-Chapter 12 - Bayesian Approaches to Testing a Point ("Null") Hypothesis (PyMC3 3.5)
-Chapter 16 - Metric-Predicted Variable on One or Two Groups (PyMC3 3.5)
-Chapter 17 - Metric-Predicted Variable with One Metric Predictor (PyMC3 3.5)
+
+Chapter 9 - Hierarchical Models
+Chapter 10 - Model Comparison and Hierarchical Modelling
+Chapter 12 - Bayesian Approaches to Testing a Point ("Null") Hypothesis
+Chapter 16 - Metric-Predicted Variable on One or Two Groups
+Chapter 17 - Metric-Predicted Variable with One Metric Predictor
Chapter 18 - Metric Predicted Variable with Multiple Metric Predictors
-Chapter 19 - Metric Predicted Variable with One Nominal Predictor (PyMC3 3.5)
+Chapter 19 - Metric Predicted Variable with One Nominal Predictor
Chapter 20 - Metric Predicted Variable with Multiple Nominal Predictor
-Chapter 21 - Dichotomous Predicted Variable (PyMC3 3.5)
-Chapter 22 - Nominal Predicted Variable (PyMC3 3.5)
-Chapter 23 - Ordinal Predicted Variable (PyMC3 3.5)
-Chapter 24 - Count Predicted Variable (PyMC3 3.5)
-
+Chapter 21 - Dichotomous Predicted Variable
+Chapter 22 - Nominal Predicted Variable
+Chapter 23 - Ordinal Predicted Variable
+Chapter 24 - Count Predicted Variable
Extra:
Bayesian Linear Regression example (Bishop, 2006)
Example on modelling Ordinal Data (Liddell & Kruschke, 2018)