# How can I derive the needed sample size for two independent sample t test?

Given two samples $$X_1$$ and $$X_2$$ of sizes $$n_1$$ and $$n_2$$. I need to test $$H_0 : EX_1 = EX_2 \\ H_1 : EX_2 < EX_1$$ with fixed type 1 error $$\alpha$$ and type 2 error $$\beta$$. How can I derive the needed $$n$$ for this?

My thoughts are the following: we can use T test, and calculate $${\displaystyle t={\frac {{\overline {X}}_{1}-{\overline {X}}_{2}}{\sqrt {{\frac {s_{1}^{2}}{n_{1}}}+{\frac {s_{2}^{2}}{n_{2}}}}}}.}$$ If $$H_0$$ is correct then it would be T distribution (which is close to normal distribution). Thus we can from $$P(t > c) = \alpha$$ calculate threshold $$c$$ to ensure level of significance $$\alpha$$ . I suppose I need to derive $$n$$ (for simplicity assume $$n_1 = n_2 = n$$) from $$\beta$$ but how can I do that? Also can I use this test for such (one-sided) task? It looks good when $$H_1:EX_2 \neq EX_1$$ because in that case because of symmetry of T distribution it would be $$P(t>c) = \frac{\alpha}{2}$$ , can I use it in general in case of $$H_1 : EX_2 < EX_1$$?

Remember the formula for the margin of error=ME for a $$2$$ sided t confidence interval for $$\mu_{1,2}$$ with $$n_1=n_2=n$$:

$$\text{ME}=t^*\ \sqrt{\frac{\text{var}(x_1)+\text{var}(x_2)}{n}}$$

Therefore:

$$n=({\text{var}(x_1)+\text{var}(x_2)})\left(\frac{t^*}{\text{ME}}\right)^2$$

When you know the margin of error, $$3$$ percent points for example, the confidence level, $$s_1^2$$, and $$s_2^2$$, then you estimate $$t^*\approx\text{InvNormCD}\left(\text{area}=\frac{1-C}2\right)$$, assuming $$n\ge 30$$ by the large counts condition:

$$n\ge({\text{var}(x_1)+\text{var}(x_2)})\left(\frac{t^*}{\text{ME}}\right)^2$$

If $$n$$ should be less than $$30$$, then maybe use an estimate