What can happen:
Decision | ||
---|---|---|
Truth | Do not reject | Reject null |
Null true | Correct | Type I error |
Null false | Type II error | Correct |
Tension between truth and decision about truth (imperfect).
[1] 14.487469 5.014611 6.924277 5.201860 8.852952 10.835874 3.686684
[8] 11.165242 8.016188 12.383518 1.378099 3.172503 13.074996 11.353573
[15] 5.015575
x
from population with mean 10 or not (over):
One Sample t-test
data: x
t = -1.8767, df = 14, p-value = 0.08157
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
5.794735 10.280387
sample estimates:
mean of x
8.037561
List of 10
$ statistic : Named num -1.88
..- attr(*, "names")= chr "t"
$ parameter : Named num 14
..- attr(*, "names")= chr "df"
$ p.value : num 0.0816
$ conf.int : num [1:2] 5.79 10.28
..- attr(*, "conf.level")= num 0.95
$ estimate : Named num 8.04
..- attr(*, "names")= chr "mean of x"
$ null.value : Named num 10
..- attr(*, "names")= chr "mean"
$ stderr : num 1.05
$ alternative: chr "two.sided"
$ method : chr "One Sample t-test"
$ data.name : chr "x"
- attr(*, "class")= chr "htest"
[1] 0.0815652
rowwise
to work one random sample at a timetibble(sim = 1:1000) %>%
rowwise() %>%
mutate(my_sample = list(rnorm(15, 8, 4))) %>%
mutate(t_test = list(t.test(my_sample, mu = 10))) %>%
mutate(p_val = t_test$p.value) %>%
count(p_val <= 0.05)
We correctly rejected 422 times out of 1000, so the estimated power is 0.422.
power.t.test
. Input delta
is difference between null and true mean:Method | Power |
---|---|
Simulation | 0.422 |
power.t.test |
0.4378 |
n=
, replaced by a power=
:
One-sample t test power calculation
n = 33.3672
delta = 2
sd = 4
sig.level = 0.05
power = 0.8
alternative = two.sided
power.t.test
a collection (“vector”) of values, it will do calculation for each one.
One-sample t test power calculation
n = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
delta = 2
sd = 4
sig.level = 0.05
power = 0.2928286, 0.5644829, 0.7539627, 0.8693979, 0.9338976, 0.9677886, 0.9847848, 0.9929987, 0.9968496, 0.9986097
alternative = two.sided
List of 8
$ n : num [1:10] 10 20 30 40 50 60 70 80 90 100
$ delta : num 2
$ sd : num 4
$ sig.level : num 0.05
$ power : num [1:10] 0.293 0.564 0.754 0.869 0.934 ...
$ alternative: chr "two.sided"
$ note : NULL
$ method : chr "One-sample t test power calculation"
- attr(*, "class")= chr "power.htest"
[1] 0.2928286 0.5644829 0.7539627 0.8693979 0.9338976 0.9677886 0.9847848
[8] 0.9929987 0.9968496 0.9986097
delta
is true difference in meanspower.t.test
, so take as 14.
Comments
mean=10
, that is, the true mean equals the null mean, \(H_0\) is actually true, and the probability of rejecting it then is \(\alpha = 0.05\).