0
0
SciPydata~10 mins

t-test (ttest_ind, ttest_rel) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function for independent t-test from scipy.stats.

SciPy
from scipy.stats import [1]

# Now you can use this function to compare two independent samples
Drag options to blanks, or click blank then click option'
Attest_rel
Bttest_ind
Cttest_1samp
Dttest_paired
Attempts:
3 left
💡 Hint
Common Mistakes
Using ttest_rel which is for related samples.
Trying to import a non-existent function like ttest_paired.
2fill in blank
medium

Complete the code to perform a related t-test on two paired samples.

SciPy
from scipy.stats import ttest_rel

sample1 = [5, 7, 8, 6, 9]
sample2 = [6, 8, 7, 7, 10]

result = ttest_rel([1], sample2)
print(result)
Drag options to blanks, or click blank then click option'
Asample1
Bsample2
Csample1 + sample2
Dsample1 * sample2
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the samples or using combined lists.
Using arithmetic operations instead of sample lists.
3fill in blank
hard

Fix the error in the code to correctly perform an independent t-test between two groups.

SciPy
from scipy.stats import ttest_ind

group_a = [12, 15, 14, 10, 13]
group_b = [9, 11, 10, 8, 12]

result = ttest_ind(group_a, [1])
print(result)
Drag options to blanks, or click blank then click option'
A[group_a, group_b]
Bgroup_a
Cgroup_b
Dgroup_a + group_b
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the same group twice.
Passing a list of groups or concatenated lists.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores t-test p-values for pairs of samples.

SciPy
samples = {'A': [1, 2, 3], 'B': [2, 3, 4], 'C': [3, 4, 5]}
from scipy.stats import ttest_ind

p_values = {key: ttest_ind(samples[key], samples[[1]]).pvalue for key in samples if key != [2] and key != 'C'}
Drag options to blanks, or click blank then click option'
A'B'
B'A'
C'C'
D'D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same sample for both blanks.
Using samples not in the dictionary.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores t-test statistics for pairs of samples where the statistic is greater than 2.

SciPy
samples = {'X': [10, 12, 11], 'Y': [9, 11, 10], 'Z': [13, 15, 14]}
from scipy.stats import ttest_ind

results = {k: ttest_ind(samples[k], samples[[1]]).statistic for k in samples if k != [2] and ttest_ind(samples[k], samples[[3]]).statistic > 2}
Drag options to blanks, or click blank then click option'
A'Y'
B'X'
C'Z'
D'W'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent samples in blanks.
Using samples not in the dictionary.