── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ tsibble::interval() masks lubridate::interval()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
aus_livestock |>distinct(Animal)
# A tibble: 7 × 1
Animal
<fct>
1 Bulls, bullocks and steers
2 Calves
3 Cattle (excl. calves)
4 Cows and heifers
5 Lambs
6 Pigs
7 Sheep
ovejas <- aus_livestock |>filter(Animal =="Sheep", State =="New South Wales")ovejas
# A tsibble: 558 x 4 [1M]
# Key: Animal, State [1]
Month Animal State Count
<mth> <fct> <fct> <dbl>
1 1972 Jul Sheep New South Wales 669400
2 1972 Aug Sheep New South Wales 581100
3 1972 Sep Sheep New South Wales 468100
4 1972 Oct Sheep New South Wales 515300
5 1972 Nov Sheep New South Wales 564500
6 1972 Dec Sheep New South Wales 565400
7 1973 Jan Sheep New South Wales 630300
8 1973 Feb Sheep New South Wales 528900
9 1973 Mar Sheep New South Wales 594500
10 1973 Apr Sheep New South Wales 443000
# ℹ 548 more rows
# A tsibble: 486 x 4 [1M]
# Key: Animal, State [1]
Month Animal State Count
<mth> <fct> <fct> <dbl>
1 1972 Jul Sheep New South Wales 669400
2 1972 Aug Sheep New South Wales 581100
3 1972 Sep Sheep New South Wales 468100
4 1972 Oct Sheep New South Wales 515300
5 1972 Nov Sheep New South Wales 564500
6 1972 Dec Sheep New South Wales 565400
7 1973 Jan Sheep New South Wales 630300
8 1973 Feb Sheep New South Wales 528900
9 1973 Mar Sheep New South Wales 594500
10 1973 Apr Sheep New South Wales 443000
# ℹ 476 more rows
Visualization
Time plot
ovejas_train |>autoplot(Count)
lambda <- ovejas_train |>features(Count, features = guerrero) |>pull(lambda_guerrero)lambda
[1] 0.5806898
ovejas_train |>autoplot(box_cox(Count, lambda))
Season plot
ovejas_train |>gg_season(Count)
ovejas_train |>gg_season(box_cox(Count, lambda))
ovejas_train |>features(Count, feat_stl)
# A tibble: 1 × 11
Animal State trend_strength seasonal_strength_year seasonal_peak_year
<fct> <fct> <dbl> <dbl> <dbl>
1 Sheep New South Wal… 0.914 0.584 9
# ℹ 6 more variables: seasonal_trough_year <dbl>, spikiness <dbl>,
# linearity <dbl>, curvature <dbl>, stl_e_acf1 <dbl>, stl_e_acf10 <dbl>
# A mable: 1 x 6
# Key: Animal, State [1]
Animal State snaive_bc snaive combi_bc
<fct> <fct> <model> <model> <model>
1 Sheep New South Wales <SNAIVE> <SNAIVE> <STL decomposition model>
# ℹ 1 more variable: combi <model>
ovejas_fit |>augment() |>features(.innov, ljung_box, dof =0, lag =24)
# A tibble: 4 × 5
Animal State .model lb_stat lb_pvalue
<fct> <fct> <chr> <dbl> <dbl>
1 Sheep New South Wales combi 145. 0
2 Sheep New South Wales combi_bc 138. 0
3 Sheep New South Wales snaive 1021. 0
4 Sheep New South Wales snaive_bc 1098. 0
accuracy(ovejas_fit) |>arrange(MAPE)
# A tibble: 4 × 12
Animal State .model .type ME RMSE MAE MPE MAPE MASE RMSSE
<fct> <fct> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Sheep New South… combi… Trai… 451. 4.70e4 34632. -1.16 12.1 0.458 0.457
2 Sheep New South… combi Trai… 713. 4.73e4 34649. -0.863 12.3 0.459 0.459
3 Sheep New South… snaiv… Trai… -10469. 1.03e5 75551. -11.7 30.7 1 1
4 Sheep New South… snaive Trai… -10469. 1.03e5 75551. -11.7 30.7 1 1
# ℹ 1 more variable: ACF1 <dbl>
# A fable: 288 x 6 [1M]
# Key: Animal, State, .model [4]
Animal State .model Month Count .mean
<fct> <fct> <chr> <mth> <dist> <dbl>
1 Sheep New South Wales snaive_bc 2013 Jan t(N(1435, 255334)) 115655.
2 Sheep New South Wales snaive_bc 2013 Feb t(N(1304, 255334)) 99577.
3 Sheep New South Wales snaive_bc 2013 Mar t(N(1251, 255334)) 93376.
4 Sheep New South Wales snaive_bc 2013 Apr t(N(1157, 255334)) 82864.
5 Sheep New South Wales snaive_bc 2013 May t(N(1293, 255334)) 98198.
6 Sheep New South Wales snaive_bc 2013 Jun t(N(1020, 255334)) 68775.
7 Sheep New South Wales snaive_bc 2013 Jul t(N(1163, 255334)) 83551.
8 Sheep New South Wales snaive_bc 2013 Aug t(N(1355, 255334)) 105589.
9 Sheep New South Wales snaive_bc 2013 Sep t(N(1708, 255334)) 152765.
10 Sheep New South Wales snaive_bc 2013 Oct t(N(2119, 255334)) 217309.
# ℹ 278 more rows
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1+1
[1] 2
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).