tTestScaledMdd {EnvStats}  R Documentation 
Compute the scaled minimal detectable difference necessary to achieve a specified power for a one or twosample ttest, given the sample size(s) and Type I error level.
tTestScaledMdd(n.or.n1, n2 = n.or.n1, alpha = 0.05, power = 0.95,
sample.type = ifelse(!missing(n2) && !is.null(n2), "two.sample", "one.sample"),
alternative = "two.sided", two.sided.direction = "greater",
approx = FALSE, tol = 1e07, maxiter = 1000)
n.or.n1 
numeric vector of sample sizes. When 
n2 
numeric vector of sample sizes for group 2. The default value is the value of

alpha 
numeric vector of numbers between 0 and 1 indicating the Type I error level
associated with the hypothesis test. The default value is 
power 
numeric vector of numbers between 0 and 1 indicating the power
associated with the hypothesis test. The default value is 
sample.type 
character string indicating whether to compute power based on a onesample or
twosample hypothesis test. 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 
tol 
numeric scalar indicating the tolerance argument to pass to the

maxiter 
positive integer indicating the maximum number of iterations
argument to pass to the 
Formulas for the power of the ttest for specified values of
the sample size, scaled difference, and Type I error level are given in
the help file for tTestPower
. The function tTestScaledMdd
uses the uniroot
search algorithm to determine the
required scaled minimal detectable difference for specified values of the
sample size, power, and Type I error level.
numeric vector of scaled minimal detectable differences.
See tTestPower
.
Steven P. Millard (EnvStats@ProbStatInfo.com)
See tTestPower
.
tTestPower
, tTestAlpha
,
tTestN
,
plotTTestDesign
, Normal,
t.test
, Hypothesis Tests.
# Look at how the scaled minimal detectable difference for the
# onesample ttest increases with increasing required power:
seq(0.5, 0.9, by = 0.1)
#[1] 0.5 0.6 0.7 0.8 0.9
scaled.mdd < tTestScaledMdd(n.or.n1 = 20, power = seq(0.5,0.9,by=0.1))
round(scaled.mdd, 2)
#[1] 0.46 0.52 0.59 0.66 0.76
#
# Repeat the last example, but compute the scaled minimal detectable
# differences based on the approximation to the power instead of the
# exact formula:
scaled.mdd < tTestScaledMdd(n.or.n1 = 20, power = seq(0.5, 0.9, by = 0.1),
approx = TRUE)
round(scaled.mdd, 2)
#[1] 0.47 0.53 0.59 0.66 0.76
#==========
# Look at how the scaled minimal detectable difference for the twosample
# ttest decreases with increasing sample size:
seq(10,50,by=10)
#[1] 10 20 30 40 50
scaled.mdd < tTestScaledMdd(seq(10, 50, by = 10), sample.type = "two")
round(scaled.mdd, 2)
#[1] 1.71 1.17 0.95 0.82 0.73
#
# Look at how the scaled minimal detectable difference for the twosample
# ttest decreases with increasing values of Type I error:
scaled.mdd < tTestScaledMdd(20, alpha = c(0.001, 0.01, 0.05, 0.1),
sample.type="two")
round(scaled.mdd, 2)
#[1] 1.68 1.40 1.17 1.06
#==========
# Modifying the example on pages 214 to 215 of USEPA (2009),
# determine the minimal mean level of aldicarb at the third compliance
# well necessary to detect a mean level of aldicarb greater than the
# MCL of 7 ppb, assuming 90%, 95%, and 99% power. Use a 99% significance
# level and assume an upper onesided alternative (third compliance well
# mean larger than 7). Use the estimated standard deviation from the
# first four months of data to estimate the true population standard
# deviation in order to determine the minimal detectable difference based
# on the computed scaled minimal detectable difference, then use this
# minimal detectable difference to determine the mean level of aldicarb
# necessary to detect a difference. (The data are stored in
# EPA.09.Ex.21.1.aldicarb.df.)
#
# Note that the scaled minimal detectable difference changes from 3.4 to
# 3.9 to 4.7 as the power changes from 90% to 95% to 99%. Thus, the
# minimal detectable difference changes from 7.2 to 8.1 to 9.8, and the
# minimal mean level of aldicarb changes from 14.2 to 15.1 to 16.8.
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
#5 1 Well.2 23.7
#6 2 Well.2 21.9
#7 3 Well.2 26.9
#8 4 Well.2 26.1
#9 1 Well.3 5.6
#10 2 Well.3 3.3
#11 3 Well.3 2.3
#12 4 Well.3 6.9
sigma < with(EPA.09.Ex.21.1.aldicarb.df,
sd(Aldicarb.ppb[Well == "Well.3"]))
sigma
#[1] 2.101388
scaled.mdd < tTestScaledMdd(n.or.n1 = 4, alpha = 0.01,
power = c(0.90, 0.95, 0.99), sample.type="one", alternative="greater")
scaled.mdd
#[1] 3.431501 3.853682 4.668749
mdd < scaled.mdd * sigma
mdd
#[1] 7.210917 8.098083 9.810856
minimal.mean < mdd + 7
minimal.mean
#[1] 14.21092 15.09808 16.81086
#==========
# Clean up
#
rm(scaled.mdd, sigma, mdd, minimal.mean)