View source: R/plot.feasible.r
| plot.feasible | R Documentation |
feasible objectsGenerate diagnostic plots for objects of class "feasible", returned by feasible.
One can display either (i) mean feasible vs. target interventions, or (ii) the non-overlap ratio.
## S3 method for class 'feasible'
plot(x, x.axis = c("strategy", "time"),
which = c("feasible", "nonoverlap"),
facet = c("none", "time", "strategy"), ...)
x |
An object of class |
x.axis |
A string specifying the x-axis:
|
which |
Which plot to show:
|
facet |
Optional faceting to reduce overplotting:
Facet strips are labelled with variable name and value (via |
... |
Additional arguments (currently unused). Included for method consistency. |
Both plot types are drawn with ggplot2. To reduce overplotting,
lines and points use transparency (alpha) and slightly smaller
widths/sizes by default. Faceting by time or strategy
can further improve readability when many series are present.
The "summary" attribute of a "feasible" object is expected to contain
(at least) the following columns:
time: discrete time index.
Strategy: strategy index (row index of the intervention design).
Abar: target value (intervention level) for that strategy at that time.
Feasible: mean feasible value under the estimated feasible intervention.
Low: non-overlap ratio (proportion of mass below the density threshold).
Interpretation of abar:
In feasible, the abar argument may be either
a numeric vector (static grid of targets) or a numeric matrix.
If abar is a vector, each distinct value defines a strategy that is
constant over time; in this case each strategy represents the same target value
at every time-point.
If abar is a matrix, rows index intervention strategies and
columns index time-points. In the summary, Strategy identifies the row,
and Abar is the entry of that row at the corresponding time-point.
Plot types:
Feasible vs Target (which = "feasible"):
Y-axis: mean feasible intervention (Feasible).
X-axis: controlled by x.axis:
x.axis = "time": x-axis shows time; colors represent Targets (Abar)
when each strategy has the same target at all time-points, or represent strategies
when targets vary over time within a strategy.
x.axis = "strategy": x-axis shows strategy index; if each strategy corresponds
to a single target value at all time-points and this relationship is consistent,
the x-axis is relabelled to show Abar (Targets) instead.
Reference line and ticks:
When the x-axis is on the Target scale (strategies are constant over time with respect to Abar),
the plot includes a dashed 1:1 reference line \text{Feasible} = \text{Target} and aligns
the x- and y-axis limits to the range of Abar, when plausible (i.e., when the feasible values
lie within the range of Abar).
When x.axis = "time", short horizontal ticks at each time-point indicate the
Abar values for each strategy (or Target when strategies are constant over time),
using the same color mapping as the series.
When x.axis = "strategy" and strategies do not correspond to a single target over all time-points,
ticks are drawn at each strategy to indicate the Abar values across time.
Non-overlap Ratio (which = "nonoverlap"):
Y-axis: non-overlap ratio Low (bounded between 0 and 1), plotted with fixed limits
c(0, 1).
X-axis: same choice of x.axis as for the feasible plot.
Terminology: Throughout the plots, “Target” refers to the intervention values passed as the
abar argument to feasible (stored as column Abar in the object's summary).
When strategies are constant over time with respect to Abar and this structure is consistent across time,
each Target corresponds to an identical intervention pattern at all time-points. This is reflected in both the
x-axis labelling and the legend.
Invisibly returns the ggplot2 object that is drawn (either the feasible plot or the non-overlap plot).
Han Bao, Michael Schomaker
feasible, summary.feasible
data(EFV)
Lnodes <- c("adherence.1","weight.1",
"adherence.2","weight.2",
"adherence.3","weight.3",
"adherence.4","weight.4")
Ynodes <- c("VL.0","VL.1","VL.2","VL.3","VL.4")
Anodes <- c("efv.0","efv.1","efv.2","efv.3","efv.4")
## ------------------------------------------------------------------
## Example 1: Static grid of Targets (vector abar)
## Each strategy uses the same target value at every time-point
## ------------------------------------------------------------------
abar_static <- seq(0, 10, by = 2)
m_static <- feasible(X = EFV,
Anodes = Anodes,
Lnodes = Lnodes,
Ynodes = Ynodes,
d.method = "parametric",
abar = abar_static,
grid.size = NULL,
left.boundary = 0,
right.boundary = 10)
## Feasible vs Target with time on x-axis (default).
## Colors indicate Targets (Abar), and short ticks show Abar at each time.
plot(m_static, which = "feasible")
## Feasible vs Target with time on x-axis.
plot(m_static, x.axis = "time", which = "feasible")
## Non-overlap ratio
plot(m_static, which = "nonoverlap")
## Facet by time to reduce overplotting
plot(m_static, which = "feasible", facet = "time")
## ------------------------------------------------------------------
## Example 2: Non-constant intervention strategies (matrix abar)
## Strategies can have different target values at different time-points
## ------------------------------------------------------------------
## Here rows define strategies and columns define time-points.
abar_matrix <- rbind(
c(0, 2, 4, 6, 8), # strategy 1
c(9, 6, 2, 1, 0), # strategy 2
c(1, 3, 5, 7, 9) # strategy 3
)
set.seed(456)
m_matrix <- feasible(X = EFV,
Anodes = Anodes,
Lnodes = Lnodes,
Ynodes = Ynodes,
d.method = "parametric",
abar = abar_matrix,
grid.size = 1,
left.boundary = 0,
right.boundary = 10)
## Feasible vs Target with time on the x-axis.
## Colors represent strategies; short ticks at each time show
## the corresponding Abar for each strategy.
plot(m_matrix,
x.axis = "time",
which = "feasible",
facet = "none")
## Feasible vs Target with strategy on the x-axis.
## Strategies no longer use the same target at all time-points,
## so the x-axis stays on the strategy index, and ticks at each
## strategy indicate the Abar values across time.
plot(m_matrix,
x.axis = "strategy",
which = "feasible",
facet = "none")
## Non-overlap ratio for these non-constant strategies,
## shown over time and faceted by strategy for clarity.
plot(m_matrix,
x.axis = "time",
which = "nonoverlap",
facet = "strategy")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.