# NOT RUN {
data(cricket)
library(tsibble)
library(dplyr)
library(ggplot2)
# convert data set to a tsibble ----
cricket_tsibble <- cricket %>%
mutate(data_index = row_number()) %>%
as_tsibble(index = data_index)
# set the hierarchy of the units in a table ----
hierarchy_model <- tibble::tibble(
units = c("index", "over", "inning", "match"),
convert_fct = c(1, 20, 2, 1)
)
# Compute granularities ----
cricket_tsibble %>%
create_gran("over_inning",
hierarchy_model)
# Visualise distribution of runs across granularities ----
cricket_tsibble %>%
filter(batting_team %in% c("Mumbai Indians",
"Chennai Super Kings"))%>%
prob_plot("inning", "over",
hierarchy_model,
response = "runs_per_over",
plot_type = "lv")
# }
Run the code above in your browser using DataLab