0
0
Data Analysis Pythondata~10 mins

P-values and significance in Data Analysis Python - Interactive Code Practice

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

Complete the code to calculate the p-value from a t-test.

Data Analysis Python
from scipy import stats
sample1 = [5, 6, 7, 8, 9]
sample2 = [5, 5, 6, 7, 8]
t_stat, p_value = stats.ttest_ind(sample1, sample2)
print('P-value:', [1])
Drag options to blanks, or click blank then click option'
Asample1
Bp_value
Ct_stat
Dstats
Attempts:
3 left
💡 Hint
Common Mistakes
Using the t-statistic instead of the p-value.
Printing the function instead of the variable.
2fill in blank
medium

Complete the code to check if the p-value is less than the significance level 0.05.

Data Analysis Python
p_value = 0.03
if p_value [1] 0.05:
    print('Reject the null hypothesis')
else:
    print('Fail to reject the null hypothesis')
Drag options to blanks, or click blank then click option'
A<
B>=
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < for the comparison.
Checking equality instead of less than.
3fill in blank
hard

Fix the error in the code to correctly calculate the p-value for a paired t-test.

Data Analysis Python
from scipy import stats
before = [20, 21, 19, 22, 20]
after = [22, 23, 20, 24, 21]
t_stat, p_value = stats.ttest_rel(before, [1])
print('P-value:', p_value)
Drag options to blanks, or click blank then click option'
Aafter
Bstats
Cbefore
Dttest_rel
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the same sample twice.
Passing the function name instead of data.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their lengths, but only include words longer than 3 letters.

Data Analysis Python
words = ['apple', 'cat', 'banana', 'dog', 'pear']
lengths = { [1]: len([2]) for word in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Bwords
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using the list 'words' instead of the variable 'word'.
Using 'len' as a key instead of the word.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths, including only words with length greater than 4.

Data Analysis Python
words = ['apple', 'cat', 'banana', 'dog', 'pear']
result = { [1]: [2] for word in words if len(word) [3] 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase.
Using wrong comparison operator.