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
[6] 10.835874 3.686684 11.165242 8.016188 12.383518
[11] 1.378099 3.172503 13.074996 11.353573 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"
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
[1] 0.94908647 0.99956360 0.88277128 0.99619287
[5] 0.77070660 0.97770385 0.61513033 0.91115700
[9] 0.43784659 0.75396272 0.27216777 0.51028173
[13] 0.14530058 0.26245348 0.06577280 0.09719303
[17] 0.02500000 0.02500000
pulling things from the right places:
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\).