0
0
SciPydata~30 mins

t-test (ttest_ind, ttest_rel) in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Performing Independent and Paired t-tests with SciPy
📖 Scenario: You are a data analyst working with a health study team. They collected two sets of data:Step 1: Blood pressure readings from two different groups of patients (Group A and Group B).Step 2: Blood pressure readings from the same patients before and after a treatment.Your job is to use t-tests to find out if there are significant differences between these groups.
🎯 Goal: Build a Python program that:Creates two lists of blood pressure readings for Group A and Group B.Creates two lists of blood pressure readings for the same patients before and after treatment.Uses ttest_ind to compare Group A and Group B.Uses ttest_rel to compare before and after treatment readings.Prints the t-test statistics and p-values for both tests.
📋 What You'll Learn
Create lists with exact blood pressure values for Group A and Group B.
Create lists with exact blood pressure values for before and after treatment.
Import ttest_ind and ttest_rel from scipy.stats.
Use ttest_ind with Group A and Group B lists.
Use ttest_rel with before and after treatment lists.
Print the t-statistic and p-value for both tests.
💡 Why This Matters
🌍 Real World
T-tests are used in health studies, marketing, and social sciences to compare groups and measure effects of treatments or changes.
💼 Career
Data analysts and scientists use t-tests to validate hypotheses and support decision-making with data.
Progress0 / 4 steps
1
Create blood pressure data lists for two groups
Create two lists called group_a and group_b with these exact blood pressure readings: group_a = [120, 122, 119, 130, 128] and group_b = [115, 117, 113, 120, 118].
SciPy
Need a hint?

Use square brackets to create lists with the exact numbers given.

2
Create blood pressure data lists for before and after treatment
Create two lists called before_treatment and after_treatment with these exact blood pressure readings: before_treatment = [130, 128, 135, 140, 138] and after_treatment = [125, 123, 130, 135, 132].
SciPy
Need a hint?

Use the exact variable names and values given to create the lists.

3
Import t-test functions and perform tests
Import ttest_ind and ttest_rel from scipy.stats. Then create two variables: independent_test to store the result of ttest_ind(group_a, group_b) and paired_test to store the result of ttest_rel(before_treatment, after_treatment).
SciPy
Need a hint?

Use the exact import statement and function calls as shown.

4
Print the t-test results
Print the t-statistic and p-value from independent_test and paired_test using these exact print statements:
print(f"Independent t-test: t = {independent_test.statistic:.3f}, p = {independent_test.pvalue:.3f}")
print(f"Paired t-test: t = {paired_test.statistic:.3f}, p = {paired_test.pvalue:.3f}")
SciPy
Need a hint?

Use f-strings to format the output with 3 decimal places as shown.