plot.magioutput: Generate plots from 'magioutput' object

View source: R/visualization.R

plot.magioutputR 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 magioutput object.

type

string; the default type = "traj" plots inferred trajectories, while setting type = "trace" generates diagnostic traceplots for the MCMC samples of the parameters and log-posterior values.

obs

logical; if true, points will be added on the plots for the observations when type = "traj".

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 type = "traj". If provided, should be the same length as the number of system components in X.

par.names

vector of parameter names, when type = "trace". If provided, should be the same length as the number of parameters in \theta, or the combined length of \theta and \sigma when sigma = TRUE.

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 ci = TRUE.

upper

the upper quantile of the credible band/interval, default is 0.975. Only used if ci = TRUE.

sigma

logical; if true, the noise levels \sigma will be included in the traceplots when type = "trace".

lp

logical; if true, the values of the log-posterior will be included in the traceplots when type = "trace".

nplotcol

the number of subplots per row.

...

additional arguments to plot.

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)


magi documentation built on April 26, 2023, 1:12 a.m.