Chapter07_power {DanielBiostatistics10th} | R Documentation |
Functions for Chapter 7, Hypothesis Testing.
power_z(
x,
null.value,
sd,
n,
alternative = c("two.sided", "less", "greater"),
sig.level = 0.05
)
x |
numeric vector, mean parameter(s) |
null.value |
numeric scalar, mean parameter |
sd |
numeric scalar, population standard deviation |
n |
integer scalar, sample size |
alternative |
character scalar, alternative hypothesis,
either |
sig.level |
numeric scalar, significance level (i.e., Type-I-error rate), default |
Function power_z()
calculates the powers at each element of the alternative parameters \mu_1
, for one-sample z
-test
H_0: \mu = \mu_0
vs. H_A: \mu \neq \mu_0
, if alternative = 'two.sided'
H_0: \mu \leq \mu_0
vs. H_A: \mu > \mu_0
, if alternative = 'greater'
H_0: \mu \geq \mu_0
vs. H_A: \mu < \mu_0
, if alternative = 'less'
Function power_z()
returns a 'power_z'
object,
which inherits from 'power.htest'
class.
Wayne W. Daniel, Biostatistics: A Foundation for Analysis in the Health Sciences, Tenth Edition. Wiley, ISBN: 978-1-119-62550-6.
library(DanielBiostatistics10th)
# Page 272, Example 7.9.1
(p791 = power_z(seq.int(from = 16, to = 19, by = .5), null.value = 17.5, sd = 3.6, n = 100L))
# Page 275, Table 7.9.1
autoplot(p791) + labs(title = 'Page 275, Figure 7.9.2')
# Page 276, Example 7.9.2
(p792 = power_z(seq.int(from = 50, to = 70, by = 5), null.value = 65, sd = 15, n = 20L,
sig.level = .01, alternative = 'less'))
autoplot(p792) + labs(title = 'Page 277, Figure 7.9.4')
# Page 278, Example 7.10.1
(n_d7101 <- uniroot(f = function(x) {
power_z(55, null.value = 65, sd = 15, n = x, sig.level = .01, alternative = 'less')$power - .95
}, interval = c(0, 50))$root)
power_z(55, null.value = 65, sd = 15, n = ceiling(n_d7101), sig.level = .01, alternative = 'less')