lab-2-1

.docx

School

Conestoga College *

*We aren’t endorsed by this school

Course

8010

Subject

Economics

Date

Feb 20, 2024

Type

docx

Pages

5

Uploaded by UltraWater15179

Report
lab-2.R Chintan 2023-01-25 library (fpp3) ## ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ── ## ✔ tibble 3.1.8 ✔ tsibble 1.1.3 ## ✔ dplyr 1.0.10 ✔ tsibbledata 0.4.1 ## ✔ tidyr 1.2.1 ✔ feasts 0.3.0 ## ✔ lubridate 1.9.0 ✔ fable 0.3.2 ## ✔ ggplot2 3.4.0 ## ── 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 (knitr) library (seasonal) ## ## Attaching package: 'seasonal' ## The following object is masked from 'package:tibble': ## ## view library (tidyverse) ## ── Attaching packages ## ─────────────────────────────────────── ## tidyverse 1.3.2 ── ## ✔ readr 2.1.3 ✔ stringr 1.5.0 ## ✔ purrr 0.3.5 ✔ forcats 0.5.2 ## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── ## ✖ lubridate::as.difftime() masks base::as.difftime() ## ✖ lubridate::date() masks base::date() ## ✖ dplyr::filter() masks stats::filter()
## ✖ tsibble::intersect() masks lubridate::intersect(), base::intersect() ## ✖ tsibble::interval() masks lubridate::interval() ## ✖ dplyr::lag() masks stats::lag() ## ✖ tsibble::setdiff() masks lubridate::setdiff(), base::setdiff() ## ✖ tsibble::union() masks lubridate::union(), base::union() ## ✖ seasonal::view() masks tibble::view() library (readr) library (stringr) library (readxl) set.seed ( 133 ) food_prices <- read_csv ( "E:/conestoga/sem-2/statistical forecasting/Lab-2/food_prices.csv" ) ## Rows: 2067 Columns: 3 ## ── Column specification ──────────────────────────────────────────────────────── ## Delimiter: "," ## chr (2): Products, Date ## dbl (1): Price ## ## Use `spec()` to retrieve the full column specification for this data. ## Specify the column types or set `show_col_types = FALSE` to quiet this message. #1. Create a new variable orange_prices by filtering our new_prices so it includes only Oranges new_prices <- food_prices %>% mutate ( Date = yearmonth (Date)) %>% as_tsibble ( key = Products, index = Date) orange_prices <- new_prices %>% filter ( ` Products ` == "Oranges, per kilogram 3" ) decomp <- orange_prices %>% model ( classical= classical_decomposition (Price, type= "additive" ), x11= X_13ARIMA_SEATS (Price ~ x11 ()), stl= STL (Price) ) #2. Decompose this using STL stlcomps <- decomp %>% select (stl) %>% components (decomp)
#x11comps<- decomp %>% select(x11) %>% components(decomp) #classicComp<- decomp %>% select(classical) %>%components(decomp) stlcomps %>% tail () %>% kable () .model Date Price trend season_year remainder season_adjust stl 2021 Aug 2.87 3.375300 -0.5869257 0.0816256 3.456926 stl 2021 Sep 3.04 3.383412 -0.2670860 -0.0763258 3.307086 stl 2021 Oct 3.00 3.392103 -0.0209359 -0.3711667 3.020936 stl 2021 Nov 3.80 3.400793 0.2305962 0.1686103 3.569404 stl 2021 Dec 3.73 3.409484 0.0777480 0.2427678 3.652252 stl 2022 Jan 3.19 3.419435 -0.2182102 -0.0112248 3.408210 #3. Plot the decomposition stlcomps %>% autoplot () #4. Create a new variable egg_prices by filtering new_prices so it includes only Eggs egg_prices <- new_prices %>% filter ( ` Products ` == "Eggs, 1 dozen 3" ) #5. Decompose this using x11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help