# NOT RUN {
## formating the data frame for pandemic_model function
#loading data
data <- covid19BH
data
names(data)
#re-order data in ascending order
class(data$date)
data$date = as.Date(data$date)
class(data$date)
data <- data[order(data$date), ]
head(data)
# building the Y list required
start <- data$date[1]
end <- data$date[nrow(data)]
cases <- data$last_available_confirmed
new_cases <- data$new_confirmed
deaths <- data$last_available_deaths
new_deaths <- data$new_deaths
pop <- data$estimated_population_2019[1]
Y <- format_data(s_date = start, e_date = end,
cases = cases, n_cases = new_cases,
deaths = deaths, n_deaths = new_deaths,
name = "Belo Horizonte/MG", pop = pop)
Y
plot(Y)
## fitted model:
##pandemic_model function may take a few minutes...
# }
# NOT RUN {
outputBH = pandemic_model(Y, control = list(max_treedepth = 50, adapt_delta = 0.999))
outputBH
summary(outputBH)
##convergence diagnostics
traceplot(outputBH)
density(outputBH)
stan_ac(outputBH$fit, pars = c("a","b","c","f"))
## making predictions
predictions = posterior_predict(outputBH)
## calculating prediction intervals and statistics
stats = pandemic_stats(predictions)
## plotting results
plot(predictions)
# }
Run the code above in your browser using DataLab