EME 210
Data Analytics for Energy Systems

Paired Mean of Differences One-Line Test

PrintPrint

Paired Mean of Differences One-Line Test

Read It: Paired Mean of Differences One-Line Test

To conduct the one-line test for a paired mean of differences hypothesis test, you will use a t-test for two related samples. Below, we demonstrate how to implement this code.

 Watch It: Video - Hypothesis Test for Two Samples: Mean of Differences (Paired Comparison) (2:03 minutes)

Click here for a transcript.

In this video, we're going to talk about the one-line test for doing a mean of differences, or a paired comparison test. And so, in this test we're still using those natural gas and wind data we needed to calculate the difference, and then take the mean of that difference. And then we did this randomization procedure where we calculated a multiplier to figure out if that difference was equal to zero or not equal to zero. And eventually we calculated a p-value, which resulted in rejecting the null hypothesis. And so, this one minor test, again as I've done with most of these I'm going to call it results, and say stats dot t-test. And in this case, it's rel to signify that this data is not independent that we are doing a paired comparison test we still give it our first sample, sample gas, making sure that it follows that order that we've talked about before. our second sample, sample wind. And in this case all we need to do specify the alternative equal to less and do results dot key value. And so, we can see what our p-value is. It's very close to zero. We reject the null hypothesis, but we can note that there is a little bit more specificity with this one-line test than with our randomization procedure.

Credit: © Penn State is licensed under CC BY-NC-SA 4.0

Try It: Google Colab

  1. Click the Google Colab file used in the video here.
  2. Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
  3. Once you have it saved in your Drive, try to edit the following code to run the paired mean of differences one-line test. Remember to import the libraries and run the code to create some data.

Note: You must be logged into your PSU Google Workspace in order to access the file.

# Libraries
import numpy as np
import scipy.stats as stats

# create some data
x = np.random.randint(0,100,1000)
y = np.random.randint(0,200,1000)

# implement one-line test
results = ...
results.pvalue

Once you have implemented this code on your own, come back to this page to test your knowledge.


 Assess It: Check Your Knowledge

Knowledge Check