plotCiNormDesign {EnvStats}  R Documentation 
Create plots involving sample size, halfwidth, estimated standard deviation, and confidence level for a confidence interval for the mean of a normal distribution or the difference between two means.
plotCiNormDesign(x.var = "n", y.var = "half.width",
range.x.var = NULL, n.or.n1 = 25, n2 = n.or.n1,
half.width = sigma.hat/2, sigma.hat = 1, conf.level = 0.95,
sample.type = ifelse(missing(n2), "one.sample", "two.sample"),
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,
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.or.n1 
numeric scalar indicating the sample size. The default value is 
n2 
numeric scalar indicating the sample size for group 2.
The default value is the value of 
half.width 
positive numeric scalar indicating the halfwidth of the confidence interval.
The default value is 
sigma.hat 
positive numeric scalar specifying the estimated standard deviation.
The default value is 
conf.level 
a scalar between 0 and 1 indicating the confidence level associated with the confidence interval.
The default value is 
sample.type 
character string indicating whether this is a onesample or twosample confidence interval. 
round.up 
logical scalar indicating whether to round up the computed sample sizes to the next smallest integer.
The default value is 
n.max 
for the case when 
tol 
for the case when 
maxiter 
for the case when 
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 
main , xlab , ylab , type , ... 
additional graphical parameters (see 
See the help files for ciNormHalfWidth
and ciNormN
for information on how to compute a onesample confidence interval for the mean of
a normal distribution or a twosample confidence interval for the difference between
two means, how the halfwidth is computed when other quantities are fixed, and how the
sample size is computed when other quantities are fixed.
plotCiNormDesign
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. 
The normal distribution and lognormal distribution are probably the two most frequently used distributions to model environmental data. In order to make any kind of probability statement about a normallydistributed population (of chemical concentrations for example), you have to first estimate the mean and standard deviation (the population parameters) of the distribution. Once you estimate these parameters, it is often useful to characterize the uncertainty in the estimate of the mean. This is done with confidence intervals.
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 confidence intervals. The functions
ciNormHalfWidth
, ciNormN
, and plotCiNormDesign
can be used to investigate these relationships for the case of normallydistributed observations.
Steven P. Millard (EnvStats@ProbStatInfo.com)
Berthouex, P.M., and L.C. Brown. (2002). Statistics for Environmental Engineers. Second Edition. Lewis Publishers, Boca Raton, FL.
Gilbert, R.O. (1987). Statistical Methods for Environmental Pollution Monitoring. Van Nostrand Reinhold, New York, NY.
Helsel, D.R., and R.M. Hirsch. (1992). Statistical Methods in Water Resources Research. Elsevier, New York, NY, Chapter 7.
Millard, S.P., and N. Neerchal. (2001). Environmental Statistics with SPLUS. CRC Press, Boca Raton, FL.
Ott, W.R. (1995). Environmental Statistics and Data Analysis. Lewis Publishers, Boca Raton, FL.
USEPA. (2009). Statistical Analysis of Groundwater Monitoring Data at RCRA Facilities, Unified Guidance. EPA 530/R09007, March 2009. Office of Resource Conservation and Recovery Program Implementation and Information Division. U.S. Environmental Protection Agency, Washington, D.C. p.213.
Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. PrenticeHall, Upper Saddle River, NJ, Chapters 7 and 8.
ciNormHalfWidth
, ciNormN
, Normal
,
enorm
, t.test
,
Estimating Distribution Parameters.
# Look at the relationship between halfwidth and sample size
# for a onesample confidence interval for the mean, assuming
# an estimated standard deviation of 1 and a confidence level of 95%.
dev.new()
plotCiNormDesign()
#
# Plot sample size vs. the estimated standard deviation for
# various levels of confidence, using a halfwidth of 0.5.
dev.new()
plotCiNormDesign(x.var = "sigma.hat", y.var = "n", main = "")
plotCiNormDesign(x.var = "sigma.hat", y.var = "n", conf.level = 0.9,
add = TRUE, plot.col = 2)
plotCiNormDesign(x.var = "sigma.hat", y.var = "n", conf.level = 0.8,
add = TRUE, plot.col = 3)
legend(0.25, 60, c("95%", "90%", "80%"), lty = 1, lwd = 3, col = 1:3)
mtext("Sample Size vs. Estimated SD for Confidence Interval for Mean",
font = 2, cex = 1.25, line = 2.75)
mtext("with HalfWidth=0.5 and Various Confidence Levels", font = 2,
cex = 1.25, line = 1.25)
#
# Modifying the example on pages 214 to 215 of USEPA (2009),
# look at the relationship between halfwidth and sample size for a
# 95% confidence interval for the mean level of Aldicarb at the
# first compliance well. Use the estimated standard deviation from
# the first four months of data.
# (The data are stored in EPA.09.Ex.21.1.aldicarb.df.)
EPA.09.Ex.21.1.aldicarb.df
# Month Well Aldicarb.ppb
#1 1 Well.1 19.9
#2 2 Well.1 29.6
#3 3 Well.1 18.7
#4 4 Well.1 24.2
#...
mu.hat < with(EPA.09.Ex.21.1.aldicarb.df,
mean(Aldicarb.ppb[Well=="Well.1"]))
mu.hat
#[1] 23.1
sigma.hat < with(EPA.09.Ex.21.1.aldicarb.df,
sd(Aldicarb.ppb[Well=="Well.1"]))
sigma.hat
#[1] 4.93491
dev.new()
plotCiNormDesign(sigma.hat = sigma.hat, digits = 2,
range.x.var = c(2, 25))
#==========
# Clean up
#
rm(mu.hat, sigma.hat)
graphics.off()