Formulas to calculate sample size [Power / Sample Size]

posted by ElMaestro  – Belgium?, 2019-02-04 13:27 (659 d 21:53 ago) – Posting: # 19857
Views: 2,634

Hi BE-proff,

» Can anybody share formula of formulas set for relevant calculations? :confused:

This is a great challenge you awarded yourself.:-D
Sample size calculation is not a set of deterministic equations (yet?!?), but usually involve integrals.

For a start try and look at Potvin's paper.
Here you'll find a very decent approximation which is based on the central t test. This provides the "exact" solution when the expected match is 100% and it is a very decent* approximation in most other relevant case whenever desired power is above the magical 80%. Perhaps you can start there and then make it more complicated and exact once you get into it?

Here's how I would approach it (and I am assuming you are not relying on external libraries**):
1. Make a function for the density of central t at any level of df.
2. Make a function that can integrate it, from minus infinity to some arbitrary value x.
3. Make a function that can find the critical value of the central t for an arbitrary p-level between 0 and 1. This one may be a little tricky if you write it from scratch but you can find inspiration by googling Russel Lenth's ASA243 Al Gore Rhythm. I imagine you can also find some py code on the www but I am not certain about it.

With those three at hand you can reproduce power.TOST sand sampleN.TOST values using the central t approximation by insertion into the equation from Potvin. You may be able to find a way to import and use gsl or similar libraries in python, then it is simply a matter of calling some functions. Can't help with the implementation of it as I don't do python.

Next, if you are hardcore you can look into noncentral t and Owen's Q. If you can write the framework above then you have all the skill at hand to also do this last step.
This will give you the opportunity to get anything power.TOST does.

Happy coding. Interested to hear of your further achievements, so please keep me posted.

* I am sure the BE police will spank me for saying so but I am willing to defend my words.:-D
** I am also willing to at least read posts asking why someone would want to reinvent the wheel. :-D

I could be wrong, but...

Best regards,

No, of course you do not need to audit your CRO if it was inspected in 1968 by the agency of Crabongostan.

Complete thread:

 Admin contact
21,209 posts in 4,426 threads, 1,481 registered users;
online 23 (1 registered, 22 guests [including 15 identified bots]).
Forum time: Wednesday 11:21 CET (Europe/Vienna)

You can’t fix by analysis
what you bungled by design.    Richard J. Light, Judith D. Singer, John B. Willett

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz