Python-112 Paired Samples T-Test

2021-07-04  本文已影响0人  RashidinAbdu
Concept:

Background:

1. Data from excel or given arrays:

image.png

2.Given arrays:
group3 = [88, 82, 84, 93, 75, 78, 84, 87, 95, 91, 83, 89, 77, 68, 91]
group4 = [91, 84, 88, 90, 79, 80, 88, 90, 90, 96, 88, 89, 81, 74, 92]

3. Do the test:
#pip install scipy
#pip install openpyxl
import pandas as pd
import numpy as np

# read the data from excel
group1 = np.array(pd.read_excel('C:/Users/Mr.R/Desktop/excels/zm.xlsx', sheet_name='1', usecols='C'))
group2 = np.array(pd.read_excel('C:/Users/Mr.R/Desktop/excels/zm.xlsx', sheet_name='1', usecols='D'))
print(group1, group2)
import scipy.stats as stats
#perform the paired samples t-test
paired_samples_t_test1_2 = stats.ttest_rel(group1, group2)

print("\n paired_samples_t_test1_2 result :\n", paired_samples_t_test1_2)


#or two arrays
group3 = [88, 82, 84, 93, 75, 78, 84, 87, 95, 91, 83, 89, 77, 68, 91]
group4 = [91, 84, 88, 90, 79, 80, 88, 90, 90, 96, 88, 89, 81, 74, 92]
paired_samples_t_test_3_4 = stats.ttest_rel(group3, group4)
print("\n Here is paired_samples_t_test_3_4 result:\n", paired_samples_t_test_3_4)

# Interpret the results.
# In this example, the paired samples t-test uses the following null and alternative hypotheses:
# H0: The mean pre-test and post-test scores are equal
# HA:The mean pre-test and post-test scores are not equal
# Since the p-value (0.0101) is less than 0.05, we reject the null hypothesis.
# We have sufficient evidence to say that the true mean test score is different
# for group3 and group4.
test results:
image.png
5. Interpret the results:
In this example, the paired samples t-test uses the following null and alternative hypotheses:

上一篇 下一篇

猜你喜欢

热点阅读