Skip to content

Commit 7b417b8

Browse files
committed
title change
1 parent f114c65 commit 7b417b8

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

vignettes/panel-data.Rmd

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ In the following sections, we will go over preprocessing the data in the
196196
`epi_recipe` framework, and fitting a model and making predictions within the
197197
`epipredict` framework and using the package's canned forecasters.
198198

199-
# A simple example
199+
# A Simple AR(3) Model Example
200+
200201
## Preprocessing
201202

202203
As a simple example, let's work with the `num_graduates` column for now. We will
@@ -212,7 +213,8 @@ employ_small <- employ %>%
212213
mutate(
213214
num_graduates_prop = num_graduates / sum(num_graduates),
214215
med_income_2y_prop = med_income_2y / sum(med_income_2y),
215-
med_income_5y_prop = med_income_5y / sum(med_income_5y)) %>%
216+
med_income_5y_prop = med_income_5y / sum(med_income_5y)
217+
) %>%
216218
ungroup()
217219
head(employ_small)
218220
```
@@ -269,7 +271,9 @@ and `ahead` columns.
269271

270272
```{r view-preprocessed, include=T}
271273
# Display a sample of the preprocessed data
272-
baked_sample <- r %>% prep() %>% bake(new_data = employ_small) %>%
274+
baked_sample <- r %>%
275+
prep() %>%
276+
bake(new_data = employ_small) %>%
273277
sample_n(5)
274278
baked_sample
275279
```
@@ -325,25 +329,27 @@ employ_small_with_preds <- augment(wf_linreg, latest)
325329
employ_small_with_preds %>% head()
326330
```
327331

328-
## AR(3) Model Diagnostics
332+
## Model Diagnostics
329333

330334
First, we'll plot the residuals (that is, $y_{t} - \hat{y}_{t}$) against the
331335
fitted values ($\hat{y}_{t}$).
332336

333337
```{r lienarreg-resid-plot, include=T, warning=F}
334-
employ_small_with_preds <- employ_small_with_preds %>%
335-
mutate(resid = num_graduates_prop - .pred)
336-
338+
employ_small_with_preds <- employ_small_with_preds %>%
339+
mutate(resid = num_graduates_prop - .pred)
340+
337341
p1 <- employ_small_with_preds %>%
338-
ggplot(aes(x = .pred, y = resid)) +
342+
ggplot(aes(x = .pred, y = resid)) +
339343
geom_point(size = 1.5, alpha = .8) +
340-
geom_smooth(method = "loess", color = "red", linetype = "dashed", size = .7) +
344+
geom_smooth(method = "loess", color = "red", linetype = "dashed", size = .7) +
341345
xlab("Fitted values") +
342346
ylab("Residuals") +
343347
ggtitle("Plot of Fitted Values vs. Residuals in AR(3) Model")
344348
345-
p2 <- employ_small_with_preds %>%
346-
ggplot(aes(sample = resid)) + stat_qq(alpha = .6) + stat_qq_line() +
349+
p2 <- employ_small_with_preds %>%
350+
ggplot(aes(sample = resid)) +
351+
stat_qq(alpha = .6) +
352+
stat_qq_line() +
347353
ggtitle("Q-Q Plot of Residuals")
348354
349355
grid.arrange(p1, p2, ncol = 2)
@@ -378,7 +384,9 @@ where $y_i$ is the 2-year median income at time $i$.
378384
```{r flatline, include=T, warning=F}
379385
out_fl <- flatline_forecaster(employ_small, "med_income_2y",
380386
args_list = flatline_args_list(
381-
ahead = 1L, forecast_date = as.Date("2015-01-01")))
387+
ahead = 1L, forecast_date = as.Date("2015-01-01")
388+
)
389+
)
382390
383391
augment(out_fl$epi_workflow, employ_small) %>% head()
384392
```
@@ -394,11 +402,13 @@ where $y_i$ is as before, and $z_i$ is the 5-year median income at time $i$.
394402

395403
```{r arx-lr, include=T, warning=F}
396404
arx_args <- arx_args_list(
397-
lags = c(0L, 1L), ahead = 1L, forecast_date = as.Date("2015-01-01"))
405+
lags = c(0L, 1L), ahead = 1L, forecast_date = as.Date("2015-01-01")
406+
)
398407
399408
out_arx_lr <- arx_forecaster(employ_small, "med_income_2y",
400409
c("med_income_2y", "med_income_5y"),
401-
args_list = arx_args)
410+
args_list = arx_args
411+
)
402412
403413
out_arx_lr$predictions %>% head()
404414
```
@@ -410,7 +420,8 @@ as expected. Below we use a boosted tree model instead of a linear regression.
410420
out_arx_rf <- arx_forecaster(
411421
employ_small, "med_income_2y", c("med_income_2y", "med_income_5y"),
412422
trainer = parsnip::boost_tree(mode = "regression", trees = 20),
413-
args_list = arx_args)
423+
args_list = arx_args
424+
)
414425
415426
out_arx_rf$predictions %>% head()
416427
```

0 commit comments

Comments
 (0)