Plots for Sampling Design Based on Nonparametric Confidence Interval for a Quantile
Source:R/plotCiNparDesign.R
plotCiNparDesign.RdCreate plots involving sample size, quantile, and confidence level for a nonparametric confidence interval for a quantile.
Usage
plotCiNparDesign(x.var = "n", y.var = "conf.level", range.x.var = NULL,
n = 25, p = 0.5, conf.level = 0.95, ci.type = "two.sided",
lcl.rank = ifelse(ci.type == "upper", 0, 1),
n.plus.one.minus.ucl.rank = ifelse(ci.type == "lower", 0, 1),
plot.it = TRUE, add = FALSE, n.points = 100, plot.col = "black",
plot.lwd = 3 * par("cex"), plot.lty = 1, digits = .Options$digits,
cex.main = par("cex"), ..., main = NULL, xlab = NULL, ylab = NULL,
type = "l")Arguments
- x.var
character string indicating what variable to use for the x-axis. Possible values are
"n"(sample size; the default),"p"(quantile), and"conf.level"(the confidence level).- y.var
character string indicating what variable to use for the y-axis. Possible values are
conf.level(confidence level; the default), and"n"(sample size).- range.x.var
numeric vector of length 2 indicating the range of the x-variable to use for the plot. The default value depends on the value of
x.var. Whenx.var="n"the default value isc(2,50). Whenx.var="p"the default value isc(0.5, 0.99). Whenx.var="conf.level", the default value isc(0.5, 0.99).- n
numeric scalar indicating the sample size. The default value is
n=25. Missing (NA), undefined (NaN), and infinite (Inf,-Inf) values are not allowed. This argument is ignored if eitherx.var="n"ory.var="n".- p
numeric scalar specifying the quantile. The value of this argument must be between 0 and 1. The default value is
p=0.5. The argument is ignored ifx.var="p".- conf.level
a scalar between 0 and 1 indicating the confidence level associated with the confidence interval. The default value is
conf.level=0.95. This argument is ignored ifx.var="conf.level"ory.var="conf.level".- ci.type
character string indicating what kind of confidence interval to compute. The possible values are
"two-sided"(the default),"lower", and"upper".- lcl.rank, n.plus.one.minus.ucl.rank
numeric vectors of non-negative integers indicating the ranks of the order statistics that are used for the lower and upper bounds of the confidence interval for the specified quantile(s). When
lcl.rank=1that means use the smallest value as the lower bound, whenlcl.rank=2that means use the second to smallest value as the lower bound, etc. Whenn.plus.one.minus.ucl.rank=1that means use the largest value as the upper bound, whenn.plus.one.minus.ucl.rank=2that means use the second to largest value as the upper bound, etc. A value of0forlcl.rankindicates no lower bound (i.e., -Inf) and a value of0forn.plus.one.minus.ucl.rankindicates no upper bound (i.e.,Inf). Whenci.type="upper"thenlcl.rankis set to0by default, otherwise it is set to1by default. Whenci.type="lower"thenn.plus.one.minus.ucl.rankis set to0by default, otherwise it is set to1by default.- plot.it
a logical scalar indicating whether to create a plot or add to the existing plot (see
add) on the current graphics device. Ifplot.it=FALSE, no plot is produced, but a list of (x,y) values is returned (see VALUE). The default value isplot.it=TRUE.- add
a logical scalar indicating whether to add the design plot to the existing plot (
add=TRUE), or to create a plot from scratch (add=FALSE). The default value isadd=FALSE. This argument is ignored ifplot.it=FALSE.- n.points
a numeric scalar specifying how many (x,y) pairs to use to produce the plot. There are
n.pointsx-values evenly spaced betweenrange.x.var[1]andrange.x.var[2]. The default value isn.points=100.- plot.col
a numeric scalar or character string determining the color of the plotted line or points. The default value is
plot.col="black". See the entry forcolin the help file forparfor more information.- plot.lwd
a numeric scalar determining the width of the plotted line. The default value is
3*par("cex"). See the entry forlwdin the help file forparfor more information.- plot.lty
a numeric scalar determining the line type of the plotted line. The default value is
plot.lty=1. See the entry forltyin the help file forparfor more information.- digits
a scalar indicating how many significant digits to print out on the plot. The default value is the current setting of
options("digits").- cex.main, main, xlab, ylab, type, ...
additional graphical parameters (see
par).
Details
See the help files for eqnpar, ciNparConfLevel,
and ciNparN for information on how to compute a
nonparametric confidence interval for a quantile, how the confidence level
is computed when other quantities are fixed, and how the sample size is
computed when other quantities are fixed.
Value
plotCiNparDesign invisibly returns a list with components
x.var and y.var, giving coordinates of the points that
have been or would have been plotted.
References
See the help file for eqnpar.
Author
Steven P. Millard (EnvStats@ProbStatInfo.com)
Note
See the help file for eqnpar.
Examples
# Look at the relationship between confidence level and sample size for
# a two-sided nonparametric confidence interval for the 90'th percentile.
if (interactive()) dev.new()
plotCiNparDesign(p = 0.9)
#----------
# Plot sample size vs. quantile for various levels of confidence:
if (interactive()) dev.new()
plotCiNparDesign(x.var = "p", y.var = "n", range.x.var = c(0.8, 0.95),
ylim = c(0, 60), main = "")
plotCiNparDesign(x.var = "p", y.var = "n", conf.level = 0.9, add = TRUE,
plot.col = 2, plot.lty = 2)
plotCiNparDesign(x.var = "p", y.var = "n", conf.level = 0.8, add = TRUE,
plot.col = 3, plot.lty = 3)
legend("topleft", c("95%", "90%", "80%"), lty = 1:3, col = 1:3,
lwd = 3 * par('cex'), bty = 'n')
title(main = paste("Sample Size vs. Quantile for ",
"Nonparametric CI for \nQuantile, with ",
"Various Confidence Levels", sep=""))
#==========
# Clean up
#---------
graphics.off()