Clase 2

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()
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
library(patchwork)
library(tidyquant)
Loading required package: PerformanceAnalytics
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following object is masked from 'package:tsibble':

    index

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric


######################### Warning from 'xts' package ##########################
#                                                                             #
# The dplyr lag() function breaks how base R's lag() function is supposed to  #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
# source() into this session won't work correctly.                            #
#                                                                             #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
# dplyr from breaking base R's lag() function.                                #
#                                                                             #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#                                                                             #
###############################################################################

Attaching package: 'xts'

The following objects are masked from 'package:dplyr':

    first, last


Attaching package: 'PerformanceAnalytics'

The following object is masked from 'package:fpp3':

    prices

The following object is masked from 'package:graphics':

    legend

Loading required package: quantmod
Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 

Attaching package: 'tidyquant'

The following object is masked from 'package:fable':

    VAR
empleo_tsbl <- us_employment |> 
  filter(year(Month) >= 1990, Title == "Retail Trade") |> 
  select(-Series_ID)
empleo_decomp <- empleo_tsbl |> 
  model(
    clasica = classical_decomposition(Employed,
                                      type = "additive")
  )

empleo_decomp
# A mable: 1 x 1
          clasica
          <model>
1 <DECOMPOSITION>
empleo_components <- empleo_decomp |> 
  components()
empleo_components
# A dable: 357 x 7 [1M]
# Key:     .model [1]
# :        Employed = trend + seasonal + random
   .model     Month Employed  trend seasonal random season_adjust
   <chr>      <mth>    <dbl>  <dbl>    <dbl>  <dbl>         <dbl>
 1 clasica 1990 Jan   13256.    NA    -75.5   NA           13331.
 2 clasica 1990 Feb   12966.    NA   -273.    NA           13239.
 3 clasica 1990 Mar   12938.    NA   -253.    NA           13191.
 4 clasica 1990 Apr   13012.    NA   -190.    NA           13203.
 5 clasica 1990 May   13108.    NA    -88.9   NA           13197.
 6 clasica 1990 Jun   13183.    NA    -10.4   NA           13193.
 7 clasica 1990 Jul   13170. 13178.   -13.3    5.65        13183.
 8 clasica 1990 Aug   13160. 13161.    -9.99   8.80        13169.
 9 clasica 1990 Sep   13113. 13141.   -87.4   59.9         13201.
10 clasica 1990 Oct   13185. 13117.    34.6   33.8         13151.
# ℹ 347 more rows
empleo_components |> 
  autoplot()
Warning: Removed 6 rows containing missing values (`geom_line()`).

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