0

One Sample T-Test

Unsolved
Prob. and Stats

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

Amazon
Apple
Facebook
Google
Netflix

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. 

 

 

Sample Input:
<class 'list'>
x: 10
u: 15
n: 4
s: 8.5

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

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.

Nulla repellendus adipisci fuga impedit numquam vero accusantium quod deserunt porro veniam, distinctio officia dolore maiores nulla illum aut beatae omnis, repellendus repudiandae exercitationem soluta vitae eaque minima aliquid animi, quasi laborum enim, laborum fugit in quos inventore esse suscipit architecto animi? Repudiandae eum iusto obcaecati, sit cumque dolore cupiditate deserunt, obcaecati ea eos aliquid provident labore pariatur totam ipsam nihil similique, exercitationem minima veritatis numquam eius ab assumenda dolor repellat, dicta ipsa facere obcaecati sapiente alias? Vitae et delectus cum soluta eum possimus culpa quae aliquam earum, perspiciatis minima magnam exercitationem?

Doloribus consequuntur repellat modi voluptates odit aperiam voluptate vitae molestiae iste, nostrum dolorem eum, tempore ratione assumenda quam nemo iure, quas repellendus harum nobis veritatis aliquam fuga non accusamus cumque excepturi, aperiam iure quidem mollitia unde sed quo ducimus in?

Ut fuga ipsum eum facere dolorem cumque quaerat voluptatibus necessitatibus aliquid, non doloremque rem assumenda accusamus possimus nesciunt amet voluptates in, atque sunt exercitationem rerum error hic beatae quisquam consectetur quam, sapiente consectetur mollitia illum incidunt?

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)