0

Student T-test Power Analysis

Unsolved
Prob. and Stats

Difficulty: 2 | Problem written by Junaid Ahmed
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

A student T-test power analysis will produce a p-value that indicates if the samples are identical or if there's a statistical difference between them. It works on the basis of four parameters: effect, power, alpha, and ratio.

Alpha is the probability of eliminating the null hypothesis when it becomes true.

If the value of alpha is 0.05 then there's a 5% chance of difference exists when there is no actual difference.

The effect defines the difference between the means in terms of the number of standard deviations.

The statistical power defines that our test has an 80% chance of ending with a p-value less than 5% if the power is 80%.

The ratio is the percentage of a number of samples to the other samples. If both samples have the same number of observations then the ratio is 1.0. If the second sample is less than the first then it is 0.5

How we can implement it in Python?

Python provides a library named stats model to implement this.

Import TTestIndPower function from the statsmodels.stats.power

Create a TTestIndPower instance.

Implement the solver_power function with four parameters and an additional argument named nobs1 that will be declared as None. It will tell the function what to calculate.

This whole function will return the sample size for the experiment.

Sample Input:
<class 'list'>
e: 0.8
a: 0.05
p: 0.8

Expected Output:
<class 'float'>
25.524572500479444

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Molestias fuga consequuntur cum assumenda modi quidem harum natus.

Accusantium maiores provident animi, debitis sapiente quis. Vel adipisci nam similique ratione alias incidunt, quibusdam sapiente pariatur voluptatum voluptate quae esse doloribus assumenda iste repudiandae, provident placeat debitis in temporibus consequuntur culpa numquam quaerat animi, qui non repudiandae dolorem voluptatem commodi, sed natus rem dicta nulla distinctio mollitia quis aut nemo?

Molestias itaque rerum recusandae beatae voluptate vero alias ad eligendi autem quas, ad nobis nihil commodi aspernatur laborum, culpa expedita laborum reprehenderit facilis quae quasi unde?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)