Closed nikosbosse closed 11 months ago
@seabbs @sbfnk @Bisaloo
Decisions taken:
we have
new_forecast(data, forecast_type)
validate_forecast()
with methods corresponding to the different classesas_forecast()
that
Illustration:
as_forecast
isn't fully generic, i.e. hard for other users to work with who would want to create new classes. But I think that's fine for now / don't have a good idea for how to make it better in a non-crazy way.
Every class gets a print method that provides useful information on the output.
Please reopen if you disagree with anything.
This issue collects all questions surrounding the workflow to create and validate forecast objects.
Overall questions
Old behaviour (before the update)
Previously, we had a function
check_forecasts()
thatscoringutils_check
, which was a list with different componentsdata[, lapply(.SD, FUN = function(x) length(unique(x))), by = "model"]
print.scoringutils_check()
that made the output look niceThere were several potential worklflows:
data |> check_forecasts()
--> get infodata |> check_forecasts() |> score()
--> just run in pipelinedats |> score()
--> call tocheck_forecasts()
would happen internally withinscore()
New behaviour
What functions should exist?
Advanced R suggests that every class should have
Usually,
Other things that I've seen:
is.myclass()
andis_myclass()
as a test function that returnsTRUE
orFALSE
as.myclass()
andas_myclass()
which is I guess the helper function?Proposal:
(this now assumes that the classes are going to be called
forecast_something
, see #473Have a constructor,
new_forecast(forecast_type)
that constructs an object of classforecast_[target_type]
. itHave a (validator? check function?) generic called
is_forecast()
is_forecast()
.default() just returnsFALSE
is_forecast.forecast_binary
etc. runs input checks to validate the input. If all is well it returnsTRUE
. Otherwise it errors.Have a helper function
as_forecast()
. Itnew_forecast()
is_forecast()
[x] Q1: Given that Hadley et al. suggest to have the validator be called
validate_myclass
, should we call itvalidate_forecast()
(returning the validated object) instead ofis_forecast()
(returningTRUE
/FALSE
)? Should we have both?is_forecast()
could wrapvalidate_forecast()
[x] Q2: which of these functions should be exported?
[x] Q3: Should the validator function add messages / warnings as an attribute similar to what
check_forecasts()
did? In addition to throwing them of course.Output diagnostics
The proposal above currently does not capture everything the old
check_forecasts()
did. In particular, it doesn't provide output diagnostics.We could likely get much of the desired behaviour by creating a print method for
forecast_binary
etc. This print method could then use the stored attributes to return something likeAnd then when the forecast is summarised or if other attributes are added, these could be added to the output as well
This doesn't give us everything the old
check_forecasts()
had. E.g. it doesn't give us a list (which is probably easier to access than the attributes). It also doesn't give us theunique_values
component that the oldcheck_forecasts()
had. I did like that, but it can also just be an extra function.diagnose
or something like that.