您现在的位置是:首页 >其他 >使用Python结算两组结果的paired T-test网站首页其他

使用Python结算两组结果的paired T-test

DeniuHe 2024-06-14 17:19:50
简介使用Python结算两组结果的paired T-test

How to Conduct a Paired Samples T-Test in Python - GeeksforGeeks

 

Paired sample T-test: This test is also known as the dependent sample t-test. It is a statistical concept and is used to check whether the mean difference between the two sets of observation is equal to zero.  Each entity is measured is two times in this test that results in the pairs of observations.

Syntax to install Scipy library in our system :

pip install scipy

How to conduct a paired samples T-Test in Python?

Let us consider that we want to know whether an engine oil significantly impacts the car’s mileage of different brands. In order to test this, we have 10 cars in a garage doped with original engine oil initially. We have noted their mileage for 100 kilometers each. Then, we have each of the cars doped with another engine oil (different from the original one). Then, the mileage of the cars is calculated for 100 kilometers each. To compare the difference between the mean mileage of the first and second test, we use a paired samples t-test because for each car their first test score can be paired with their second test score. Conducting paired sample T-test is a step-by-step process.

Step 1: Construct the data.

We need two arrays to hold pre and post-mileage of the cars.

  • Python3

# pre holds the mileage before applying

# the different engine oil

pre = [88, 82, 84, 93, 75, 78, 84, 87,

       95, 91, 83, 89, 77, 68, 91]

  

# post holds the mileage before applying 

# the different engine oil

post = [91, 84, 88, 90, 79, 80, 88, 90

        90, 96, 88, 89, 81, 74, 92]

Step 2: Conducting a paired-sample T-test.

Scipy library contains ttest_rel() function using which we can conduct the paired samples t-test in Python. The syntax is given below,

Syntax:

ttest_rel(arr1, arr2)

Parameters:

  • arr1: It represents an array of sample observations from group 1
  • arr2: It represents an array of sample observations from group 2

据外网资源查找结果,

一般使用scipy中的ttest_rel() 

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。