TSlab1 Revathy
TSlab1 Revathy
TSlab1 Revathy
R
revak
2024-05-19
##1> Set Up
library(fpp3)
## ── 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(tidyverse)
## Rows: 19 Columns: 21
## ── Column specification
────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): North American Industry Classification System (NAICS) 3
## dbl (7): 2002, 2003, 2004, 2005, 2006, 2007, 2008
## num (13): 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
2019, ...
##
## ℹ 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.
## # A tibble: 6 × 21
## North American Indus…¹ `2002` `2003` `2004` `2005` `2006` `2007` `2008`
`2009`
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
<dbl>
## 1 Forestry, logging and… 7941 8101 7966 7666 7205 6332 5544
4406
## 2 Mining, quarrying, an… 17184 17256 18975 19338 20416 23222 28611
23251
## 3 Utilities 43723 43280 46111 44619 45578 46787 46434
45569
## 4 Construction 213684 221792 227238 233124 244687 258014 271446
259994
## 5 Manufacturing 903171 896256 875269 854352 835430 799984 753952
654947
## 6 Transportation and wa… 209937 213273 215467 221099 227585 232039 233812
229055
## # ℹ abbreviated name:
## # ¹`North American Industry Classification System (NAICS) 3`
## # ℹ 12 more variables: `2010` <dbl>, `2011` <dbl>, `2012` <dbl>, `2013`
<dbl>,
## # `2014` <dbl>, `2015` <dbl>, `2016` <dbl>, `2017` <dbl>, `2018` <dbl>,
## # `2019` <dbl>, `2020` <dbl>, `2021` <dbl>
colnames(jobs)
###Lab Steps
##Step 1: Data Cleaning
jobs <- jobs %>%
pivot_longer(cols = `2002`:`2021`, names_to = "year", values_to = "value")
%>%
mutate(year = as.integer(year)) %>%
as_tsibble(key = `North American Industry Classification System (NAICS) 3`,
index = year)
## # A tsibble: 20 x 3 [1Y]
## # Key: North American Industry Classification System (NAICS) 3 [1]
## `North American Industry Classification System (NAICS) 3` year value
## <chr> <int> <dbl>
## 1 Arts, entertainment and recreation 2002 83730
## 2 Arts, entertainment and recreation 2003 87619
## 3 Arts, entertainment and recreation 2004 90838
## 4 Arts, entertainment and recreation 2005 90790
## 5 Arts, entertainment and recreation 2006 91562
## 6 Arts, entertainment and recreation 2007 93434
## 7 Arts, entertainment and recreation 2008 94049
## 8 Arts, entertainment and recreation 2009 94024
## 9 Arts, entertainment and recreation 2010 91980
## 10 Arts, entertainment and recreation 2011 92515
## 11 Arts, entertainment and recreation 2012 93126
## 12 Arts, entertainment and recreation 2013 92469
## 13 Arts, entertainment and recreation 2014 94026
## 14 Arts, entertainment and recreation 2015 101652
## 15 Arts, entertainment and recreation 2016 112399
## 16 Arts, entertainment and recreation 2017 114862
## 17 Arts, entertainment and recreation 2018 114857
## 18 Arts, entertainment and recreation 2019 119120
## 19 Arts, entertainment and recreation 2020 84254
## 20 Arts, entertainment and recreation 2021 80992
###This code snippet filters the original jobs data to create a new data
frame arts containing only entries for "Arts, entertainment and recreation"
jobs. It selects rows where the industry code ("North American Industry
Classification System (NAICS) 3") matches that specific category. The
resulting arts data frame has 20 years of data (one row per year) on jobs in
that industry.
## Saving 5 x 4 in image
###This time series plot visualizes an upward trend in Arts, Entertainment &
Recreation jobs from early 2000s to just above 2020.
### The x-axis represents years, and the y-axis likely represents jobs in
thousands.
###The graph shows there is an upward trend(not linear) of increasing jobs
until 2019 and there is a sharp decline in jobs in 2020 and further decline
in the coming year.
## Saving 5 x 4 in image