library(timetk)
## Warning: package 'timetk' was built under R version 4.3.3
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.3.3
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'readr' was built under R version 4.3.3
## Warning: package 'dplyr' was built under R version 4.3.3
## ── 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
## ✔ purrr   1.0.2     ✔ tidyr   1.3.0
## ── 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(magrittr)
## Warning: package 'magrittr' was built under R version 4.3.3
## 
## Attaching package: 'magrittr'
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## The following object is masked from 'package:tidyr':
## 
##     extract
library(dplyr)
bikeshare <- bike_sharing_daily %>% select(dteday,cnt) %>% set_names(c("date","value"))
bikeshare 
## # A tibble: 731 × 2
##    date       value
##    <date>     <dbl>
##  1 2011-01-01   985
##  2 2011-01-02   801
##  3 2011-01-03  1349
##  4 2011-01-04  1562
##  5 2011-01-05  1600
##  6 2011-01-06  1606
##  7 2011-01-07  1510
##  8 2011-01-08   959
##  9 2011-01-09   822
## 10 2011-01-10  1321
## # ℹ 721 more rows
bikeshare %>% plot_time_series(date,value, .interactive = TRUE, .plotly_slider = TRUE)
bikeshare %>% plot_time_series(date,value, .interactive = TRUE, .plotly_slider = TRUE, .facet_scales = "free", .smooth = FALSE, .color_var = month(date))
bikeshare %>% group_by(year(date)) %>% plot_seasonal_diagnostics(date, value, .x_lab='Date', .y_lab='# Users', .title='Bike Share User Data')
bikeshare %>% group_by(year(date)) %>% plot_anomaly_diagnostics(date, value)
## frequency = 7 observations per 1 week
## trend = 92 observations per 3 months
## frequency = 7 observations per 1 week
## trend = 92 observations per 3 months
outliers <- bikeshare %>% group_by(year(date)) %>% tk_anomaly_diagnostics(date, value) %>% filter(anomaly=='Yes')
## frequency = 7 observations per 1 week
## trend = 92 observations per 3 months
## frequency = 7 observations per 1 week
## trend = 92 observations per 3 months
View(outliers)