|
40 | 40 | }, |
41 | 41 | { |
42 | 42 | "cell_type": "code", |
43 | | - "execution_count": 6, |
| 43 | + "execution_count": 1, |
44 | 44 | "metadata": {}, |
45 | 45 | "outputs": [], |
46 | 46 | "source": [ |
|
50 | 50 | }, |
51 | 51 | { |
52 | 52 | "cell_type": "code", |
53 | | - "execution_count": 7, |
| 53 | + "execution_count": 2, |
54 | 54 | "metadata": {}, |
55 | 55 | "outputs": [], |
56 | 56 | "source": [ |
|
68 | 68 | }, |
69 | 69 | { |
70 | 70 | "cell_type": "code", |
71 | | - "execution_count": 8, |
| 71 | + "execution_count": 3, |
72 | 72 | "metadata": {}, |
73 | 73 | "outputs": [ |
74 | 74 | { |
|
77 | 77 | "-5.494678164823001" |
78 | 78 | ] |
79 | 79 | }, |
80 | | - "execution_count": 8, |
| 80 | + "execution_count": 3, |
81 | 81 | "metadata": {}, |
82 | 82 | "output_type": "execute_result" |
83 | 83 | } |
|
92 | 92 | "cell_type": "markdown", |
93 | 93 | "metadata": {}, |
94 | 94 | "source": [ |
95 | | - "By default, the function returns a scalar value given by the mean log likelihood. To return the log likelihood contributions, set the argument `return_scalar` to `False`. The function will the return an array." |
| 95 | + "By default, the function returns a scalar value given by the mean log likelihood. To return the log likelihood contributions, set the argument `return_scalar` to `False`. The function will the return a dictionary containing the scalar value, contributions, and a pandas.DataFrame which can be used for visualization purposes." |
96 | 96 | ] |
97 | 97 | }, |
98 | 98 | { |
99 | 99 | "cell_type": "code", |
100 | | - "execution_count": 11, |
| 100 | + "execution_count": 6, |
101 | 101 | "metadata": {}, |
102 | 102 | "outputs": [ |
103 | 103 | { |
104 | 104 | "data": { |
105 | 105 | "text/plain": [ |
106 | | - "(1000,)" |
| 106 | + "dict_keys(['value', 'contributions', 'comparison_plot_data'])" |
107 | 107 | ] |
108 | 108 | }, |
109 | | - "execution_count": 11, |
| 109 | + "execution_count": 6, |
110 | 110 | "metadata": {}, |
111 | 111 | "output_type": "execute_result" |
112 | 112 | } |
113 | 113 | ], |
114 | 114 | "source": [ |
115 | 115 | "log_like_contribs = rp.get_log_like_func(params=params, options=options, df=data, return_scalar=False)\n", |
116 | | - "array = log_like_contribs(params)\n", |
117 | | - "array.shape" |
118 | | - ] |
119 | | - }, |
120 | | - { |
121 | | - "cell_type": "markdown", |
122 | | - "metadata": {}, |
123 | | - "source": [ |
124 | | - "## Comparison plot data\n", |
125 | | - "\n", |
126 | | - "The log likelihood function can also return a pandas.DataFrame containing more detailed information. In the DataFrame lists the individual contributions of each observation split up by choices and wages and is suited for [estimagic](https://estimagic.readthedocs.io/en/latest/)'s visualization capabilities. When the argument `return_comparison_plot_data` is set to **True**, the criterion returns a tuple containing the mean log likelihood/likelihood contributions and the comparison plot data." |
| 116 | + "outputs = log_like_contribs(params)\n", |
| 117 | + "outputs.keys()" |
127 | 118 | ] |
128 | 119 | }, |
129 | 120 | { |
130 | 121 | "cell_type": "code", |
131 | | - "execution_count": 12, |
| 122 | + "execution_count": 7, |
132 | 123 | "metadata": {}, |
133 | | - "outputs": [], |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "data": { |
| 127 | + "text/plain": [ |
| 128 | + "-5.494678164823001" |
| 129 | + ] |
| 130 | + }, |
| 131 | + "execution_count": 7, |
| 132 | + "metadata": {}, |
| 133 | + "output_type": "execute_result" |
| 134 | + } |
| 135 | + ], |
134 | 136 | "source": [ |
135 | | - "log_like = rp.get_log_like_func(params=params, options=options, df=data, return_comparison_plot_data=True)\n", |
136 | | - "out = log_like(params)" |
| 137 | + "outputs[\"value\"]" |
137 | 138 | ] |
138 | 139 | }, |
139 | 140 | { |
140 | 141 | "cell_type": "code", |
141 | | - "execution_count": 13, |
| 142 | + "execution_count": 11, |
142 | 143 | "metadata": {}, |
143 | 144 | "outputs": [ |
144 | 145 | { |
145 | 146 | "data": { |
146 | 147 | "text/plain": [ |
147 | | - "-5.494678164823001" |
| 148 | + "array([-1.12998713, -1.16105606, -8.14899502, -1.18885353, -6.5085553 ,\n", |
| 149 | + " -1.22019297, -7.125007 , -5.29376864, -7.4765499 , -4.82486523])" |
148 | 150 | ] |
149 | 151 | }, |
150 | | - "execution_count": 13, |
| 152 | + "execution_count": 11, |
151 | 153 | "metadata": {}, |
152 | 154 | "output_type": "execute_result" |
153 | 155 | } |
154 | 156 | ], |
155 | 157 | "source": [ |
156 | | - "out[0]" |
| 158 | + "outputs[\"contributions\"][0:10]" |
| 159 | + ] |
| 160 | + }, |
| 161 | + { |
| 162 | + "cell_type": "markdown", |
| 163 | + "metadata": {}, |
| 164 | + "source": [ |
| 165 | + "The DataFrame saved under the key `comparison_plot_data` lists the individual contributions of each observation split up by choices and wages and is suited for [estimagic](https://estimagic.readthedocs.io/en/latest/)'s visualization capabilities." |
157 | 166 | ] |
158 | 167 | }, |
159 | 168 | { |
160 | 169 | "cell_type": "code", |
161 | | - "execution_count": 14, |
| 170 | + "execution_count": 12, |
162 | 171 | "metadata": {}, |
163 | 172 | "outputs": [ |
164 | 173 | { |
|
230 | 239 | " <td>-0.072571</td>\n", |
231 | 240 | " <td>choice</td>\n", |
232 | 241 | " </tr>\n", |
233 | | - " <tr>\n", |
234 | | - " <th>...</th>\n", |
235 | | - " <td>...</td>\n", |
236 | | - " <td>...</td>\n", |
237 | | - " <td>...</td>\n", |
238 | | - " <td>...</td>\n", |
239 | | - " <td>...</td>\n", |
240 | | - " </tr>\n", |
241 | | - " <tr>\n", |
242 | | - " <th>9995</th>\n", |
243 | | - " <td>999</td>\n", |
244 | | - " <td>0</td>\n", |
245 | | - " <td>hammock</td>\n", |
246 | | - " <td>0.000000</td>\n", |
247 | | - " <td>wage</td>\n", |
248 | | - " </tr>\n", |
249 | | - " <tr>\n", |
250 | | - " <th>9996</th>\n", |
251 | | - " <td>999</td>\n", |
252 | | - " <td>1</td>\n", |
253 | | - " <td>hammock</td>\n", |
254 | | - " <td>0.000000</td>\n", |
255 | | - " <td>wage</td>\n", |
256 | | - " </tr>\n", |
257 | | - " <tr>\n", |
258 | | - " <th>9997</th>\n", |
259 | | - " <td>999</td>\n", |
260 | | - " <td>2</td>\n", |
261 | | - " <td>hammock</td>\n", |
262 | | - " <td>0.000000</td>\n", |
263 | | - " <td>wage</td>\n", |
264 | | - " </tr>\n", |
265 | | - " <tr>\n", |
266 | | - " <th>9998</th>\n", |
267 | | - " <td>999</td>\n", |
268 | | - " <td>3</td>\n", |
269 | | - " <td>hammock</td>\n", |
270 | | - " <td>0.000000</td>\n", |
271 | | - " <td>wage</td>\n", |
272 | | - " </tr>\n", |
273 | | - " <tr>\n", |
274 | | - " <th>9999</th>\n", |
275 | | - " <td>999</td>\n", |
276 | | - " <td>4</td>\n", |
277 | | - " <td>hammock</td>\n", |
278 | | - " <td>0.000000</td>\n", |
279 | | - " <td>wage</td>\n", |
280 | | - " </tr>\n", |
281 | 242 | " </tbody>\n", |
282 | 243 | "</table>\n", |
283 | | - "<p>10000 rows × 5 columns</p>\n", |
284 | 244 | "</div>" |
285 | 245 | ], |
286 | 246 | "text/plain": [ |
287 | | - " identifier period choice value kind\n", |
288 | | - "0 0 0 hammock -0.597872 choice\n", |
289 | | - "1 0 1 hammock -0.248358 choice\n", |
290 | | - "2 0 2 hammock -0.127806 choice\n", |
291 | | - "3 0 3 hammock -0.083382 choice\n", |
292 | | - "4 0 4 hammock -0.072571 choice\n", |
293 | | - "... ... ... ... ... ...\n", |
294 | | - "9995 999 0 hammock 0.000000 wage\n", |
295 | | - "9996 999 1 hammock 0.000000 wage\n", |
296 | | - "9997 999 2 hammock 0.000000 wage\n", |
297 | | - "9998 999 3 hammock 0.000000 wage\n", |
298 | | - "9999 999 4 hammock 0.000000 wage\n", |
299 | | - "\n", |
300 | | - "[10000 rows x 5 columns]" |
| 247 | + " identifier period choice value kind\n", |
| 248 | + "0 0 0 hammock -0.597872 choice\n", |
| 249 | + "1 0 1 hammock -0.248358 choice\n", |
| 250 | + "2 0 2 hammock -0.127806 choice\n", |
| 251 | + "3 0 3 hammock -0.083382 choice\n", |
| 252 | + "4 0 4 hammock -0.072571 choice" |
301 | 253 | ] |
302 | 254 | }, |
303 | | - "execution_count": 14, |
| 255 | + "execution_count": 12, |
304 | 256 | "metadata": {}, |
305 | 257 | "output_type": "execute_result" |
306 | 258 | } |
307 | 259 | ], |
308 | 260 | "source": [ |
309 | | - "out[1]" |
| 261 | + "outputs[\"comparison_plot_data\"].head()" |
310 | 262 | ] |
311 | 263 | }, |
312 | 264 | { |
|
398 | 350 | "name": "python", |
399 | 351 | "nbconvert_exporter": "python", |
400 | 352 | "pygments_lexer": "ipython3", |
401 | | - "version": "3.8.3" |
| 353 | + "version": "3.7.10" |
402 | 354 | } |
403 | 355 | }, |
404 | 356 | "nbformat": 4, |
|
0 commit comments