|
3850 | 3850 | "outputs": [], |
3851 | 3851 | "source": [ |
3852 | 3852 | "def make_delay_table(\n", |
3853 | | - " scenario, scenario_name, base=base_overall, base_name=\"current\",\n", |
3854 | | - " asu_beds=list(range(9,15)), rehab_beds=list(range(10,17))\n", |
3855 | | - " ):\n", |
| 3853 | + " scenario, scenario_name, base, base_name, asu_beds, rehab_beds\n", |
| 3854 | + "):\n", |
3856 | 3855 | " \"\"\"\n", |
3857 | 3856 | " Create table with the probability of delay and 1 in n patients delayed,\n", |
3858 | 3857 | " for the base case and a provided scenario.\n", |
|
3884 | 3883 | " tab_segment = []\n", |
3885 | 3884 | "\n", |
3886 | 3885 | " # Loop over base case and scenario...\n", |
3887 | | - " for scenario_name, df in {base_name: base[unit_name],\n", |
3888 | | - " scenario_name: scenario[unit_name]}.items():\n", |
| 3886 | + " for name, df in {base_name: base[unit_name],\n", |
| 3887 | + " scenario_name: scenario[unit_name]}.items():\n", |
3889 | 3888 | "\n", |
3890 | 3889 | " # Extract results for specified beds\n", |
3891 | 3890 | " df = df[df[\"beds\"].isin(unit_beds)][\n", |
3892 | 3891 | " [\"beds\", \"prob_delay\", \"1_in_n_delay\"]]\n", |
3893 | 3892 | "\n", |
3894 | 3893 | " # Rename column to be specific to scenario\n", |
3895 | 3894 | " df = df.rename(columns={\n", |
3896 | | - " \"prob_delay\": f\"prob_delay_{scenario_name}\",\n", |
3897 | | - " \"1_in_n_delay\": f\"1_in_n_delay_{scenario_name}\"})\n", |
| 3895 | + " \"prob_delay\": f\"prob_delay_{name}\",\n", |
| 3896 | + " \"1_in_n_delay\": f\"1_in_n_delay_{name}\"})\n", |
3898 | 3897 | "\n", |
3899 | 3898 | " # Save dataframe to list\n", |
3900 | 3899 | " tab_segment.append(df)\n", |
|
4100 | 4099 | "12 37.0 " |
4101 | 4100 | ] |
4102 | 4101 | }, |
4103 | | - "execution_count": 11, |
4104 | 4102 | "metadata": {}, |
4105 | | - "output_type": "execute_result" |
| 4103 | + "output_type": "display_data" |
4106 | 4104 | } |
4107 | 4105 | ], |
4108 | 4106 | "source": [ |
4109 | | - "full_tab2 = make_delay_table(scenario=s1_overall, scenario_name=\"5%\")\n", |
4110 | | - "full_tab2" |
| 4107 | + "full_tab2 = make_delay_table(\n", |
| 4108 | + " scenario=s1_overall, scenario_name=\"5%\", base=base_overall,\n", |
| 4109 | + " base_name=\"current\", asu_beds=list(range(9,15)),\n", |
| 4110 | + " rehab_beds=list(range(10,17)))\n", |
| 4111 | + "display(full_tab2)" |
4111 | 4112 | ] |
4112 | 4113 | }, |
4113 | 4114 | { |
|
4546 | 4547 | "# Make table\n", |
4547 | 4548 | "sup_tab1 = make_delay_table(scenario=s4_overall,\n", |
4548 | 4549 | " scenario_name=\"no_complex_neuro\",\n", |
| 4550 | + " base=base_overall,\n", |
| 4551 | + " base_name=\"current\",\n", |
4549 | 4552 | " asu_beds=list(range(10,16)),\n", |
4550 | 4553 | " rehab_beds=list(range(12,17)))\n", |
4551 | 4554 | "\n", |
|
4993 | 4996 | "37 40 2 0.000007 1.000000 0.000007 136875.0" |
4994 | 4997 | ] |
4995 | 4998 | }, |
4996 | | - "execution_count": 16, |
4997 | 4999 | "metadata": {}, |
4998 | | - "output_type": "execute_result" |
| 5000 | + "output_type": "display_data" |
4999 | 5001 | } |
5000 | 5002 | ], |
5001 | 5003 | "source": [ |
|
5007 | 5009 | "\n", |
5008 | 5010 | "# Hijack the get_occupancy_freq() method from runner to calculate stats\n", |
5009 | 5011 | "pooled_results = base_runner.get_occupancy_freq(combined_audit, unit=\"pooled\")\n", |
5010 | | - "pooled_results" |
| 5012 | + "display(pooled_results)" |
5011 | 5013 | ] |
5012 | 5014 | }, |
5013 | 5015 | { |
|
5075 | 5077 | "outputs": [], |
5076 | 5078 | "source": [ |
5077 | 5079 | "class PooledDelay:\n", |
| 5080 | + " \"\"\"\n", |
| 5081 | + " Class to calculate probability of delays in scenarios with partial pooling\n", |
| 5082 | + " of acute and rehab beds.\n", |
| 5083 | + "\n", |
| 5084 | + " Attributes\n", |
| 5085 | + " ----------\n", |
| 5086 | + " asu : pd.Series\n", |
| 5087 | + " Frequency distribution of ASU bed occupancies.\n", |
| 5088 | + " rehab : pd.Series\n", |
| 5089 | + " Frequency distribution of rehab bed occupancies.\n", |
| 5090 | + " asu_beds : int or float\n", |
| 5091 | + " Number of dedicated ASU beds (excluding pooled beds).\n", |
| 5092 | + " rehab_beds : int or float\n", |
| 5093 | + " Number of dedicated rehab beds (excluding pooled beds).\n", |
| 5094 | + " pooled_beds : int or float\n", |
| 5095 | + " Number of beds that can be used by either unit.\n", |
| 5096 | + " \"\"\"\n", |
5078 | 5097 | " def __init__(self, base_results):\n", |
5079 | 5098 | " \"\"\"\n", |
| 5099 | + " Initialise the PooledDelay object with base simulation results.\n", |
| 5100 | + "\n", |
5080 | 5101 | " Parameters\n", |
5081 | 5102 | " ----------\n", |
5082 | 5103 | " base_results: dict\n", |
|
5103 | 5124 | " occ_freq : pd.Series\n", |
5104 | 5125 | " Frequencies of each number of beds, with the index representing the\n", |
5105 | 5126 | " occupancy.\n", |
5106 | | - " min_occ : int\n", |
5107 | | - " The minimum number of beds for which we want to check probability.\n", |
5108 | 5127 | " threshold : int\n", |
5109 | 5128 | " The threshold number of beds for comparison.\n", |
5110 | 5129 | " comparison : str\n", |
|
5114 | 5133 | " Returns\n", |
5115 | 5134 | " -------\n", |
5116 | 5135 | " float\n", |
5117 | | - " The probability of an occupancy greater than or equal to min_occ.\n", |
| 5136 | + " Probability that the occupancy meets the specified comparison\n", |
| 5137 | + " condition.\n", |
5118 | 5138 | " \"\"\"\n", |
5119 | 5139 | " # Calculate total frequency\n", |
5120 | 5140 | " total_freq = occ_freq.sum()\n", |
|
5129 | 5149 | " elif comparison == \"lt\":\n", |
5130 | 5150 | " # Less than\n", |
5131 | 5151 | " filtered_freq = occ_freq[occ_freq.index < threshold].sum()\n", |
| 5152 | + " else:\n", |
| 5153 | + " raise ValueError(f\"Comparison '{comparison}' not valid.\")\n", |
5132 | 5154 | "\n", |
5133 | 5155 | " # Calculate and return the probability\n", |
5134 | 5156 | " return filtered_freq / total_freq\n", |
|
5141 | 5163 | " ----------\n", |
5142 | 5164 | " unit: str\n", |
5143 | 5165 | " Name of unit to investigate (\"asu\", \"rehab\").\n", |
| 5166 | + "\n", |
| 5167 | + " Returns\n", |
| 5168 | + " -------\n", |
| 5169 | + " float\n", |
| 5170 | + " Probability that only the specified unit has delays.\n", |
5144 | 5171 | " \"\"\"\n", |
5145 | 5172 | " # Determine name of other unit, depending on which you are focussing on\n", |
5146 | 5173 | " other_unit = \"rehab\" if unit == \"asu\" else \"asu\"\n", |
|
5262 | 5289 | " Number of dedicated rehabilitation beds (excluding pooled beds).\n", |
5263 | 5290 | " pooled_beds: int\n", |
5264 | 5291 | " Number of beds that can be used by either unit.\n", |
| 5292 | + "\n", |
| 5293 | + " Returns\n", |
| 5294 | + " -------\n", |
| 5295 | + " pool_results: dict\n", |
| 5296 | + " Dictionary containing number of dedicated and pooled beds,\n", |
| 5297 | + " probability of delay for each unit, and 1 in n patients delayed\n", |
| 5298 | + " for each unit.\n", |
5265 | 5299 | " \"\"\"\n", |
5266 | 5300 | " # Get counts of dedicated and pooled beds\n", |
5267 | 5301 | " self.asu_beds = asu_beds\n", |
|
0 commit comments