0

One Sample T-Test

Unsolved
Prob. and Stats

Difficulty: 2 | Problem written by Junaid Ahmed
Problem reported in interviews at     Write a Python function to implement a one-sample t-test. The function should return a tuple containing the t-statistic and the p-value.

A one-sample t-test is used to determine if a population's mean is equal to a given value. The test can be used with continuous data.

The equation for a one-sample t-test is:

$$Sample = \frac{x-\upsilon }{ ( \frac{s}{\sqrt{n}} ) }$$

x is the sample mean

u is the hypothesized mean

s is the sample standard deviation

n is the sample size

You should reject the null hypothesis if the p-value for the test is less than your chosen significance level.

To calculate the p-value we first have to find out the degrees of freedom of n samples.

We can also calculate this by using the formula:

$$df = n-1$$

You can convert this into a p-value by dividing the degree of freedom with the sample value.

<class 'int'>
x: 10
<class 'int'>
u: 15
<class 'int'>
n: 4
<class 'float'>
s: 8.5

Expected Output:
<class 'tuple'>
(-1.1764705882352942, 0.75)

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

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