您现在的位置是:首页 >其他 >使用Python结算两组结果的paired T-test网站首页其他
使用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
|
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()