Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/plotPredIntNormDesign.R
Create plots involving sample size, number of future observations, halfwidth, estimated standard deviation, and confidence level for a prediction interval for the next k observations from a normal distribution.
1 2 3 4 5 6 7  plotPredIntNormDesign(x.var = "n", y.var = "half.width", range.x.var = NULL,
n = 25, k = 1, n.mean = 1, half.width = 4 * sigma.hat, sigma.hat = 1,
method = "Bonferroni", conf.level = 0.95, round.up = FALSE, n.max = 5000,
tol = 1e07, maxiter = 1000, 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")

x.var 
character string indicating what variable to use for the xaxis.
Possible values are 
y.var 
character string indicating what variable to use for the yaxis.
Possible values are 
range.x.var 
numeric vector of length 2 indicating the range of the xvariable to use for the plot.
The default value depends on the value of 
n 
positive integer greater than 1 indicating the sample size upon
which the prediction interval is based. The default value is 
k 
positive integer specifying the number of future observations
or averages the prediction interval should contain with confidence level

n.mean 
positive integer specifying the sample size associated with the k future
averages. The default value is 
half.width 
positive scalar indicating the halfwidths of the prediction interval.
The default value is 
sigma.hat 
numeric scalar specifying the value of the estimated standard deviation.
The default value is 
method 
character string specifying the method to use if the number of future observations
( 
conf.level 
numeric scalar between 0 and 1 indicating the confidence level of the
prediction interval. The default value is 
round.up 
for the case when 
n.max 
for the case when 
tol 
numeric scalar indicating the tolerance to use in the 
maxiter 
positive integer indicating the maximum number of iterations to use in the

plot.it 
a logical scalar indicating whether to create a plot or add to the existing plot
(see explanation of the argument 
add 
a logical scalar indicating whether to add the design plot to the existing plot ( 
n.points 
a numeric scalar specifying how many (x,y) pairs to use to produce the plot.
There are 
plot.col 
a numeric scalar or character string determining the color of the plotted line or points. The default value
is 
plot.lwd 
a numeric scalar determining the width of the plotted line. The default value is

plot.lty 
a numeric scalar determining the line type of the plotted line. The default value is

digits 
a scalar indicating how many significant digits to print out on the plot. The default
value is the current setting of 
cex.main, main, xlab, ylab, type, ... 
additional graphical parameters (see 
See the help files for predIntNorm
, predIntNormK
,
predIntNormHalfWidth
, and predIntNormN
for
information on how to compute a prediction interval for the next k
observations or averages from a normal distribution, how the halfwidth is
computed when other quantities are fixed, and how the
sample size is computed when other quantities are fixed.
plotPredIntNormDesign
invisibly returns a list with components:
x.var 
xcoordinates of points that have been or would have been plotted. 
y.var 
ycoordinates of points that have been or would have been plotted. 
See the help file for predIntNorm
.
In the course of designing a sampling program, an environmental scientist may wish
to determine the relationship between sample size, confidence level, and halfwidth
if one of the objectives of the sampling program is to produce prediction intervals.
The functions predIntNormHalfWidth
, predIntNormN
, and
plotPredIntNormDesign
can be used to investigate these relationships for the
case of normallydistributed observations.
Steven P. Millard ([email protected])
See the help file for predIntNorm
.
predIntNorm
, predIntNormK
,
predIntNormHalfWidth
, predIntNormN
,
Normal
.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  # Look at the relationship between halfwidth and sample size for a
# prediction interval for k=1 future observation, assuming an estimated
# standard deviation of 1 and a confidence level of 95%:
dev.new()
plotPredIntNormDesign()
#==========
# Plot sample size vs. the estimated standard deviation for various levels
# of confidence, using a halfwidth of 4:
dev.new()
plotPredIntNormDesign(x.var = "sigma.hat", y.var = "n", range.x.var = c(1, 2),
ylim = c(0, 90), main = "")
plotPredIntNormDesign(x.var = "sigma.hat", y.var = "n", range.x.var = c(1, 2),
conf.level = 0.9, add = TRUE, plot.col = "red")
plotPredIntNormDesign(x.var = "sigma.hat", y.var = "n", range.x.var = c(1, 2),
conf.level = 0.8, add = TRUE, plot.col = "blue")
legend("topleft", c("95%", "90%", "80%"), lty = 1, lwd = 3 * par("cex"),
col = c("black", "red", "blue"), bty = "n")
title(main = paste("Sample Size vs. Sigma Hat for Prediction Interval for",
"k=1 Future Obs, HalfWidth=4, and Various Confidence Levels",
sep = "\n"))
#==========
# The data frame EPA.92c.arsenic3.df contains arsenic concentrations (ppb)
# collected quarterly for 3 years at a background well and quarterly for
# 2 years at a compliance well. Using the data from the background well,
# plot the relationship between halfwidth and sample size for a twosided
# 90% prediction interval for k=4 future observations.
EPA.92c.arsenic3.df
# Arsenic Year Well.type
#1 12.6 1 Background
#2 30.8 1 Background
#3 52.0 1 Background
#...
#18 3.8 5 Compliance
#19 2.6 5 Compliance
#20 51.9 5 Compliance
mu.hat < with(EPA.92c.arsenic3.df,
mean(Arsenic[Well.type=="Background"]))
mu.hat
#[1] 27.51667
sigma.hat < with(EPA.92c.arsenic3.df,
sd(Arsenic[Well.type=="Background"]))
sigma.hat
#[1] 17.10119
dev.new()
plotPredIntNormDesign(x.var = "n", y.var = "half.width", range.x.var = c(4, 50),
k = 4, sigma.hat = sigma.hat, conf.level = 0.9)
#==========
# Clean up
#
rm(mu.hat, sigma.hat)
graphics.off()

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.