I consider the study of sleep after coffee. I know that
- standard deviation = 3.5 (hours of sleep)
- if the difference between the hours of sleep was at least 1.5h on average, this would be significant
I wanted to estimate the study size required to have an 75 % probability of detecting such a difference between, at a 1 % significance level.
I tried using this formula for sample size:
n = [Z-score^2 * sd * (1-sd)]/ confidence interval^2
But because 1-sd = -2.5 the whole expression becomes smaller than zero. Is there sth I do wrong?
Several important things are not clear to me from your statement of the Question. So I will make some assumptions that I hope will be helpful toward a solution. Even if not exactly correct, my assumptions may point you in the right direction. At the very least, I hope my Answer gives you the opportunity to explain your situation more fully.
In what follows I am relying heavily on the following sentence in your Question "I wanted to estimate the study size required to have an 75 % probability of detecting such a difference between, at a 1 % significance level."
Not so much on your attempted answer.
It seems you want a 'power and sample size' computation for a paired t test (one-sample t test on differences) and that you are testing $H_0: \delta = 0$ against $H_a: \delta > 0,$ where $\delta$ is the average decrease in hours of sleep in the population from drinking coffee.
You assume the population SD is $\sigma = 3.5,$ you want to reject $H_0$ against specific alternative $H_a: \delta = 1.5$ in a test at the 1% level. The question is in how many subjects $n$ do you need to find the loss of sleep $d$d from drinking coffee.
For clarity, let's look at one fictitious sample of $n = 40$ differences $d_i,$ as follows:
Then the proposed t test (in R) gives the following output. Because the P-value is $0.0006 > 0.01 = 1\%$ the test rejects at the 1% level.
Of course, this one fictitious dataset cannot provide evidence that $n = 40$ is enough subjects. For one thing, our data have sample SD about $3.1,$ which happens to be smaller than the assumed population $\sigma = 3.5.$
However, one can look at 100,000 such datasets to see what rejection rate we get. Is it the required 75%? A little experimentation shows that to get a power of 75% we need about $n = 52.$
Notes: (1) The numerical vector
pvcontains P-values from 100,000 P-values, the logical vectorpv <= .01contains 100,000TRUEs andFALSEs, and itsmeanis its proportion ofTRUEs (rejections).(2) Many mathematical statistics texts give an exact formula, involving non-central t distributions, to find power for a given sample size. Also, there are online calculators and software packages that do exact 'power and sample size' computations.
(3) Your attempted Answer seems to use the formula for a confidence interval, I don't see how that leads to what you say you want.
(4) Usually coffee leads to loss of sleep, so I think you need a one-sided procedure. (A two-sided test would require more observations than a one-sided test.)