plot.magioutput {magi} | R Documentation |
Generate plots from magioutput
object
Description
Plots inferred system trajectories or diagnostic traceplots from the output of MagiSolver
Usage
## S3 method for class 'magioutput'
plot(
x,
type = "traj",
obs = TRUE,
ci = TRUE,
ci.col = "skyblue",
comp.names,
par.names,
est = "mean",
lower = 0.025,
upper = 0.975,
sigma = FALSE,
lp = TRUE,
nplotcol = 3,
...
)
Arguments
x |
a |
type |
string; the default |
obs |
logical; if true, points will be added on the plots for the observations when |
ci |
logical; if true, credible bands/intervals will be added to the plots. |
ci.col |
string; color to use for credible bands. |
comp.names |
vector of system component names, when |
par.names |
vector of parameter names, when |
est |
string specifying the posterior quantity to plot as the estimate. Can be "mean", "median", "mode", or "none". Default is "mean", which plots the posterior mean of the MCMC samples. |
lower |
the lower quantile of the credible band/interval, default is 0.025. Only used if |
upper |
the upper quantile of the credible band/interval, default is 0.975. Only used if |
sigma |
logical; if true, the noise levels |
lp |
logical; if true, the values of the log-posterior will be included in the traceplots when |
nplotcol |
the number of subplots per row. |
... |
additional arguments to |
Details
Plots the inferred system trajectories (when type = "traj"
) or diagnostic traceplots of the parameters and log-posterior (when type = "trace"
) from the MCMC samples.
By default, the posterior mean is treated as the estimate of the trajectories and parameters (est = "mean"
).
Alternatives are the posterior median (est = "median"
, taken component-wise) and the posterior mode (est = "mode"
, approximated by the MCMC sample with the highest log-posterior value).
The default type = "traj"
produces plots of the inferred trajectories and credible bands from the MCMC samples, one subplot for each system component.
By default, lower = 0.025
and upper = 0.975
produces a central 95% credible band when ci = TRUE
.
Adding the observed data points (obs = TRUE
) can provide a visual assessment of the inferred trajectories.
Setting type = "trace"
generates diagnostic traceplots for the MCMC samples of the system parameters and the values of the log-posterior, which is a useful tool for informally assessing convergence.
In this case, the est
and ci
options add horizontal lines to the plots that indicate the estimate (in red) and credible interval (in green) for each parameter.
Examples
# Set up odeModel list for the Fitzhugh-Nagumo equations
fnmodel <- list(
fOde = fnmodelODE,
fOdeDx = fnmodelDx,
fOdeDtheta = fnmodelDtheta,
thetaLowerBound = c(0, 0, 0),
thetaUpperBound = c(Inf, Inf, Inf)
)
# Example FN data
data(FNdat)
y <- setDiscretization(FNdat, by = 0.25)
# Create magioutput from a short MagiSolver run (demo only, more iterations needed for convergence)
result <- MagiSolver(y, fnmodel, control = list(nstepsHmc = 20, niterHmc = 500))
# Inferred trajectories
plot(result, comp.names = c("V", "R"), xlab = "Time", ylab = "Level")
# Parameter trace plots
plot(result, type = "trace", par.names = c("a", "b", "c", "sigmaV", "sigmaR"), sigma = TRUE)