Skip to content

Commit 892b08e

Browse files
committed
fix tables
1 parent 4d6be6f commit 892b08e

16 files changed

+3233
-5554
lines changed

02-visualization.qmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ In February 2006, a statistician named Hans Rosling gave a TED talk titled ["The
100100

101101
```{r}
102102
#| label: tbl-gapminder-2007
103-
#| tbl-cap: "Gapminder 2007 Data: First 6 of 142 countries"
103+
#| tbl-cap: "Gapminder 2007 Data First 6 of 142 countries"
104104
#| echo: false
105105
106106
gapminder_2007 %>%
107107
head() %>%
108108
kable(
109109
format = "markdown",
110110
digits = 2,
111-
caption = "Gapminder 2007 Data: First 6 of 142 countries",
111+
#caption = "Gapminder 2007 Data: First 6 of 142 countries",
112112
booktabs = TRUE
113113
) %>%
114114
kable_styling(
@@ -168,7 +168,7 @@ tibble(
168168
) %>%
169169
kable(
170170
format = "markdown",
171-
caption = "Summary of Grammar of Graphics for this plot",
171+
# caption = "Summary of Grammar of Graphics for this plot",
172172
booktabs = TRUE
173173
) %>%
174174
kable_styling(
@@ -965,7 +965,7 @@ kable(
965965
format = "markdown",
966966
flights_table,
967967
digits = 3,
968-
caption = "Number of flights pre-counted for each carrier",
968+
# caption = "Number of flights pre-counted for each carrier",
969969
booktabs = TRUE,
970970
longtable = TRUE
971971
) %>%
@@ -1181,7 +1181,7 @@ Let's recap all five of the Five Named Graphs (5NG) in @tbl-viz-summary summariz
11811181
read_csv("table/viz_summary_table.csv", na = "") %>%
11821182
kable(
11831183
format = "markdown",
1184-
caption = "Summary of 5NG",
1184+
# caption = "Summary of 5NG",
11851185
booktabs = TRUE
11861186
) %>%
11871187
kable_styling(

03-wrangling.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ temp <- "https://docs.google.com/spreadsheets/d/e/2PACX-1vRgwl1lugQA6zxzfB6_0hM5
949949
temp %>%
950950
kable(
951951
format = "markdown",
952-
caption = "Summary of data wrangling verbs",
952+
#caption = "Summary of data wrangling verbs",
953953
booktabs = TRUE
954954
) %>%
955955
kable_styling(font_size = ifelse(knitr:::is_latex_output(), 10, 16),

04-tidy.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ stocks <- tibble(
230230
stocks %>%
231231
kable(
232232
digits = 2,
233-
caption = "Stock Prices (Non-Tidy Format)",
233+
#caption = "Stock Prices (Non-Tidy Format)",
234234
booktabs = TRUE,
235235
format = "markdown"
236236
) %>%
@@ -258,7 +258,7 @@ stocks_tidy <- stocks %>%
258258
stocks_tidy %>%
259259
kable(
260260
digits = 2,
261-
caption = "Stock Prices (Tidy Format)",
261+
#caption = "Stock Prices (Tidy Format)",
262262
booktabs = TRUE,
263263
format = "markdown"
264264
) %>%
@@ -282,7 +282,7 @@ stocks %>%
282282
kable(
283283
format = "markdown",
284284
digits = 2,
285-
caption = "Date, Boeing Price, Weather Data",
285+
#caption = "Date, Boeing Price, Weather Data",
286286
booktabs = TRUE
287287
) %>%
288288
kable_styling(font_size = ifelse(knitr:::is_latex_output(), 10, 16),

05-regression.qmd

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ evals_ch5 %>%
191191
slice_sample(n = 5) %>%
192192
knitr::kable(
193193
digits = 3,
194-
caption = "A random sample of 5 out of the 463 courses at UT Austin",
194+
#caption = "A random sample of 5 out of the 463 courses at UT Austin",
195195
booktabs = TRUE,
196196
format = "markdown"
197197
) %>%
@@ -486,7 +486,7 @@ score_model
486486

487487
This output is telling us that the `Intercept` coefficient $b_0$ of the regression line is 3.8803, and the slope coefficient for `by_avg` is 0.0666. Therefore the blue regression line in @fig-numxplot4 is
488488

489-
$$\widehat{\text{score}} = b_0 + b_{\text{bty avg}} \cdot\text{bty avg} = 3.8803 + 0.0666\cdot\text{ bty avg}$$
489+
$$\widehat{\text{score}} = b_0 + b_{\text{bty avg}} \cdot\text{bty avg} = 3.8803 + 0.0666\cdot\text{bty avg}$$
490490

491491
where
492492

@@ -533,11 +533,18 @@ summary(score_model)$coefficients
533533
#| label: tbl-numxplot4b
534534
#| tbl-cap: "Linear regression table"
535535
#| echo: false
536+
#| eval: true
536537
537-
summary(score_model)$coefficients %>%
538+
score_model_coeffs <- summary(score_model)$coefficients
539+
540+
colnames(score_model_coeffs) <- c("Estimate", "Std. Error", "t value", "p value")
541+
542+
score_model_coeffs %>%
543+
as.data.frame() %>%
544+
rownames_to_column("term") %>%
538545
knitr::kable(
539546
digits = 3,
540-
caption = "Linear regression table",
547+
#caption = "Linear regression table",
541548
booktabs = TRUE,
542549
format = "markdown"
543550
) %>%
@@ -597,7 +604,9 @@ What is the value on the blue line corresponding to this instructor's `bty_avg`
597604

598605
* Red circle: This is the *observed value* $y$ = `r y` and corresponds to this instructor's actual teaching score.
599606

600-
* Red square: This is the *fitted value* $\widehat{y}$ and corresponds to the value on the regression line for $x$ = `r x`. This value is computed using the intercept and slope in the regression table above: $$\widehat{y} = b_0 + b_1 \cdot x = `r coefs[1,1]` + `r coefs[2,1]` * `r x` = `r y_hat`$$
607+
* Red square: This is the *fitted value* $\widehat{y}$ and corresponds to the value on the regression line for $x$ = `r x`. This value is computed using the intercept and slope in the regression table above:
608+
609+
$$\widehat{y} = b_0 + b_1 \cdot x = `r coefs[1,1]` + `r coefs[2,1]` * `r x` = `r y_hat`$$
601610

602611
* Blue arrow: The length of this arrow is the *residual* and is computed by subtracting the fitted value $\widehat{y}$ from the observed value $y$. The residual can be thought of as the error or "lack of fit" of the regression line. In the case of this instructor, it is $y - \widehat{y}$ = `r y` - `r y_hat` = `r y-y_hat`. In other words, the model was off by `r y-y_hat` teaching score units for this instructor.
603612

@@ -664,7 +673,7 @@ score_model_data %>%
664673
filter(ID %in% seq(from = index, to = (index + 3))) %>%
665674
knitr::kable(
666675
digits = 3,
667-
caption = "Regression points (for only 21st through 24th instructor)",
676+
#caption = "Regression points (for only 21st through 24th instructor)",
668677
booktabs = TRUE,
669678
format = "markdown"
670679
) %>%
@@ -785,7 +794,7 @@ gapminder2007 %>%
785794
slice_sample(n =5) %>%
786795
knitr::kable(
787796
digits = 3,
788-
caption = "Random sample of 5 out of 142 countries",
797+
#caption = "Random sample of 5 out of 142 countries",
789798
booktabs = TRUE,
790799
format = "markdown"
791800
) %>%
@@ -930,12 +939,13 @@ lifeExp_by_continent <- gapminder2007 %>%
930939

931940
```{r}
932941
#| label: tbl-catxplot0
942+
#| tbl-cap: "Life expectancy by continent"
933943
#| echo: false
934944
935945
lifeExp_by_continent %>%
936946
knitr::kable(
937947
digits = 3,
938-
caption = "Life expectancy by continent",
948+
# caption = "Life expectancy by continent",
939949
booktabs = TRUE,
940950
format = "markdown"
941951
) %>%
@@ -970,7 +980,7 @@ gapminder2007 %>%
970980
mutate(`Difference versus Africa` = mean - mean_africa) %>%
971981
knitr::kable(
972982
digits = 3,
973-
caption = "Mean life expectancy by continent and relative differences from mean for Africa",
983+
# caption = "Mean life expectancy by continent and relative differences from mean for Africa",
974984
booktabs = TRUE,
975985
format = "markdown"
976986
) %>%
@@ -1015,7 +1025,7 @@ gapminder2007 %>%
10151025
mutate(`mean vs Africa` = mean - mean_africa) %>%
10161026
knitr::kable(
10171027
digits = 3,
1018-
caption = "Mean life expectancy by continent",
1028+
# caption = "Mean life expectancy by continent",
10191029
booktabs = TRUE,
10201030
format = "markdown"
10211031
) %>%
@@ -1047,11 +1057,16 @@ coefs <- summary(lifeExp_model)$coefficients
10471057
#| label: tbl-catxplot4b
10481058
#| tbl-cap: "Linear regression table"
10491059
#| echo: false
1060+
#| eval: true
1061+
1062+
colnames(coefs) <- c("Estimate", "Std. Error", "t value", "p value")
10501063
10511064
coefs %>%
1065+
as.data.frame() %>%
1066+
rownames_to_column("term") %>%
10521067
knitr::kable(
10531068
digits = 3,
1054-
caption = "Linear regression table",
1069+
# caption = "Linear regression table",
10551070
booktabs = TRUE,
10561071
format = "markdown"
10571072
) %>%
@@ -1074,12 +1089,20 @@ $$
10741089

10751090
Let's break this down. First, $\mathbb{1}_{A}(x)$ is what's known in mathematics as an "indicator function" that takes one of two possible values:
10761091

1092+
<!-- $$ -->
1093+
<!-- \mathbb{1}_{A}(x) = \left\{ -->
1094+
<!-- \begin{array}{ll} -->
1095+
<!-- 1 & \text{if } x \text{ is in } A \\ -->
1096+
<!-- 0 & \text{otherwise} \end{array} -->
1097+
<!-- \right. -->
1098+
<!-- $$ -->
1099+
10771100
$$
1078-
\mathbb{1}_{A}(x) = \left\{
1079-
\begin{array}{ll}
1080-
1 & \text{if } x \text{ is in } A \\
1081-
0 & \text{otherwise} \end{array}
1082-
\right.
1101+
\mathbb{1}_{A}(x) =
1102+
\begin{cases}
1103+
1 & \text{if } x \in A \\
1104+
0 & \text{otherwise}
1105+
\end{cases}
10831106
$$
10841107

10851108
In a statistical modeling context this is also known as a "dummy variable". In our case, let's consider the first such indicator variable:
@@ -1181,7 +1204,7 @@ lifeExp_model_data %>%
11811204
slice(1:10) %>%
11821205
knitr::kable(
11831206
digits = 3,
1184-
caption = "Regression points (First 10 out of 142 countries)",
1207+
# caption = "Regression points (First 10 out of 142 countries)",
11851208
booktabs = TRUE,
11861209
format = "markdown"
11871210
) %>%

0 commit comments

Comments
 (0)