phac-nml-phrsd / casteval

https://phac-nml-phrsd.github.io/casteval/
GNU General Public License v3.0
1 stars 0 forks source link

date format in `plot_forecast()` #13

Closed papsti closed 2 months ago

papsti commented 2 months ago

originally documented by @davidchampredon as follows:

when defining a forecast with dates, it would be better to have the dates displayed by plot_forecast() formatted as dates (e.g., dd-mm-yy) not integers (e.g., 199940) as it is now.

papsti commented 2 months ago

daniel and i think this could be a bug. a reproducible example would be great.

davidchampredon commented 2 months ago

MRE:


library(casteval)
library(lubridate)
packageVersion('casteval')

set.seed(1234)

# Retrieve forecast outputs from model
a = readRDS('fcstobj-all-2024-08-22-1158.rds')  # RDS file sent separately
x = a$clha$COVIDAB2024$fcst.obj$simfwd.aggr$H.aggr
timevec = x[[1]]$date
n = length(timevec)
str(timevec)

# Create data formatted for `casteval`
xx = list()
for(i in seq_along(x)){
  xx[[i]] = x[[i]]$value
}
dat = list(
  time = ymd(timevec),
  vals = xx
)

# `casteval` object
fc = create_forecast(dat = dat)

# Make up observations
obs = data.frame(
  time = ymd(timevec),
  val_obs = round(80 - 80/25 * c(1:n) + rnorm(n, sd = 3))
)
obs

g = plot_forecast(fcst = fc, 
                  obs = obs, 
                  score = log_score, 
                  quant_intervals = c(20, 80))

ga = plot_forecast(fcst = fc, 
                   obs = obs, 
                   score = accuracy, 
                   quant_pairs = c(20, 80))
plot(g )
plot(ga)
# x-axis dates are not well formatted

image