plotTTestDesign {EnvStats}  R Documentation 
Create plots involving sample size, power, scaled difference, and significance level for a one or twosample ttest.
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 = 1e07, 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")
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 
delta.over.sigma 
numeric scalar specifying the ratio of the true difference ( 
alpha 
numeric scalar between 0 and 1 indicating the Type I error level associated
with the hypothesis test. The default value is 
power 
numeric scalar between 0 and 1 indicating the power associated with the
hypothesis test. The default value is 
sample.type 
character string indicating whether the design is based on a onesample or
twosample ttest. When 
alternative 
character string indicating the kind of alternative hypothesis. The possible
values are 
two.sided.direction 
character string indicating the direction (positive or negative) for the scaled
minimal detectable difference when 
approx 
logical scalar indicating whether to compute the power based on an approximation
to the noncentral tdistribution. The default value is 
round.up 
logical scalar indicating whether to round up the values of the computed sample
size(s) to the next smallest integer. The default value is 
n.max 
for the case when 
tol 
numeric scalar relevant to the case when 
maxiter 
numeric scalar relevant to the case when 
plot.it 
a logical scalar indicating whether to create a new plot or add to the existing plot
(see 
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 tTestPower
, tTestN
, and
tTestScaledMdd
for information on how to compute the power,
sample size, or scaled minimal detectable difference for a one or twosample
ttest.
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.
See the help files for tTestPower
, tTestN
, and
tTestScaledMdd
.
Steven P. Millard (EnvStats@ProbStatInfo.com)
See the help files for tTestPower
, tTestN
, and
tTestScaledMdd
.
tTestPower
, tTestN
,
tTestScaledMdd
, t.test
.
# Look at the relationship between power and sample size for a twosample ttest,
# assuming a scaled difference of 0.5 and a 5% significance level:
dev.new()
plotTTestDesign(sample.type = "two")
#
# For a twosample ttest, 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",
"TwoSample tTest, with Alpha=0.05 and Various Powers",
sep="\n"))
#==========
# Modifying the example on pages 214 to 215 of USEPA (2009), look at
# power versus scaled minimal detectable difference for various sample
# sizes in the context of the problem of using a onesample ttest to
# compare the mean for the well with the MCL of 7 ppb. Use alpha = 0.01,
# assume an upper onesided 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 OneSample tTest",
"with Alpha=0.01 and Various Sample Sizes", sep="\n"))
#==========
# Clean up
#
graphics.off()