Type: | Package |
Title: | Thresholds and Invariant Intervals for Network Meta-Analysis |
Version: | 0.1.6 |
Description: | Calculation and presentation of decision-invariant bias adjustment thresholds and intervals for Network Meta-Analysis, as described by Phillippo et al. (2018) <doi:10.1111/rssa.12341>. These describe the smallest changes to the data that would result in a change of decision. |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | TRUE |
Imports: | nnls, grid, gridExtra, gtable, Matrix, ggplot2 |
Depends: | R (≥ 3.1.0) |
RoxygenNote: | 7.1.0 |
Suggests: | knitr, rmarkdown, coda |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2020-06-11 13:57:46 UTC; dp14189 |
Author: | David Phillippo [aut, cre] |
Maintainer: | David Phillippo <david.phillippo@bristol.ac.uk> |
Repository: | CRAN |
Date/Publication: | 2020-06-11 14:30:02 UTC |
Posterior covariance matrix from Social Anxiety NMA
Description
The posterior covariance matrix of the variables d
(basic treatment
effect parameters) and delta
(shrunken random effects estimates for
each study).
Usage
SocAnx.post.cov
Format
An object of class matrix
(inherits from array
) with 186 rows and 186 columns.
Source
Generated from WinBUGS output, using the WinBUGS code from
Mayo-Wilson et al. (2014). See also vignette("Examples", package =
"nmathresh")
.
References
Mayo-Wilson E, Dias S, Mavranezouli I, Kew K, Clark DM, Ades AE, et al. Psychological and pharmacological interventions for social anxiety disorder in adults: a systematic review and network meta-analysis. Lancet Psychiatry 2014;1:368-76. http://dx.doi.org/10.1016/S2215-0366(14)70329-3
See Also
Posterior summary from Social Anxiety NMA
Description
A summary.mcmc
object of the type produced by the coda
package,
containing the requisite posterior summary information on the variables
d
(basic treatment effect parameters), delta
(shrunken random
effects estimates for each study), and diff
(contrasts of treatment
effect parameters).
Usage
SocAnx.post.summary
Format
A summary.mcmc
object. The key components for our use are:
- statistics
Matrix containing the posterior summary statistics of the variables
d
,delta
, anddiff
, with columns forMean
,SD
,Naive SE
, andTime-series SE
(also known as the Monte-Carlo standard error)- quantiles
Matrix containing the posterior 2.5%, 25%, 50%, 75%, and 97.5% quantiles of the variables
d
,delta
, anddiff
Source
Generated from WinBUGS output, using the WinBUGS code from
Mayo-Wilson et al. (2014). See also vignette("Examples", package =
"nmathresh")
.
References
Mayo-Wilson E, Dias S, Mavranezouli I, Kew K, Clark DM, Ades AE, et al. Psychological and pharmacological interventions for social anxiety disorder in adults: a systematic review and network meta-analysis. Lancet Psychiatry 2014;1:368-76. http://dx.doi.org/10.1016/S2215-0366(14)70329-3
See Also
Posterior covariance matrix from Thrombolytics NMA
Description
The posterior covariance matrix of the basic treatment effect parameters.
Usage
Thrombo.post.cov
Format
An object of class matrix
(inherits from array
) with 5 rows and 5 columns.
Source
Generated from WinBUGS output, using the WinBUGS code from Caldwell
et al. (2005). See also vignette("Examples", package = "nmathresh")
.
References
Caldwell DM, Ades AE, Higgins JPT. Simultaneous comparison of multiple treatments: combining direct and indirect evidence. Brit Med J 2005;331:897-900. http://dx.doi.org/10.1136/bmj.331.7521.897
See Also
Posterior summary from Thrombolytics NMA
Description
A summary.mcmc
object of the type produced by the coda
package,
containing the requisite posterior summary information on the variables
dd
, the contrasts of the treatment effect parameters.
Usage
Thrombo.post.summary
Format
A summary.mcmc
object. The key components for our use are:
- statistics
Matrix containing the posterior summary statistics, with columns for
Mean
,SD
,Naive SE
, andTime-series SE
(also known as the Monte-Carlo standard error)- quantiles
Matrix containing the posterior 2.5%, 25%, 50%, 75%, and 97.5% quantiles
Source
Generated from WinBUGS output, using the WinBUGS code from Caldwell
et al. (2005). See also vignette("Examples", package = "nmathresh")
.
References
Caldwell DM, Ades AE, Higgins JPT. Simultaneous comparison of multiple treatments: combining direct and indirect evidence. Brit Med J 2005;331:897-900. http://dx.doi.org/10.1136/bmj.331.7521.897
See Also
summary.mcmc
, Thrombo.post.cov
Convert contrast indexing
Description
Functions for converting between d_{ab}
indexing of contrasts (useful
notationally) and d[i]
indexing used by R.
Usage
d_ab2i(a, b, K)
d_i2ab(i, K)
Arguments
a |
Vector of treatment codes |
b |
Vector of treatment codes |
K |
Total number of treatments. |
i |
Vector of indices |
Value
d_ab2i
returns a vector of indices i
. d_i2ab
returns a data frame of indices a
and b
.
Functions
-
d_ab2i
: Convertd[i]
type indices tod_{ab}
type indices. -
d_i2ab
: Convertd_{ab}
type indices tod[i]
type indices.
Note
By convention, 1 \le a < b \le K
. If this is not the case, an
error will be thrown. For a given number of treatments K
, the total
number of possible contrasts d_{ab}
is K(K-1)/2
, and hence
i \le K
. Again, if this is not the case, an error will be thrown.
Examples
d_ab2i(c(1,1,1, 2,2, 3), c(2,3,4, 3,4, 4), K=4)
d_i2ab(1:6, K=4)
Get thresholds from U matrix
Description
Return the positive and negative thresholds for an observation, given a
vector of possible threshold solutions. This function is intended for
internal use, and is called by nma_thresh
automatically.
Usage
get.int(
x,
kstar,
trt.code,
contrs,
mcid = FALSE,
mean.dk = NULL,
inflmat = NULL,
opt.max = NULL
)
Arguments
x |
Column of |
kstar |
Base-case optimal treatment. |
trt.code |
Vector of (possibly recoded) treatments. See
|
contrs |
Details of contrasts corresponding to rows in |
mcid |
Use MCID decision rule? Default |
mean.dk |
Posterior means of basic treatment parameters, required when
|
inflmat |
Column of influence matrix |
opt.max |
Is the maximum treatment effect optimal? See
|
Value
Data frame of thresholds and new optimal treatments with columns
lo
, lo.newkstar
, hi
, and hi.newkstar
.
Calculate thresholds and invariant intervals
Description
This function calculates decision-invariant bias-adjustment thresholds and intervals for Bayesian network meta-analysis, as described by Phillippo et al. (2018). Thresholds are derived from the joint posterior, and reflect the amount of change to a data point before the treatment decision changes. Calculation is achieved using fast matrix operations.
Usage
nma_thresh(
mean.dk,
lhood,
post,
nmatype = "fixed",
X = NULL,
mu.design = NULL,
delta.design = NULL,
opt.max = TRUE,
trt.rank = 1,
trt.code = NULL,
trt.sub = NULL,
mcid = 0,
mcid.type = "decision"
)
Arguments
mean.dk |
Posterior means of basic treatment parameters |
lhood |
Likelihood (data) covariance matrix. |
post |
Posterior covariance matrix (see details). |
nmatype |
Character string, giving the type of NMA performed. One of "fixed" (fixed effects, the default) or "random" (random effects). May be abbreviated. |
X |
[FE models only] Design matrix for basic treatment parameters. |
mu.design |
[RE models only] Design matrix for any extra parameters.
Defaults to |
delta.design |
[RE models only] Design matrix for delta, defaults to the
|
opt.max |
Should the optimal decision be the maximal treatment effect
( |
trt.rank |
Rank of the treatment to derive thresholds for. Defaults to 1, thresholds for the optimum treatment. |
trt.code |
Treatment codings of the reference treatment and in the
parameter vector |
trt.sub |
Only look at thresholds in this subset of treatments in
|
mcid |
Minimal clinically important difference for the decision (when
|
mcid.type |
Default |
Details
This function provides bias-adjustment threshold analysis for both
fixed and random effects NMA models, as described by Phillippo et
al. (2018). Parameters mean.dk
, lhood
, and
post
are always required, however there are differences in the
specification of post
and other required parameters and between the
fixed and random effects cases:
- FE models
The design matrix
X
for basic treatment parameters is required. The posterior covariance matrix specified inpost
should only refer to the basic treatment parameters.- RE models
The design matrix
mu.design
for additional parameters (e.g. covariates) is required, as is the design matrixdelta.design
for random effects terms. The posterior covariance matrix specified inpost
should refer to the basic treatment parameters, RE terms, and additional parameters in that order; i.e.post
should be the posterior covariance matrix of the vector(d^T, \delta^T, \mu^T)^T
.
Value
An object of class thresh
.
Model details
The FE NMA model
The fixed effects NMA model is assumed to be of the form
- Prior:
d \sim \mathrm{N} ( d_0, \Sigma_d )
- Likelihood:
y|d \sim \mathrm{N} ( \delta, V )
- FE model:
\delta = Xd + M\mu
The additional parameters \mu
may be given any sensible prior; they
do not affect the threshold analysis in any way.
The RE NMA model
The random effects NMA model is assumed to be of the form
- Priors:
d \sim \mathrm{N} ( d_0, \Sigma_d ), \quad \mu \sim \mathrm{N} ( \mu_0, \Sigma_\mu )
- Likelihood:
y|d,\mu,\tau^2 \sim \mathrm{N} ( L\delta + M\mu, V )
- RE model:
\delta \sim \mathrm{N} ( Xd, \tau^2 )
The between-study heterogeneity parameter \tau^2
may be given any
sensible prior. In the RE case, the threshold derivations make the
approximation that \tau^2
is fixed and known.
Decision rules
The default decision rule is maximal efficacy; the optimal treatment is
k^* = \mathrm{argmax}_k \mathrm{E}(d_{k})
.
When \epsilon
= mcid
is greater than zero and
mcid.type = 'decision'
, the decision rule is no longer for a single
best treatment, but is based on minimal clinically important difference. A
treatment is in the optimal set if \mathrm{E}(d_k) \ge
\epsilon
and \max_a \mathrm{E}(d_a) -
\mathrm{E}(d_k) \le \epsilon
.
When mcid.type = 'change'
, the maximal efficacy rule is used, but
thresholds are found for when a new treatment is better than the base-case
optimal by at least mcid
.
See Also
recon_vcov
, thresh_forest
,
thresh-class
.
Examples
# Please see the vignette "Examples" for worked examples including use of
# this function, including more information on the brief code below.
vignette("Examples", package = "nmathresh")
### Contrast level thresholds for Thrombolytic treatments NMA
K <- 6 # Number of treatments
# Contrast design matrix is
X <- matrix(ncol = K-1, byrow = TRUE,
c(1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, -1, 1, 0, 0,
0, -1, 0, 1, 0,
0, -1, 0, 0, 1))
# Reconstruct hypothetical likelihood covariance matrix using NNLS
lik.cov <- recon_vcov(Thrombo.post.cov, prior.prec = .0001, X = X)
# Thresholds are then
thresh <- nma_thresh(mean.dk = Thrombo.post.summary$statistics[1:(K-1), "Mean"],
lhood = lik.cov,
post = Thrombo.post.cov,
nmatype = "fixed",
X = X,
opt.max = FALSE)
Reconstruct likelihood covariance matrix
Description
Reconstruct the contrast-level likelihood covariance matrix from prior and
posterior covariance matrices. The resulting likelihood covariance matrix can
then be used to perform a contrast-level threshold analysis with the function
nma_thresh
.
Usage
recon_vcov(
post,
prior.prec = 1e-04,
prior.vcov = diag(1/prior.prec, dim(post)[1]),
X = NULL,
verbose = FALSE
)
Arguments
post |
Posterior covariance matrix. |
prior.prec |
Prior precision. Defaults to .0001 which is a common flat
prior for NMA. Not used if |
prior.vcov |
Prior covariance matrix. Defaults to a diagonal matrix of
the same size as post, with elements |
X |
Contrast design matrix. If omitted a complete network is assumed. |
verbose |
Print intermediate matrices? Defaults to |
Details
Full details of the calculation are given by Phillippo et al.
(2018). Briefly, the aim is to recover the contrast-level likelihood
covariance matrix V
that would have led to the posterior covariance
matrix \Sigma
being obtained from a fixed effects NMA, with design
matrix X
and prior covariance matrix \Sigma_d
for a normal
prior on the basic treatment parameters. This is possible in this case via
the equation (resulting from conjugacy):
\Sigma^{-1} = X^TV^{-1}X + \Sigma_d^{-1}.
When the treatment network is complete (i.e. fully connected), this equation may be rearranged exactly.
When the treatment network is incomplete (i.e. not all treatments are directly compared), this equation may be solved through the use of non-negative least squares (NNLS).
When NNLS is used, some additional diagnostics are printed (and returned as attributes). Firstly, the residual sum-of-squares (RSS) from the NNLS fit. The RSS is further split into fixed RSS, from structural zeros in the reconstructed posterior according to the design matrix (and hence not fitted) that are non-zero in the true posterior, and fitted RSS, from the other fitted elements. Secondly, the Kullback-Leibler divergence of the reconstructed posterior from the true posterior. Interpreting the KL divergence as a log Bayes factor, values less than 1 indicate negligible differences between the reconstructed posterior from the true posterior, whilst values greater than 3 indicate considerable differences.
Value
A matrix; the reconstructed likelihood covariance matrix. If NNLS is
used, the residual sum-of-squares and Kullback-Leibler divergence
diagnostics (as printed to the console) are returned as additional
attributes rss.total
, rss.fixed
, rss.free
,
kl.divergence
.
See Also
Examples
# Please see the vignette "Examples" for worked examples including use of
# this function, including more information on the brief code below.
vignette("Examples", package = "nmathresh")
### Contrast level thresholds for Thrombolytic treatments NMA
K <- 6 # Number of treatments
# Contrast design matrix is
X <- matrix(ncol = K-1, byrow = TRUE,
c(1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, -1, 1, 0, 0,
0, -1, 0, 1, 0,
0, -1, 0, 0, 1))
# Reconstruct hypothetical likelihood covariance matrix using NNLS
lik.cov <- recon_vcov(Thrombo.post.cov, prior.prec = .0001, X = X)
The thresh class
Description
The function nmathresh
returns S3 objects of class thresh
.
Details
Objects of class thresh
have the following components:
thresholds
A data frame with columns
lo
andhi
for the lower and upper thresholds, andlo.newkstar
andhi.newkstar
for the new optimal (or rank-trt.rank
) treatments at each of the thresholds.U
The threshold solutions matrix. One column for each data point
m
, one row for each contrastd_{ab}
(in ascending order). The elementsU_{ab,m}
describe the amount of adjustment to data pointy_m
required to reverse the relative ranking of treatmentsa
andb
. This matrix is particularly useful for deriving thresholds for more complex decisions (e.g. bias-adjustment thresholds for a new treatment entering the top two, for any change in rank of the top three, etc.)Ukstar
The threshold solutions matrix limited to contrasts involving
k^*
. In other words, the rows ofU
corresponding to contrasts of the formd_{ak^*}
ord_{k^*a}
. ElementsU_{ak^*,m}
of this matrix describe the amount of adjustment to data pointy_m
required to make treatmenta
optimal (or rank-trt.rank
) overk^*
.H
The influence matrix of the data on the basic treatment parameters. One column for each data point
m
, one row for each basic treatment parameterd_k
. ElementsH_{k,m}
describe the influence of data pointy_m
on parameterd_k
. This matrix can be used to derive more complex thresholds (e.g. 2D thresholds for simultaneous adjustments to two data points, or thresholds for common adjustments to a group of data points).kstar
The base-case optimal (or rank-
trt.rank
) treatmentk^*
.call
A list containing all the arguments defined in the original call to
nma_thresh
.
See Also
Producing two-dimensional invariant regions
Description
This function produces two-dimensional threshold lines and invariant regions, as shown by Phillippo et al. (2018).
Usage
thresh_2d(
thresh,
idx,
idy,
xlab = paste("Adjustment to data point", idx),
ylab = paste("Adjustment to data point", idy),
xlim = NULL,
ylim = NULL,
breaks = waiver(),
xbreaks = breaks,
ybreaks = breaks,
fill = rgb(0.72, 0.8, 0.93, 0.7),
lwd = 1,
fontsize = 12
)
Arguments
thresh |
A |
idx |
Integer specifying the index (with respect to
|
idy |
Integer specifying the index (with respect to
|
xlab |
Character string giving the label for the x axis. |
ylab |
Character string giving the label for the y axis. |
xlim |
Numeric vector of length 2, giving the x axis limits. |
ylim |
Numeric vector of length 2, giving the y axis limits. |
breaks |
Numeric vector giving position of tick marks on the x and y axes. Calculated automatically by default. |
xbreaks |
Numeric vector giving position of tick marks on the x axis.
Equal to |
ybreaks |
Numeric vector giving position of tick marks on the y axis.
Equal to |
fill |
Fill colour for invariant region. Defaults to a nice shade of
blue |
lwd |
Line width for threshold lines. Default 1. |
fontsize |
Font size for labels. Default 12. |
Value
A ggplot
object containing the 2D threshold plot, which is
returned invisibly and plotted (unless assigned).
Examples
# Please see the vignette "Examples" for worked examples including use of
# this function, including more information on the brief code below.
vignette("Examples", package = "nmathresh")
### Contrast level thresholds for Thrombolytic treatments NMA
K <- 6 # Number of treatments
# Contrast design matrix is
X <- matrix(ncol = K-1, byrow = TRUE,
c(1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, -1, 1, 0, 0,
0, -1, 0, 1, 0,
0, -1, 0, 0, 1))
# Reconstruct hypothetical likelihood covariance matrix using NNLS
lik.cov <- recon_vcov(Thrombo.post.cov, prior.prec = .0001, X = X)
# Thresholds are then
thresh <- nma_thresh(mean.dk = Thrombo.post.summary$statistics[1:(K-1), "Mean"],
lhood = lik.cov,
post = Thrombo.post.cov,
nmatype = "fixed",
X = X,
opt.max = FALSE)
# Produce an invariant region for simultaneous adjustments to both arms of Study 1
thresh_2d(thresh, 1, 2,
xlab = "Adjustment in Study 1 LOR: 3 vs. 1",
ylab = "Adjustment in Study 1 LOR: 4 vs. 1",
xlim = c(-1.5, 0.5), ylim = c(-2, 14),
ybreaks = seq(-2, 14, 2))
Producing threshold forest plots
Description
This function produces threshold forest plots, overlaying the decision-invariant intervals on the data points and their confidence/credible intervals, as shown by Phillippo et al. (2018).
Usage
thresh_forest(
thresh,
y,
CI.lo,
CI.hi,
label,
orderby = NULL,
data = NULL,
CI.title = "95% Confidence Interval",
label.title = "",
y.title = "Mean",
II.title = "Invariant Interval",
xlab = "",
xlim = NULL,
sigfig = 3,
digits = NULL,
refline = NULL,
clinsig = NULL,
cutoff = NULL,
II.colw = rgb(0.72, 0.8, 0.93),
II.cols = rgb(0.93, 0.72, 0.8),
II.lwd = 8,
CI.lwd = 1,
pointsize = 4,
fontsize = 12,
xbreaks = NULL,
add.columns = NULL,
add.columns.title = NULL,
add.columns.after = -1,
add.columns.hjust = 0.5,
add.columns.uline = TRUE,
calcdim = display,
display = TRUE
)
Arguments
thresh |
A |
y |
Data points. Either a column of |
CI.lo |
Confidence/credible interval lower limits. Either a column of
|
CI.hi |
Confidence/credible interval upper limits. Either a column of
|
label |
Row labels (for each data point). Either a column of
|
orderby |
Variable(s) to order the table rows by. Either a column or
columns of |
data |
A data frame containing the data points |
CI.title |
Title for CI column, default "95% Confidence Interval". |
label.title |
Character string giving the heading for the row labels column. |
y.title |
Character string giving the heading for the data points column, default "Mean". |
II.title |
Title for invariant interval column, default "Invariant Interval". |
xlab |
Character string giving the label for the |
xlim |
Numeric vector (length 2) of lower and upper limits for the
|
sigfig |
Number of significant digits to display in the table. Default 3. |
digits |
Number of decimal places to display in the table. Overrides
|
refline |
|
clinsig |
Set the clinical significance level. Rows are marked with a dagger if they have one or more thresholds less than this value. Not set by default. |
cutoff |
A single numeric value or numeric vector pair. Thresholds larger in magnitude than this value, or lying outside this interval, will be cut off and marked as NT (no threshold). Not set by default. |
II.colw |
Colour for "wide" invariant intervals. |
II.cols |
Colour for "short" invariant intervals. |
II.lwd |
Line width of invariant intervals. Default 8. |
CI.lwd |
Line width of confidence/credible intervals. Default 1. |
pointsize |
Point size for forest plot means. Default 4. |
fontsize |
Base font size. Default 12. |
xbreaks |
Position of tick marks on the |
add.columns |
Data frame (or matrix, vector) of additional columns to add to table. |
add.columns.title |
Optional titles for the additional columns, otherwise use names from provided data. |
add.columns.after |
Which column to add the new columns after? Default adds the columns to the far right. |
add.columns.hjust |
Vector of horizontal justifications for the new
columns, from |
add.columns.uline |
Underline the header of the new columns? Default
|
calcdim |
Logical, calculate suggested output dimensions for saving to
pdf? Calculates output size when |
display |
Logical, display the plot? Defaults to |
Value
Displays the forest plot on the current plot device (if display
= TRUE
). Also returns invisibly the underlying gtable
object, which
can be further manipulated.
Examples
# Please see the vignette "Examples" for worked examples including use of
# this function, including more information on the brief code below.
vignette("Examples", package = "nmathresh")
### Contrast level thresholds for Thrombolytic treatments NMA
K <- 6 # Number of treatments
# Contrast design matrix is
X <- matrix(ncol = K-1, byrow = TRUE,
c(1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, -1, 1, 0, 0,
0, -1, 0, 1, 0,
0, -1, 0, 0, 1))
# Reconstruct hypothetical likelihood covariance matrix using NNLS
lik.cov <- recon_vcov(Thrombo.post.cov, prior.prec = .0001, X = X)
# Thresholds are then
thresh <- nma_thresh(mean.dk = Thrombo.post.summary$statistics[1:(K-1), "Mean"],
lhood = lik.cov,
post = Thrombo.post.cov,
nmatype = "fixed",
X = X,
opt.max = FALSE)
# Get treatment codes for the contrasts with data
d.a <- d.b <- vector(length = nrow(X))
for (i in 1:nrow(X)){
d.a[i] <- ifelse(any(X[i, ] == -1), which(X[i, ] == -1), 0) + 1
d.b[i] <- ifelse(any(X[i, ] == 1), which(X[i, ] == 1), 0) + 1
}
# Transform from d_ab style contrast references into d[i] style from the full set of contrasts
# for easy indexing in R
d.i <- d_ab2i(d.a, d.b, K = 6)
# Create plot data
plotdat <- data.frame(lab = paste0(d.b, " vs. ", d.a),
contr.mean = Thrombo.post.summary$statistics[d.i, "Mean"],
CI2.5 = Thrombo.post.summary$quantiles[d.i, "2.5%"],
CI97.5 = Thrombo.post.summary$quantiles[d.i, "97.5%"])
# Plot
thresh_forest(thresh, contr.mean, CI2.5, CI97.5, label = lab, data = plotdat,
label.title = "Contrast", xlab = "Log Odds Ratio", CI.title = "95% Credible Interval",
xlim = c(-.3, .3), refline = 0, digits = 2)