test_t1: One Sample T-Test Study Planning

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/test_t1.R

Description

Calculates the power, sample size, difference of means, standard deviation, or significance level of a one sample t-test with options for one and two sided testing.

Usage

1
2
test_t1(delta = NULL, n = NULL, sd = NULL, alpha = 0.05, power = NULL,
  two.tail = TRUE, mu0 = NA, mu1 = NA)

Arguments

delta

The difference of means to be tested. This may also be specified using mu0 and mu1, if desired. If all three of these arguments are specified, delta overrides the other two.

n

The sample size

sd

The standard deviation of the difference

alpha

The significance level

power

The power of the test

two.tail

Logical. Determines if the calculations assume one or two sided testing. This may be a vector (ie, c(TRUE, FALSE))

mu0,mu1

Group means for calculating delta. The difference is always calculated as mu1 - mu0. These may be specified in place of delta and are used to calculate delta before verifiying that only one of the arguments in NULL. Thus, delta and one other argument may be NULL so long as these arguments are specified. Recycling is used if they are not the same length.

Details

Exactly one of the parameters delta, n, sd, alpha, and power must be passed as NULL. The only exception is that delta may be passed as a second NULL when mu0 and mu1 are specified.

The parameters are combined via expand.grid, so all combinations of the inputs are evaluated.

Value

Returns a data frame with the columns listed below.

  1. mu0 The hypothesized mean (only if mu0 is not NA)

  2. mu1 The alternative mean (only if mu1 is not NA)

  3. delta The difference of means

  4. sd The standard deviation of the difference of means

  5. alpha The significance level of the test.

  6. power The power of the test

  7. two.tail a logical indicating if the test assumes one or two tails

  8. n_est The exact estimated sample size. This will equal n whenever n is not NULL

  9. n The integer sample size obtained by ceiling(n_est).

Author(s)

Benjamin Nutter

References

Hogg RV, McKean JW, Craig AT, Introduction to Mathematical Statistics, Pearson Prentice Hall 6th ed., 2005. ISBN: 0-13-008507-3

See Also

power.t.test, optimize, uniroot,
vignette("TTestOneSample", package="StudyPlanning")

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
test_t1(delta=1, n=20, sd=1, two.tail=TRUE)

#* Compare to one-sample version of example from the \code{stats} package
power.t.test(n = 20, delta = 1, type="one.sample")



#* Illustrate the multiple inputs
test_t1(delta=1, sd=1, power=0.90, two.tail=c(TRUE, FALSE))

#* Compare with the examples from stats package
power.t.test(power = .90, delta = 1, type="one.sample")
power.t.test(power = .90, delta = 1, type="one.sample", alternative = "one.sided")

nutterb/StudyPlanning documentation built on May 24, 2019, 10:51 a.m.