@@ -645,7 +645,7 @@ was \$`r round(mean(airbnb$price),2)`.
645
645
-->
646
646
647
647
``` {code-cell} ipython3
648
- :tags: [remove-input ]
648
+ :tags: [" remove-cell" ]
649
649
650
650
glue(
651
651
"fig:11-example-means5",
@@ -681,12 +681,12 @@ glue(
681
681
)
682
682
```
683
683
684
- ``` { figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
684
+ :::{glue : figure } fig:11-example-means5
685
685
:name: fig:11-example-means5
686
- :figclass: caption-hack
687
686
688
687
Comparison of population distribution, sample distribution, and sampling distribution.
689
- ```
688
+ :::
689
+
690
690
691
691
+++
692
692
@@ -699,7 +699,7 @@ sampling distribution of the sample mean. We indicate the mean of the sampling
699
699
distribution with a vertical line.
700
700
701
701
``` {code-cell} ipython3
702
- :tags: [remove-input ]
702
+ :tags: [" remove-cell" ]
703
703
704
704
# Plot sampling distributions for multiple sample sizes
705
705
base = alt.Chart(
@@ -753,12 +753,11 @@ glue(
753
753
)
754
754
```
755
755
756
- ``` { figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
756
+ :::{glue : figure } fig:11-example-means7
757
757
:name: fig:11-example-means7
758
- :figclass: caption-hack
759
758
760
759
Comparison of sampling distributions, with mean highlighted as a vertical line.
761
- ```
760
+ :::
762
761
763
762
+++
764
763
@@ -963,8 +962,7 @@ one_sample
963
962
```
964
963
965
964
``` {code-cell} ipython3
966
- :tags: []
967
-
965
+ :tags: ["remove-output"]
968
966
one_sample_dist = alt.Chart(one_sample).mark_bar().encode(
969
967
x=alt.X("price")
970
968
.bin(maxbins=30)
@@ -975,12 +973,17 @@ one_sample_dist = alt.Chart(one_sample).mark_bar().encode(
975
973
one_sample_dist
976
974
```
977
975
978
- ``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
976
+ ``` {code-cell} ipython3
977
+ :tags: ["remove-cell"]
978
+
979
+ glue("fig:11-bootstrapping1", one_sample_dist)
980
+ ```
981
+
982
+ :::{glue: figure } fig:11-bootstrapping1
979
983
:name: fig:11-bootstrapping1
980
- :figclass: caption-hack
981
984
982
985
Histogram of price per night (dollars) for one sample of size 40.
983
- ```
986
+ :::
984
987
985
988
+++
986
989
@@ -1002,7 +1005,7 @@ Since we need to sample with replacement when bootstrapping,
1002
1005
we change the ` replace ` parameter to ` True ` .
1003
1006
1004
1007
``` {code-cell} ipython3
1005
- :tags: []
1008
+ :tags: ["remove-output" ]
1006
1009
1007
1010
boot1 = one_sample.sample(frac=1, replace=True)
1008
1011
boot1_dist = alt.Chart(boot1).mark_bar().encode(
@@ -1015,12 +1018,17 @@ boot1_dist = alt.Chart(boot1).mark_bar().encode(
1015
1018
boot1_dist
1016
1019
```
1017
1020
1018
- ``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1021
+ ``` {code-cell} ipython3
1022
+ :tags: ["remove-cell"]
1023
+
1024
+ glue("fig:11-bootstrapping3", boot1_dist)
1025
+ ```
1026
+
1027
+ :::{glue: figure } fig:11-bootstrapping3
1019
1028
:name: fig:11-bootstrapping3
1020
- :figclass: caption-hack
1021
1029
1022
1030
Bootstrap distribution.
1023
- ```
1031
+ :::
1024
1032
1025
1033
``` {code-cell} ipython3
1026
1034
boot1["price"].mean()
@@ -1055,10 +1063,10 @@ boot20000
1055
1063
Let's take a look at the histograms of the first six replicates of our bootstrap samples.
1056
1064
1057
1065
``` {code-cell} ipython3
1058
- :tags: []
1066
+ :tags: ["remove-output" ]
1059
1067
1060
1068
six_bootstrap_samples = boot20000.query("replicate < 6")
1061
- alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
1069
+ six_bootstrap_fig = alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
1062
1070
x=alt.X("price")
1063
1071
.bin(maxbins=20)
1064
1072
.title("Price per night (dollars)"),
@@ -1067,14 +1075,20 @@ alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
1067
1075
"replicate:N", # Recall that `:N` converts the variable to a categorical type
1068
1076
columns=2
1069
1077
)
1078
+ six_bootstrap_fig
1070
1079
```
1071
1080
1072
- ``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1081
+ ``` {code-cell} ipython3
1082
+ :tags: ["remove-cell"]
1083
+
1084
+ glue("fig:11-bootstrapping-six-bootstrap-samples", six_bootstrap_fig)
1085
+ ```
1086
+
1087
+ :::{glue: figure } fig:11-bootstrapping-six-bootstrap-samples
1073
1088
:name: fig:11-bootstrapping-six-bootstrap-samples
1074
- :figclass: caption-hack
1075
1089
1076
1090
Histograms of the first six replicates of the bootstrap samples.
1077
- ```
1091
+ :::
1078
1092
1079
1093
+++
1080
1094
@@ -1125,7 +1139,7 @@ boot20000_means
1125
1139
```
1126
1140
1127
1141
``` {code-cell} ipython3
1128
- :tags: []
1142
+ :tags: ["remove-output" ]
1129
1143
1130
1144
boot_est_dist = alt.Chart(boot20000_means).mark_bar().encode(
1131
1145
x=alt.X("mean_price")
@@ -1137,23 +1151,28 @@ boot_est_dist = alt.Chart(boot20000_means).mark_bar().encode(
1137
1151
boot_est_dist
1138
1152
```
1139
1153
1140
- ``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1154
+ ``` {code-cell} ipython3
1155
+ :tags: ["remove-cell"]
1156
+
1157
+ glue("fig:11-bootstrapping5", boot_est_dist)
1158
+ ```
1159
+
1160
+ :::{glue: figure } fig:11-bootstrapping5
1141
1161
:name: fig:11-bootstrapping5
1142
- :figclass: caption-hack
1143
1162
1144
1163
Distribution of the bootstrap sample means.
1145
- ```
1164
+ :::
1146
1165
1147
1166
+++
1148
1167
1149
1168
Let's compare the bootstrap distribution&mdash ; which we construct by taking many samples from our original sample of size 40&mdash ; with
1150
1169
the true sampling distribution&mdash ; which corresponds to taking many samples from the population.
1151
1170
1152
1171
``` {code-cell} ipython3
1153
- :tags: [remove-input ]
1172
+ :tags: [remove-cell ]
1154
1173
1155
1174
sampling_distribution.encoding.x["bin"]["extent"] = (90, 250)
1156
- alt.vconcat(
1175
+ bootstr6fig = alt.vconcat(
1157
1176
alt.layer(
1158
1177
sampling_distribution,
1159
1178
alt.Chart(sample_estimates).mark_rule(color="black", size=1.5, strokeDash=[6]).encode(x="mean(mean_price)"),
@@ -1175,12 +1194,19 @@ alt.vconcat(
1175
1194
)
1176
1195
```
1177
1196
1178
- ``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1197
+ ``` {code-cell} ipython3
1198
+ :tags: ["remove-cell"]
1199
+
1200
+ glue("fig:11-bootstrapping6", bootstr6fig)
1201
+ ```
1202
+
1203
+ :::{glue: figure } fig:11-bootstrapping6
1179
1204
:name: fig:11-bootstrapping6
1180
- :figclass: caption-hack
1181
1205
1182
1206
Comparison of the distribution of the bootstrap sample means and sampling distribution.
1183
- ```
1207
+ :::
1208
+
1209
+
1184
1210
1185
1211
``` {code-cell} ipython3
1186
1212
:tags: [remove-cell]
@@ -1277,7 +1303,7 @@ the middle 95\% of the sample mean prices in the bootstrap distribution. We can
1277
1303
visualize the interval on our distribution in {numref}` fig:11-bootstrapping9 ` .
1278
1304
1279
1305
``` {code-cell} ipython3
1280
- :tags: [remove-input ]
1306
+ :tags: [remove-cell ]
1281
1307
# Create the annotation for for the 2.5th percentile
1282
1308
rule_025 = alt.Chart().mark_rule(color="black", size=1.5, strokeDash=[6]).encode(
1283
1309
x=alt.datum(ci_bounds[0.025])
@@ -1301,15 +1327,22 @@ text_975 = text_025.encode(
1301
1327
rule_975 = rule_025.encode(x=alt.datum(ci_bounds[0.975]))
1302
1328
1303
1329
# Layer the annotations on top of the distribution plot
1304
- boot_est_dist + rule_025 + text_025 + rule_975 + text_975
1330
+ bootstr9fig = boot_est_dist + rule_025 + text_025 + rule_975 + text_975
1331
+ ```
1332
+
1333
+ ``` {code-cell} ipython3
1334
+ :tags: ["remove-cell"]
1335
+
1336
+ glue("fig:11-bootstrapping9", bootstr9fig)
1305
1337
```
1306
1338
1307
- ``` { figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1339
+ :::{glue : figure } fig:11-bootstrapping9
1308
1340
:name: fig:11-bootstrapping9
1309
- :figclass: caption-hack
1310
1341
1311
1342
Distribution of the bootstrap sample means with percentile lower and upper bounds.
1312
- ```
1343
+ :::
1344
+
1345
+
1313
1346
1314
1347
+++
1315
1348
0 commit comments