distfreereg
objectsThis is a plot
method for objects of class distfreereg
. It automates the creation of three summary and diagnostic plots for distfreereg
objects. See the Plotting with the distfreereg
Package vignette for examples.
# S3 method for distfreereg
plot(x, which = "dens", stat = NULL, density_args = NULL, polygon_args = NULL,
confband_args = NULL, abline_args = NULL, shade_col = rgb(1,0,0,0.5),
text_args = NULL, ...)
When which
is "dens
", the values used to create the density plot are returned invisibly in a list with two named elements, x
and y
. If the confidence band is plotted, then it is included as an element named confband
.
For other values of which
, nothing is returned.
Object of class distfreereg
.
Character string. Acceptable values are "dens
", "residuals
", and "epsp
":
"dens
" produces a plot of the estimated density curve of the
specified statistic.
"residuals
" produces a plot of the transformed residuals in the
order specified by x$res_order
.
"epsp
" produces a plot of the empirical partial sum process of
the (ordered) transformed residuals.
Character vector of length one specifying the name of the statistic to plot
when which
is "dens
". By default, the first statistic in
x$observed_stats
is used.
An optional list of arguments to pass to density
.
An optional list of arguments to pass to polygon
, used to shade under the density curve to the right of the value of the observed statistic. Setting equal to FALSE
prevents the call, and no shading is done.
An optional list of values that control the calculation and plotting of confidence bands. Any of the following named elements are allowed.
w
: Numeric; the sequence of points on which to evaluate the confidence band. By default, the sequence is seq(from = min(x) + buffer, to = max(x) - buffer, length.out = m
, where x
is the vector of values of the statistic in question, and buffer
is explained below.
m
: Integer; the length of w
, used only when w
is NULL
. The default value is 100.
batch_len
: Integer; the batch length for the algorithm. The default value is 50.
N
: Integer; the number of multivariate \(t\) samples to use in the simulation.
conf.level
: Numeric; the desired confidence level.
buffer
: Numeric; the proportion of either side of the range of data to ignore when defining w
, used only when w
is NULL
.
curve_args
: An optional list of arguments passed to lines
(not curve
!), used to create the boundaries of the confidence band.
polygon_args
: An optional list of arguments passed to polygon
, used to shade the confidence region. Setting equal to FALSE
prevents the call, and no shading is done.
shade_col
: This provides a shortcut to the col
argument of polygon
to change the color of the shaded region.
Setting equal to FALSE
prevents calculation and plotting of the confidence band.
An optional list of arguments to pass to abline
, used to draw a vertical line at the value of the observed statistic. Setting equal to FALSE
prevents the call, and no line is drawn.
Character string or other value specifying the color to use to shade the upper tail of the distribution. Default value is red with 50% transparency. This is a convenience argument, and the same functionality is available by defining a col
element in the polygon_args
argument.
An optional list of arguments to pass to text
, used to label the vertical line with the p-value of the observed statistic. Setting equal to FALSE
prevents the call, and no text is printed.
Additional arguments to pass to plot
.
Jesse Miller
This function produces one of three specified plots, depending on the value of which
.
When which
is "dens
", a plot of the estimated density of the simulated statistics is produced, including a vertical line at the value of the observed test statistic with the p-value displayed.
The default placement of the p-value text is on the left side of the line indicating the statistic value. Specifically, the default values of x
and y
passed to text
are the statistic value itself and the midpoint between zero and the maximum value of the density curve. The default value passed to adj
is c(1,0.5)
, meaning that the text is aligned to the left of the value \((x,y)\) and centered vertically on it. (The default value for the text itself, which can be modified via the label
argument of text
, includes a space on the left and the right for padding so the text does not overlap the vertical line itself.) To align the text so it appears on the right side (for example, to avoid overlapping the density curve), use text_args = list(adj = c(0,0.5))
. See documentation for text
for details on this and other arguments.
When which
is "residuals
", a time-series-like plot is produced showing transformed residuals in the order given by x$res_order
. In the case that the null hypothesis is rejected, this plot can help determine where (in terms of the linearly ordered covariates) a discrepancy between the model and the data occurs.
When which
is "epsp
", a plot of the empirical partial sum process is produced; that is, the \(y\)-values are
$$y_j = {1\over\sqrt{n}}\sum_{i=1}^j\hat e_i$$ where \(\hat e_i\) is the \(i\)th transformed residual in the order given by x$res_order
. Similar to the case when which
is "residuals
", this plot can help determine where (in terms of the linearly ordered covariates) a discrepancy between the model and the data occurs.
Flegal, James M. et al. Simultaneous confidence bands for (Markov chain) Monte Carlo simulations, forthcoming.
distfreereg