thresh_forest: Producing threshold forest plots

Description Usage Arguments Value Examples

View source: R/thresh_forest.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 thresh object, as produced by nma_thresh.

y

Data points. Either a column of data, or a numeric vector.

CI.lo

Confidence/credible interval lower limits. Either a column of data, or a numeric vector.

CI.hi

Confidence/credible interval upper limits. Either a column of data, or a numeric vector.

label

Row labels (for each data point). Either a column of data, or a character vector.

orderby

Variable(s) to order the table rows by. Either a column or columns of data, or a vector. By default, the rows are not reordered. Further arguments and/or multiple ordering columns may be passed to the function order by instead providing a list containing the arguments to order.

data

A data frame containing the data points y, confidence/credible intervals (CI.lo, CI.hi), and row labels labels. If data is not provided, the above variables will be searched for in the calling environment.

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 x-axis.

xlim

Numeric vector (length 2) of lower and upper limits for the x-axis. If not set, tries to choose a sensible default.

sigfig

Number of significant digits to display in the table. Default 3.

digits

Number of decimal places to display in the table. Overrides sigfig if set.

refline

x intercept of vertical reference line, if desired.

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 x-axis as a numeric vector.

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 0 (left) to 1 (right). Default centres every column.

add.columns.uline

Underline the header of the new columns? Default TRUE.

calcdim

Logical, calculate suggested output dimensions for saving to pdf? Calculates output size when TRUE; saves time when FALSE.

display

Logical, display the plot? Defaults to TRUE.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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)

nmathresh documentation built on July 8, 2020, 5:17 p.m.