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 'float'>
e: 0.8
<class 'float'>
a: 0.05
<class 'float'>
p: 0.8

Expected Output:
<class 'float'>
25.524572500479444

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Get access to Premium only exclusive educational content available to only Premium users.

Have an issue, the MLPro support team is available 24X7 to Premium users.

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

Log in to post a comment

Comments
Ready.

Input Test Case

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