Clase 3

Author

Ivanna Herrera

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(fpp3)
── Attaching packages ────────────────────────────────────────────── fpp3 0.5 ──
✔ tsibble     1.1.3     ✔ fable       0.3.3
✔ tsibbledata 0.4.1     ✔ fabletools  0.3.4
✔ feasts      0.3.1     
── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
✖ lubridate::date()    masks base::date()
✖ dplyr::filter()      masks stats::filter()
✖ tsibble::intersect() masks base::intersect()
✖ tsibble::interval()  masks lubridate::interval()
✖ dplyr::lag()         masks stats::lag()
✖ tsibble::setdiff()   masks base::setdiff()
✖ tsibble::union()     masks base::union()
aus_accommodation
# A tsibble: 592 x 5 [1Q]
# Key:       State [8]
      Date State                        Takings Occupancy   CPI
     <qtr> <chr>                          <dbl>     <dbl> <dbl>
 1 1998 Q1 Australian Capital Territory    24.3      65    67  
 2 1998 Q2 Australian Capital Territory    22.3      59    67.4
 3 1998 Q3 Australian Capital Territory    22.5      58    67.5
 4 1998 Q4 Australian Capital Territory    24.4      59    67.8
 5 1999 Q1 Australian Capital Territory    23.7      58    67.8
 6 1999 Q2 Australian Capital Territory    25.4      61    68.1
 7 1999 Q3 Australian Capital Territory    28.2      66    68.7
 8 1999 Q4 Australian Capital Territory    25.8      60    69.1
 9 2000 Q1 Australian Capital Territory    27.3      60.9  69.7
10 2000 Q2 Australian Capital Territory    30.1      64.7  70.2
# ℹ 582 more rows
aus_accommodation_long <- aus_accommodation |> 
  pivot_longer(cols = Takings:CPI, names_to = "variable",
               values_to = "valor")
aus_accommodation_long |>   
  features(valor,
           list(media = mean,
                desv_std = sd,
                minimo = min,
                maximo = max,
                mediana = median)
           ) # |> 
# A tibble: 24 × 7
   State                        variable  media desv_std minimo maximo mediana
   <chr>                        <chr>     <dbl>    <dbl>  <dbl>  <dbl>   <dbl>
 1 Australian Capital Territory CPI        88.0    13.1    67    109.     87.2
 2 Australian Capital Territory Occupancy  67.7     5.29   56.8   80.2    68.8
 3 Australian Capital Territory Takings    44.8    13.2    22.3   71.1    45.7
 4 New South Wales              CPI        88.0    13.1    67    109.     87.2
 5 New South Wales              Occupancy  62.7     3.84   54.1   69.8    62.9
 6 New South Wales              Takings   575.    157.    316.   945.    571. 
 7 Northern Territory           CPI        88.0    13.1    67    109.     87.2
 8 Northern Territory           Occupancy  60.8    10.4    41.8   79.8    60.4
 9 Northern Territory           Takings    53.8    21.7    22.0  118.     49.4
10 Queensland                   CPI        88.0    13.1    67    109.     87.2
# ℹ 14 more rows
  # pivot_wider(names_from = variable, values_from = media:mediana)
aus_accommodation_long |> 
  features(valor, feat_stl)
# A tibble: 24 × 11
   State       variable trend_strength seasonal_strength_year seasonal_peak_year
   <chr>       <chr>             <dbl>                  <dbl>              <dbl>
 1 Australian… CPI               1.00                   0.292                  3
 2 Australian… Occupan…          0.863                  0.333                  3
 3 Australian… Takings           0.985                  0.333                  3
 4 New South … CPI               1.00                   0.292                  3
 5 New South … Occupan…          0.969                  0.927                  0
 6 New South … Takings           0.990                  0.878                  0
 7 Northern T… CPI               1.00                   0.292                  3
 8 Northern T… Occupan…          0.892                  0.983                  3
 9 Northern T… Takings           0.976                  0.968                  3
10 Queensland  CPI               1.00                   0.292                  3
# ℹ 14 more rows
# ℹ 6 more variables: seasonal_trough_year <dbl>, spikiness <dbl>,
#   linearity <dbl>, curvature <dbl>, stl_e_acf1 <dbl>, stl_e_acf10 <dbl>
aus_accommodation_long |> 
  features(valor, features = guerrero)
# A tibble: 24 × 3
   State                        variable  lambda_guerrero
   <chr>                        <chr>               <dbl>
 1 Australian Capital Territory CPI                0.521 
 2 Australian Capital Territory Occupancy          1.43  
 3 Australian Capital Territory Takings            0.273 
 4 New South Wales              CPI                0.521 
 5 New South Wales              Occupancy          0.957 
 6 New South Wales              Takings            0.0961
 7 Northern Territory           CPI                0.521 
 8 Northern Territory           Occupancy          2.00  
 9 Northern Territory           Takings           -0.217 
10 Queensland                   CPI                0.521 
# ℹ 14 more rows

Quarto

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).