Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/simPowerTTest.R
Simulate the empirical power and typeIerror of twosample ttests; i.e., classical (equal variances), Welch and Hsu ttests.
1 2 3 4  sim.power.t.test(nx, rx, rx.H0 = NULL, ny, ry, ry.H0 = NULL,
sig.level = 0.05, mu = 0,
alternative = c("two.sided", "less", "greater"),
iter = 10000)

nx 
single numeric, sample size of first group. 
rx 
function to simulate the values of first group (assuming H1). 
rx.H0 

ny 
single numeric, sample size of second group. 
ry 
function to simulate the values of second group (assuming H1). 
ry.H0 

sig.level 
significance level (type I error probability) 
mu 
true value of the location shift for the null hypothesis. 
alternative 
one or twosided test. Can be abbreviated. 
iter 
single integer, number of interations of the simulations. 
Functions rx
and ry
are used to simulate the data under the
alternative hypothesis H1. If specified, functions rx.H0
and ry.H0
simulte the data unter the null hypothesis H0.
For fast computations functions from package matrixTests
are used.
Object of class "sim.power.ttest"
with the results of the three ttests
in the list elements Classical
, Welch
and Hsu
. In addition,
the simulation setup is saved in element SetUp
.
Matthias Kohl [email protected]
J. Hedderich, L. Sachs. Angewandte Statistik: Methodensammlung mit R. Springer 2018.
Hsu, P. (1938). Contribution to the theory of “student's” ttest as applied to the problem of two samples. Statistical Research Memoirs 2: 124.
Student (1908). The Probable Error of a Mean. Biometrika, 6(1): 125.
Welch, B. L. (1947). The generalization of “Student's” problem when several different population variances are involved. Biometrika, 34 (12): 2835.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62  ## Equal variance, small sample size
power.t.test(n = 5, delta = 2)
power.welch.t.test(n = 5, delta = 2)
power.hsu.t.test(n = 5, delta = 2)
sim.power.t.test(nx = 5, rx = rnorm, rx.H0 = rnorm,
ny = 5, ry = function(x) rnorm(x, mean = 2), ry.H0 = rnorm)
## Equal variance, moderate sample size
power.t.test(n = 25, delta = 0.8)
power.welch.t.test(n = 25, delta = 0.8)
power.hsu.t.test(n = 25, delta = 0.8)
sim.power.t.test(nx = 25, rx = rnorm, rx.H0 = rnorm,
ny = 25, ry = function(x) rnorm(x, mean = 0.8), ry.H0 = rnorm)
## Equal variance, high sample size
power.t.test(n = 100, delta = 0.4)
power.welch.t.test(n = 100, delta = 0.4)
power.hsu.t.test(n = 100, delta = 0.4)
sim.power.t.test(nx = 100, rx = rnorm, rx.H0 = rnorm,
ny = 100, ry = function(x) rnorm(x, mean = 0.4), ry.H0 = rnorm)
## Unequal variance, small sample size
power.welch.t.test(n = 5, delta = 5, sd1 = 1, sd2 = 3)
power.hsu.t.test(n = 5, delta = 5, sd1 = 1, sd2 = 3)
sim.power.t.test(nx = 5, rx = rnorm, rx.H0 = rnorm,
ny = 5, ry = function(x) rnorm(x, mean = 5, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
## Unequal variance, moderate sample size
power.welch.t.test(n = 25, delta = 1.8, sd1 = 1, sd2 = 3)
power.hsu.t.test(n = 25, delta = 1.8, sd1 = 1, sd2 = 3)
sim.power.t.test(nx = 25, rx = rnorm, rx.H0 = rnorm,
ny = 25, ry = function(x) rnorm(x, mean = 1.8, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
## Unequal variance, high sample size
power.welch.t.test(n = 100, delta = 0.9, sd1 = 1, sd2 = 3)
power.hsu.t.test(n = 100, delta = 0.9, sd1 = 1, sd2 = 3)
sim.power.t.test(nx = 100, rx = rnorm, rx.H0 = rnorm,
ny = 100, ry = function(x) rnorm(x, mean = 0.9, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
## Unequal variance, unequal sample sizes
## small sample sizes
sim.power.t.test(nx = 10, rx = rnorm, rx.H0 = rnorm,
ny = 5, ry = function(x) rnorm(x, mean = 5, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
sim.power.t.test(nx = 5, rx = rnorm, rx.H0 = rnorm,
ny = 10, ry = function(x) rnorm(x, mean = 3, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
## Unequal variance, unequal sample sizes
## moderate sample sizes
sim.power.t.test(nx = 25, rx = rnorm, rx.H0 = rnorm,
ny = 50, ry = function(x) rnorm(x, mean = 1.5, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))
## Unequal variance, unequal sample sizes
## high sample sizes
sim.power.t.test(nx = 100, rx = rnorm, rx.H0 = rnorm,
ny = 200, ry = function(x) rnorm(x, mean = 0.6, sd = 3),
ry.H0 = function(x) rnorm(x, sd = 3))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.