|
|
@@ -106,7 +106,10 @@
|
|
|
"source": [
|
|
|
"# Two-sided 95% confidence intervals used throughout the notebook\n",
|
|
|
"alpha = 0.05\n",
|
|
|
- "probs = [alpha / 2, 1 - alpha / 2]\n"
|
|
|
+ "probs = [alpha / 2, 1 - alpha / 2]\n",
|
|
|
+ "\n",
|
|
|
+ "# Reproducibility: pass this seed to every stochastic calculation.\n",
|
|
|
+ "random_seed = logistic.DEFAULT_RANDOM_SEED\n"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
@@ -170,7 +173,7 @@
|
|
|
"logit = logistic.LogisticPolyRegression(degree=1, mono=False)\n",
|
|
|
"\n",
|
|
|
"# fits\n",
|
|
|
- "fit_results = [logit.fit(x, y, method=\"local\") for x in xs]\n",
|
|
|
+ "fit_results = [logit.fit(x, y, method=\"local\", seed=random_seed) for x in xs]\n",
|
|
|
"if not all(result[\"success\"] for result in fit_results):\n",
|
|
|
" raise RuntimeError(\"At least one linear logistic-regression fit failed.\")\n",
|
|
|
"\n",
|
|
|
@@ -562,7 +565,8 @@
|
|
|
"# goodness of fit measures\n",
|
|
|
"index = pd.Index(scales, name = 'scale')\n",
|
|
|
"pd.DataFrame(\n",
|
|
|
- " [logit.goodness_of_fit(x, y, theta) for x, theta in zip(xs, thetas)],\n",
|
|
|
+ " [logit.goodness_of_fit(x, y, theta, bootstrap_seed=random_seed)\n",
|
|
|
+ " for x, theta in zip(xs, thetas)],\n",
|
|
|
" index=index,\n",
|
|
|
")"
|
|
|
]
|
|
|
@@ -601,7 +605,9 @@
|
|
|
"fig, axs = plt.subplots(ncols = len(scales), figsize = (6*len(scales), 5))\n",
|
|
|
"\n",
|
|
|
"quantile_methods = {\n",
|
|
|
- " \"normal\": logit.get_model_quantiles_normal,\n",
|
|
|
+ " \"normal\": lambda x, p, theta, cov: logit.get_model_quantiles_normal(\n",
|
|
|
+ " x, p, theta, cov, seed=random_seed\n",
|
|
|
+ " ),\n",
|
|
|
" \"delta\": logit.get_model_quantiles_delta,\n",
|
|
|
"}\n",
|
|
|
"\n",
|
|
|
@@ -715,7 +721,7 @@
|
|
|
"logit = logistic.LogisticPolyRegression(degree=3, mono=False)\n",
|
|
|
"\n",
|
|
|
"# fits\n",
|
|
|
- "fit_results = [logit.fit(x, y, method=\"local\") for x in xs]\n",
|
|
|
+ "fit_results = [logit.fit(x, y, method=\"local\", seed=random_seed) for x in xs]\n",
|
|
|
"if not all(result[\"success\"] for result in fit_results):\n",
|
|
|
" raise RuntimeError(\"At least one cubic logistic-regression fit failed.\")\n",
|
|
|
"\n",
|
|
|
@@ -1174,7 +1180,8 @@
|
|
|
"# goodness of fit measures\n",
|
|
|
"index = pd.Index(scales, name = 'scale')\n",
|
|
|
"pd.DataFrame(\n",
|
|
|
- " [logit.goodness_of_fit(x, y, theta) for x, theta in zip(xs, thetas)],\n",
|
|
|
+ " [logit.goodness_of_fit(x, y, theta, bootstrap_seed=random_seed)\n",
|
|
|
+ " for x, theta in zip(xs, thetas)],\n",
|
|
|
" index=index,\n",
|
|
|
")"
|
|
|
]
|
|
|
@@ -1211,7 +1218,9 @@
|
|
|
"fig, axs = plt.subplots(ncols = len(scales), figsize = (6*len(scales), 5))\n",
|
|
|
"\n",
|
|
|
"quantile_methods = {\n",
|
|
|
- " \"normal\": logit.get_model_quantiles_normal,\n",
|
|
|
+ " \"normal\": lambda x, p, theta, cov: logit.get_model_quantiles_normal(\n",
|
|
|
+ " x, p, theta, cov, seed=random_seed\n",
|
|
|
+ " ),\n",
|
|
|
" \"delta\": logit.get_model_quantiles_delta,\n",
|
|
|
"}\n",
|
|
|
"\n",
|
|
|
@@ -1447,7 +1456,7 @@
|
|
|
"logit = logistic.LogisticPolyRegression(degree=3, mono=True, lam=(0.0, 1e-6))\n",
|
|
|
"\n",
|
|
|
"# fits\n",
|
|
|
- "ress = [logit.fit(x, y, method=\"diff_evol\") for x in xs]\n",
|
|
|
+ "ress = [logit.fit(x, y, method=\"diff_evol\", seed=random_seed) for x in xs]\n",
|
|
|
"if not all(result[\"success\"] for result in ress):\n",
|
|
|
" raise RuntimeError(\"At least one monotonic cubic logistic-regression fit failed.\")\n",
|
|
|
"\n",
|
|
|
@@ -2143,7 +2152,8 @@
|
|
|
"source": [
|
|
|
"# goodness of fit measures\n",
|
|
|
"pd.DataFrame(\n",
|
|
|
- " [logit.goodness_of_fit(x, y, theta) for x, theta in zip(xs, thetas)], \n",
|
|
|
+ " [logit.goodness_of_fit(x, y, theta, bootstrap_seed=random_seed)\n",
|
|
|
+ " for x, theta in zip(xs, thetas)], \n",
|
|
|
" index = pd.Index(scales, name = 'scale')\n",
|
|
|
")"
|
|
|
]
|
|
|
@@ -2182,7 +2192,9 @@
|
|
|
"fig, axs = plt.subplots(ncols = len(scales), figsize = (6*len(scales), 5))\n",
|
|
|
"\n",
|
|
|
"quantile_methods = {\n",
|
|
|
- " \"normal\": logit.get_model_quantiles_normal,\n",
|
|
|
+ " \"normal\": lambda x, p, theta, cov: logit.get_model_quantiles_normal(\n",
|
|
|
+ " x, p, theta, cov, seed=random_seed\n",
|
|
|
+ " ),\n",
|
|
|
" \"delta\": logit.get_model_quantiles_delta,\n",
|
|
|
"}\n",
|
|
|
"\n",
|
|
|
@@ -2275,7 +2287,9 @@
|
|
|
"\n",
|
|
|
"boots_theta_results = {}\n",
|
|
|
"quantile_methods = {\n",
|
|
|
- " \"normal\": logit.get_model_quantiles_normal,\n",
|
|
|
+ " \"normal\": lambda x, p, theta, cov: logit.get_model_quantiles_normal(\n",
|
|
|
+ " x, p, theta, cov, seed=random_seed\n",
|
|
|
+ " ),\n",
|
|
|
" \"delta\": logit.get_model_quantiles_delta,\n",
|
|
|
"}\n",
|
|
|
"parameter_generators = {\n",
|
|
|
@@ -2328,7 +2342,9 @@
|
|
|
" print(f\"model CI:scale:{scale},boots-method:{method}\")\n",
|
|
|
"\n",
|
|
|
" # generate sampled or bootstrapped parameters\n",
|
|
|
- " btheta = parameter_generators[method](x, y, n_parameter_samples)\n",
|
|
|
+ " btheta = parameter_generators[method](\n",
|
|
|
+ " x, y, n_parameter_samples, seed=random_seed\n",
|
|
|
+ " )\n",
|
|
|
" \n",
|
|
|
" boots_theta_results[(scale, method)] = btheta\n",
|
|
|
"\n",
|