Plot mvgam posterior predictions for a specified series
Source:R/plot_mvgam_fc.R
plot_mvgam_forecasts.Rd
Plot mvgam posterior predictions for a specified series
Usage
plot_mvgam_fc(
object,
series = 1,
newdata,
data_test,
realisations = FALSE,
n_realisations = 15,
hide_xlabels = FALSE,
xlab,
ylab,
ylim,
n_cores = 1,
return_forecasts = FALSE,
return_score = FALSE,
...
)
# S3 method for mvgam_forecast
plot(
x,
series = 1,
realisations = FALSE,
n_realisations = 15,
hide_xlabels = FALSE,
xlab,
ylab,
ylim,
return_score = FALSE,
...
)
Arguments
- object
list
object returned frommvgam
. Seemvgam()
- series
integer
specifying which series in the set is to be plotted- newdata
Optional
dataframe
orlist
of test data containing at least 'series' and 'time' in addition to any other variables included in the linear predictor of the originalformula
. If included, the covariate information innewdata
will be used to generate forecasts from the fitted model equations. If this samenewdata
was originally included in the call tomvgam
, then forecasts have already been produced by the generative model and these will simply be extracted and plotted. However if nonewdata
was supplied to the original model call, an assumption is made that thenewdata
supplied here comes sequentially after the data supplied asdata
in the original model (i.e. we assume there is no time gap between the last observation of series 1 indata
and the first observation for series 1 innewdata
). Ifnewdata
contains observations in columny
, these observations will be used to compute a Discrete Rank Probability Score for the forecast distribution- data_test
Deprecated. Still works in place of
newdata
but users are recommended to usenewdata
instead for more seamless integration intoR
workflows- realisations
logical
. IfTRUE
, forecast realisations are shown as a spaghetti plot, making it easier to visualise the diversity of possible forecasts. IfFALSE
, the default, empirical quantiles of the forecast distribution are shown- n_realisations
integer
specifying the number of posterior realisations to plot, ifrealisations = TRUE
. Ignored otherwise- hide_xlabels
logical
. IfTRUE
, no xlabels are printed to allow the user to add custom labels usingaxis
from baseR
- xlab
label for x axis.
- ylab
label for y axis.
- ylim
Optional
vector
of y-axis limits (min, max)- n_cores
integer
specifying number of cores for generating forecasts in parallel- return_forecasts
logical
. IfTRUE
, the function will plot the forecast as well as returning the forecast object (as amatrix
of dimensionn_samples
xhorizon
)- return_score
logical
. IfTRUE
and out of sample test data is provided asnewdata
, a probabilistic score will be calculated and returned. The score used will depend on the observation family from the fitted model. Discrete families (poisson
,negative binomial
,tweedie
) use the Discrete Rank Probability Score. Other families use the Continuous Rank Probability Score. The value returned is thesum
of all scores within the out of sample forecast horizon- ...
further
par
graphical parameters.- x
Object of class
mvgam_forecast
Value
A base R
graphics plot and an optional list
containing the forecast distribution
and the out of sample probabilistic forecast score
Details
plot_mvgam_fc
generates posterior predictions from an object of class mvgam
, calculates posterior
empirical quantiles and plots them against the observed data. If realisations = FALSE
, the returned plot shows
90, 60, 40 and 20 percent posterior quantiles (as ribbons of increasingly darker shades or red)
as well as the posterior median (as a dark red line). If realisations = FALSE
, a set of n_realisations
posterior
draws are shown.
plot.mvgam_forecast
takes an object of class mvgam_forecast
, in which forecasts have already
been computed, and plots the resulting forecast distribution.
If realisations = FALSE
, these posterior quantiles are plotted along
with the true observed data that was used to train the model. Otherwise, a spaghetti plot is returned
to show possible forecast paths.