plotTTestDesign(x.var = "n", y.var = "power", range.x.var = NULL,
n.or.n1 = 25, n2 = n.or.n1,
delta.over.sigma = switch(alternative, greater = 0.5, less = -0.5,
two.sided = ifelse(two.sided.direction == "greater", 0.5, -0.5)),
alpha = 0.05, power = 0.95,
sample.type = ifelse(!missing(n2), "two.sample", "one.sample"),
alternative = "two.sided", two.sided.direction = "greater", approx = FALSE,
round.up = FALSE, n.max = 5000, tol = 1e-07, maxiter = 1000, plot.it = TRUE,
add = FALSE, n.points = 50, 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),
"delta.over.sigma"
(scaled minimal detectable difference), "power"
(power of the test)"power"
(power of the test; the default),
"delta.over.sigma"
(scaled minimal detectable difference), and
"n"
(sample sx.var
.
When x.var="n"
the default value is c(2,50)
. When
x.var="de
n.or.n1=25
. When sample.type="one.sample"
, n.or.n1
denotes the number of observations in the single sample. When
sample.type="two.s
n.or.n1
. Missing (NA
), undefined (NaN
),
and infinite (Inf
, -Inf
) values are not allowed. Talternative="greater"
or
alternative="two.sided"
alpha=0.05
.
This argument is ignored when x.var="alpha"
.power=0.95
. This argument is
ignored when x.var="power"
or y.var="power"
.sample.type="one.sample"
, the computations
for the plot are based on a one-sample t-test. When
sample.type="two.sample"
"two.sided"
(the default), "less"
, and "greater"
.alternative="two.sided"
. When
two.sided.direction="greater"
(the default), the scaled minimal detectable approx=FALSE
.round.up=FALSE
.
This argument is ignored unless y.var="n"
.y.var="n"
, a positive integer greater than 1 indicating
the maximum sample size when sample.type="one.sample"
or the maximum sample
size for group 1 when sample.type="two.sample"
. The defauy.var="n"
or
y.var="delta.over.sigma"
.
This argument is passed to the uniroot
function and indicates the tolerance
to use in the search algorithm. The default vay.var="n"
and approx=FALSE
(i.e., when the power is based on the exact test), or when
y.var="delta.over.sigma"
. This argument is passed to the
add
) on the current graphics device. If plot.it=FALSE
, no plot
is produced, but a list of (x,y) values is returned (see VALUE). Tadd=TRUE
), or to create a plot from scratch
(add=FALSE
). The default value is add=FALSE
.
This argument is ignored if n.points
x-values evenly spaced between
range.x.var[1]
and range.x.var[2]
. The default value is
n.points=50
plot.col="black"
. See the
entry for col
in the help file for par
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
).plotTTestDesign
invisibly returns a list with components
x.var
and y.var
, giving coordinates of the points that have
been or would have been plotted.tTestPower
, tTestN
, and
tTestScaledMdd
for information on how to compute the power,
sample size, or scaled minimal detectable difference for a one- or two-sample
t-test.tTestPower
, tTestN
, and
tTestScaledMdd
.tTestPower
, tTestN
,
tTestScaledMdd
, t.test
.# Look at the relationship between power and sample size for a two-sample t-test,
# assuming a scaled difference of 0.5 and a 5% significance level:
dev.new()
plotTTestDesign(sample.type = "two")
#----------
# For a two-sample t-test, plot sample size vs. the scaled minimal detectable
# difference for various levels of power, using a 5% significance level:
dev.new()
plotTTestDesign(x.var = "delta.over.sigma", y.var = "n", sample.type = "two",
ylim = c(0, 110), main="")
plotTTestDesign(x.var = "delta.over.sigma", y.var = "n", sample.type = "two",
power = 0.9, add = TRUE, plot.col = "red")
plotTTestDesign(x.var = "delta.over.sigma", y.var = "n", sample.type = "two",
power = 0.8, add = TRUE, plot.col = "blue")
legend("topright", c("95%", "90%", "80%"), lty = 1,
lwd = 3 * par("cex"), col = c("black", "red", "blue"), bty = "n")
title(main = paste("Sample Size vs. Scaled Difference for",
"Two-Sample t-Test, with Alpha=0.05 and Various Powers",
sep=""))
#==========
# Modifying the example on pages 21-4 to 21-5 of USEPA (2009), look at
# power versus scaled minimal detectable difference for various sample
# sizes in the context of the problem of using a one-sample t-test to
# compare the mean for the well with the MCL of 7 ppb. Use alpha = 0.01,
# assume an upper one-sided alternative (i.e., compliance well mean larger
# than 7 ppb).
dev.new()
plotTTestDesign(x.var = "delta.over.sigma", y.var = "power",
range.x.var = c(0.5, 2), n.or.n1 = 8, alpha = 0.01,
alternative = "greater", ylim = c(0, 1), main = "")
plotTTestDesign(x.var = "delta.over.sigma", y.var = "power",
range.x.var = c(0.5, 2), n.or.n1 = 6, alpha = 0.01,
alternative = "greater", add = TRUE, plot.col = "red")
plotTTestDesign(x.var = "delta.over.sigma", y.var = "power",
range.x.var = c(0.5, 2), n.or.n1 = 4, alpha = 0.01,
alternative = "greater", add = TRUE, plot.col = "blue")
legend("topleft", paste("N =", c(8, 6, 4)), lty = 1, lwd = 3 * par("cex"),
col = c("black", "red", "blue"), bty = "n")
title(main = paste("Power vs. Scaled Difference for One-Sample t-Test",
"with Alpha=0.01 and Various Sample Sizes", sep=""))
#==========
# Clean up
#---------
graphics.off()
Run the code above in your browser using DataLab