xs.plot(x, ...)
## S3 method for class 'default':
xs.plot(x,g,s, degfree, labels.arg=NA, mu, sigma,
probs=c(0.5, 0.95, 0.99), basis=c("robust","classical"),
method=c("chisq","density"), main=paste("X-S plot -", basis, "basis"),
xlab=deparse(substitute(x)), ylab,
contours=TRUE, col.contours="lightgrey", lty.contours=par("lty"),
lwd.contours=par("lwd"),
label.contours=contours, format.clab="p=%3.2f",
pos.clab="bottomright", col.clab=col.contours, cex.clab=0.7,
cex.label=0.7, pos=3, adj=NULL,
pch=par("pch"), col=par("col"), bg=par("bg"), cex=par("cex"),
add=FALSE, ...)
XSplot(x, ...)
length(x)
.length(x)
associated with x.s
. Ignored if s
is not supplied."basis"
; see Details.sprintf
.points
.text
.text
;
see text
for details.pch=NA
to suppress symbols if only added
contours are required.plot
.s
is supplied, x
is taken as a vector of locations and
s
a vector of standard deviations. degfree
must be supplied
in this case.
If g
is supplied and s
is not, the locations and standard deviations
used are the means and standard deviations for each group. degfree
is calculated
from the median group size. Groups should, of course, be of the same size for accurate
inference; however, using the median group size allows for some groups with missing values.
If s
and g
are both supplied, g
is ignored with a warning
If requested by contours=TRUE
, confidence regions are drawn for each value
of probs
. Contour location and shape are controlled by basis
which specifies the location and scale estimators used, and method
, which
specifies the method of calculation for the contours. Two methods are supported;
one using the chi-squared distribution (method="chisq"
) and one based on
equal density countours (method="density"
). The default, and the method
recommended by the cited Standard, is method="chisq"
and basis="robust"
.
Both calculations for confidence regions require estimation of a location $\hat{\mu}$
and an estimate $\hat{\sigma}$ of the pooled within-group standard deviation or pooled
estimate from s
. If basis="robust"
, $\hat{\mu}$ and $\hat{\sigma}$
are calculated using algA
and algS
respectively. If basis="classical"
,
$\hat{\mu}$ and $\hat{\sigma}$ are the mean of the group means and the classical pooled
standard deviation respectively. If mu
or sigma
are given, these are used
in place of the calculated $\hat{\mu}$ and $\hat{\sigma}$ respectively.
If method="chisq"
, contours for probability $p$ are calculated as
$$s=\hat{\sigma}\exp\left ( \pm\frac{1}{\sqrt{2(n-1)}}\sqrt{\chi_{2,p}^2-n \left ( \frac{x-\hat{\mu}}{\hat{\sigma}}\right ) ^2}\right )$$
for $x$ from$\hat{\mu}-\hat{\sigma}\sqrt{\frac{\chi_{2,p}^2}{n}}$ to
$\hat{\mu}+\hat{\sigma}\sqrt{\frac{\chi_{2,p}^2}{n}}$.
If method="density"
, contours for probability $p$ are calculated using
Helmert's distribution to provide constant likelihood contours round the chosen mean
and standard deviation. In the present implementation, these are found using
uniroot
to find the mean corresponding to the required density at
given standard deviations. The density chosen is $d_{max}(1-p)$ where $p$ is
the probability and $d_{max}$ the maximum density for Helmert's
distribution for the requisite nunber of degrees of freedom. (See Kruskal
(1946) for a description of Helmert's distribution and, for example,
Pawitan (2001) for the rationale behind the choice of density
contour level.) This seems to give reasonably good results for $n \ge 3$
but is anticonservative (particularly to high $s$) for $n = 2$.
Contours are by default labelled. Label locations can be specified using pos.clab
.
Options are code{"top"}, code{"topright"}, code{"right"}, code{"bottomright"},
code{"bottom"}, code{"bottomleft"}, code{"left"} and code{"topleft"}. A vector can be
specified to give labels at more than one such location.
Contour labels are usually placed approximately at the location(s) indicated and adjusted outward
appropriately. For the special case of method="density"
and degfree=1
(or where group
sizes $n=1$), for which the region is a maximu width at s=0,
"bottomright"
and "bottomleft"
place labels immediately below the countour boundary
at $s=0$ and, if specified, "bottom"
is replaced with c("bottomright", "bottomleft")
.
XSplot
is an alias for xs.plot
.algA
, algS
axis
for axis control; points
, text
for
plotting parameters; sprintf
for contour label formatting.
duewer.plot
for an alternative plot for locations and associated
standard errors or standard uncertainties;require(metRology)
set.seed(1017)
x <- rnorm(80)
g <- gl(20,4)
xs.plot(x,g)
#Identical plot with precalculated s:
X <- tapply(x,g,mean)
S <- tapply(x,g,sd)
xs.plot(X, s=S, degfree=3)
#Specify different location and within-group SD estimates:
xs.plot(X, s=S, degfree=3, mu=median(X), sigma=median(S))
#Illustrate multiple contour labelling, point labels and further embellishment
rv <- xs.plot(x,g, pos.clab=c("bottomleft", "bottomright"), labels=TRUE)
abline(v=rv$mu, h=rv$s, col=2)
Run the code above in your browser using DataLab