What can happen:
| Truth/Decision | 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
First, find out what it is called, which means saving the output from t.test:
[1] "statistic" "parameter" "p.value" "conf.int"
[5] "estimate" "null.value" "stderr" "alternative"
[9] "method" "data.name"
and then
rowwise to work one random sample at a timeWe correctly rejected 422 times out of 1000, so the estimated power is 0.422.
set.seed with any whole number, like 1 or 123. I use an old phone number: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.36713
delta = 2
sd = 4
sig.level = 0.05
power = 0.8
alternative = two.sided
No strict here:
Try a sample size and see what power you get. Here’s \(n = 15\) from before:
To get power 0.80, two-sided, need a bigger sample.
How much bigger? No idea. Make any guess. What about \(n = 50\)?
Power now too big.
sample size between 15 and 50, say \(n = 30\):
Now a little too small, hence right answer between 30 and 50, closer to 30.
… simulation has randomness: limit to how close you can get.
Rule of thumb: with 1000 simulations, estimated power within 0.03 (3%).
n_sim (say, 1000) and \(p\).prop.test will find you a confidence interval for a proportion.so we believe the true power is between 0.801 and 0.849, with 95% confidence.
we were aiming for 0.80 power, so this just misses on the high side; a slightly smaller sample is needed.
rule of thumb: if power close to 0.5, 1000 simulations gives 95% CI of about \(0.5 \pm 0.03\):
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.2931756, 0.5645044, 0.7539647, 0.8693981, 0.9338976, 0.9677886, 0.9847848, 0.9929987, 0.9968496, 0.9986097
alternative = two.sided
[1] 0.9490865 0.9995636 0.8827714 0.9961929
[5] 0.7707080 0.9777038 0.6151420 0.9111571
[9] 0.4379267 0.7539647 0.2726180 0.5103210
[13] 0.1473796 0.2629625 0.0736926 0.1015567
[17] 0.0500000 0.0500000
pulling things from the right places:
delta is true difference in meanspower.t.test, so take as 14.No strict (one-sided):
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\).