devplot: Plot deviance contributions from an MBNMA model

View source: R/plot.functions.R

devplotR Documentation

Plot deviance contributions from an MBNMA model

Description

Plot deviance contributions from an MBNMA model

Usage

devplot(
  mbnma,
  dev.type = "dev",
  plot.type = "box",
  xaxis = "time",
  facet = TRUE,
  n.iter = round(mbnma$BUGSoutput$n.iter/4),
  n.thin = mbnma$BUGSoutput$n.thin,
  ...
)

Arguments

mbnma

An S3 object of class "mbnma" generated by running a time-course MBNMA model

dev.type

Deviances to plot - can be either residual deviances ("resdev") or deviances ("dev", the default)

plot.type

Deviances can be plotted either as scatter points ("scatter" - using geom_point()) or as boxplots ("box", the default)

xaxis

A character object that indicates whether deviance contributions should be plotted by time ("time") or by follow-up count ("fup")

facet

A boolean object that indicates whether or not to facet by treatment

n.iter

The number of iterations to update the model whilst monitoring additional parameters (if necessary). Must be a positive integer. Default is the value used in mbnma.

n.thin

The thinning rate. Must be a positive integer. Default is the value used in mbnma.

...

Arguments to be sent to ggplot2::ggplot()

Details

Deviances should only be plotted for models that have converged successfully. If deviance contributions have not been monitored in mbnma$parameters.to.save then additional iterations will have to be run to get results for these.

Deviance contributions cannot be calculated for models with a multivariate likelihood (i.e. those that account for correlation between observations) because the covariance matrix in these models is treated as unknown (if rho="estimate") and deviance contributions will be correlated.

Value

Generates a plot of deviance contributions and returns a list containing the plot (as an object of class c("gg", "ggplot")), and a data.frame of posterior mean deviance/residual deviance contributions for each observation.

Examples


# Make network
alognet <- mb.network(alog_pcfb)

# Run MBNMA
mbnma <- mb.run(alognet, fun=tpoly(degree=2), intercept=FALSE)

# Plot residual deviance contributions in a scatterplot
devplot(mbnma)

# Plot deviance contributions in boxplots at each follow-up measurement
# Monitor for 500 additional iterations
devplot(mbnma, dev.type="dev", plot.type="box", xaxis="fup", n.iter=500)


MBNMAtime documentation built on Oct. 14, 2023, 5:08 p.m.