Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

HW06: hypothesis tests

DEADLINE: Wednesday, November 12th, 2025

Compare the tt and normal distributions

In class, we learned that for hypothesis testing of differences in means, the test statistic is called Student’s tt or just tt. The tt distribution is similar but not identical to the standard normal distribution, especially for small sample sizes. Its exact shape depends on the degrees of freedom, denoted ν\nu. For the difference in two means, this is simply ν=N1+N22\nu=N_1+N_2-2, where N1N_1 and N2N_2 are the sample sizes of the first and second samples, respectively.

Using scipy.stats.t.pdf and scipy.stats.norm.pdf, plot the PDFs of both distributions spanning from -5 to 5. For the tt distribution, overlay 3 different versions on the same axes: ν=1,10\nu=1, 10, and 100. Add a legend labeling each of these and the normal.

This demonstrates that, as the sample sizes grow, the tt distribution increasingly is well approximated by the standard normal. (In fact, it holds mathematically that the tt distribution approaches the standard normal exactly as ν\nu\rightarrow\infty.)

Find the most helpful online resources on tt tests you can find

There are tons of great resources that are available online and completely free. These include blog posts, YouTube videos, tutorials in the documentation to statistical software packages, whole semester-length university classes that have been pre-recorded, and more. (The course resources page lists just a few.) An important but overlooked skill (you could call it a meta skill) for scientists and engineers is learning to make use of these resources.

For this assignment, search the web to find the best two different resources you can. They can be any of the types listed above or something else.

  • For each resource: provide the URL to the resource and describe how you found it.

  • If it’s a YouTube video, embed the video in your Jupyter notebook.

  • Write summaries in your own words of what each resource conveys.

  • Describe one or more things that each resource helped you understand.

  • Describe one or more things that each resource did not help you with, either because it was missing or was included but you’re still unclear on it.

  • Rank the two resources: which was more helpful and why?

Write your own functions for computing the tt statistic and pp value

Write a python function that computes a tt test for the difference in means between two samples. You can import any functions, modules, or packages that you’d like for this purpose other than any that directly compute the tt statistic or corresponding pp value. (For example, you can’t use scipy.stats.ttest_ind, since it directly outputs both tt and pp

Your functions’ call signatures should be as follows:

def t_stat(sample1, sample2):
    """Compute the t statistic for difference in means of the two samples.
    
    Arguments:

    sample1, sample2: xarray.DataArrays, each containing one of the 
                      two samples to compute the t statistic for

    """
    # Insert your code here for computing the t statistic
    return t_stat


def pval_of_ttest(t_stat, deg_free):
    """Compute the p value of of the given t statistic and degrees of freedom.
    
    Arguments:

    t_stat: scalar, the value of the t statistic
    deg_free: scalar, the number of degrees of freedom corresponding to t_stat

    """
    # Insert your code here for computing the p value
    return p_val

Where t_stat is the value of the tt statistic, and p_val is the corresponding pp value.

Specifically, for each of the following pairs of samples from the Central Park dataset:

  1. Across all years 1869-2022, monthly average precipitation in September vs. in January.

  2. Average annual sum of cooling degree days for the period 1971-2000 vs. 2001-2022.

Use numpy.isclose to explicitly test your values against the results of scipy.stats.ttest_ind.

Extra credit

Compute the tt test for two or more salient differences-in-mean for your final project.

Find at least two pairs of sample means from your datasets whose difference are scientifically interesting for your project. Perform the tt test for each. Report the numerical values of the tt statistic, pp value, degrees of freedom. Describe your interpretation of the tt test from a statistical perspective. Also describe your interpretaiton from a physical/scientific perspective.

Create a dedicated conda environment for this course

The Resources page explains why it’s a good idea to create separate virtual environments for different projects/classes/ etc. using the Anaconda/conda environment manager. For this extra credit opportunity, create a dedicated environment using Anaconda Navigator or the conda command line tool. The environment must be created specifically for this purpose; you could name it eas42000 or eas-a4200 for example.

To show that you have done this, include the following cell in your notebook.

import os
import sys
import jupyter_core

print(f"Path to the active Python executable: {sys.executable}") 
print(f"Path to the active Jupyter installation: {jupyter_core.__file__}")
print(f"""Currently active conda environment: {os.environ.get("CONDA_DEFAULT_ENV")}""")
Path to the active Python executable: /Users/sah2249/miniconda3/envs/stats-book/bin/python
Path to the active Jupyter installation: /Users/sah2249/miniconda3/envs/stats-book/lib/python3.13/site-packages/jupyter_core/__init__.py
Currently active conda environment: stats-book

How to submit

Use the Google form here