
Last chance! 50% off unlimited learning
Sale ends in
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 = 1e-07, 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", ...)
"n"
(sample size; the default),
"half.width"
(the half-width of the confidence interval),
"sigma.hat"
(the estimated s"half.width"
(the half-width of the confidence interval; the default), and
"n"
(sample size).x.var
.
When x.var="n"
the default value is c(2,50)
.
When x.var="ha
n.or.n1=25
.
When sample.type="one.sample"
, this argument denotes the number of observations
in the single sample.
When sample.type="two.sample"<
n.or.n1
.
Missing (NA
), undefined (NaN
), and infinite (Inf
, -Inf
) values are not allowed.
sigma.hat/2
.
Missing (NA
), undefined (NaN
), and infinite (Inf
, -Inf
) values are nsigma.hat=1
.
This argument is ignored if x.var="sigma.hat"
.conf.level=0.95
. This argument is ignored if x.var="conf.level"
.sample.type="one.sample"
, the computations for the plot are based on a confidence
interval for a single mean.
When sample.type="two.
round.up=FALSE
. This argument is ignored unless y.var="n"
.y.var="n"
, positive integer greater than 1
specifying the maximum sample size for the single
group when sample.type="one.sample"
or for group 1 when
sample.type="two.sample"
. The defauly.var="n"
, numeric scalar indicating the tolerance to
use in the uniroot
search algorithm. The default value is
tol=1e-7
.y.var="n"
, positive integer indicating the maximum
number of iterations to use in the uniroot
search algorithm.
The default value is maxiter=1000
.add
below) on the current graphics device.
If plot.it=FALSE
, no plot is produced, but a list of (x,y) valuadd=TRUE
),
or to create a plot from scratch (add=FALSE
). The default value is add=FALSE
.
This argument is ignored if pl
n.points
x-values evenly spaced between range.x.var[1]
and
range.x.var[2]
. The default value is n.points=100
.plot.col=1
. See the entry for col
in the help file for par
for 3*par("cex")
. See the entry for lwd
in the help file for par
for more information.plot.lty=1
. See the entry for lty
in the help file for par
for more information.options("digits")
.par
).plotCiNormDesign
invisibly returns a list with components:ciNormHalfWidth
and ciNormN
for information on how to compute a one-sample confidence interval for the mean of
a normal distribution or a two-sample confidence interval for the difference between
two means, how the half-width is computed when other quantities are fixed, and how the
sample size is computed when other quantities are fixed.ciNormHalfWidth
, ciNormN
, Normal
,
enorm
, t.test
,
Estimating Distribution Parameters.# Look at the relationship between half-width and sample size
# for a one-sample 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 half-width 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 Half-Width=0.5 and Various Confidence Levels", font = 2,
cex = 1.25, line = 1.25)
#--------------------------------------------------------------------
# Modifying the example on pages 21-4 to 21-5 of USEPA (2009),
# look at the relationship between half-width 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()
Run the code above in your browser using DataLab