t and F Tests in Python

ECON 3209 · Week 9, Lecture 3 · Kerala Agricultural University

Department of Development Economics, KAU

Autumn 2026

Learning Outcomes

  1. Run a t-test for a single regression coefficient in Python.
  2. Understand joint significance and the logic of an F-test.
  3. Use statsmodels methods such as .t_test() and .f_test().
  4. Compare restricted and unrestricted models conceptually.
  5. Report t and F test results in clear econometric language.

Review: the t-test for one coefficient

  • A t-test checks a null hypothesis about a single coefficient.
  • Example: \[H_0: \beta_{fertilizer} = 0\]
  • The test uses the coefficient estimate, its standard error, and the t distribution.
  • In practice, regression tables already report the t statistic and p-value.
  • Python also allows explicit hypothesis testing commands.

Why do we need an F-test?

  • Sometimes we want to test several restrictions together.
  • Example: are fertilizer and rainfall jointly irrelevant in explaining yield?
  • Testing them one at a time misses the joint question.
  • The F-test evaluates combined restrictions on multiple coefficients.
  • It is a standard tool in multiple regression.

F-test intuition: restricted versus unrestricted

  • The unrestricted model allows all coefficients to be estimated freely.
  • The restricted model imposes the null hypothesis by forcing some coefficients to zero.
  • Because the restricted model fits less flexibly, we usually have \[RSS_R \geq RSS_U\]
  • The F-test asks whether that increase in RSS is large enough to reject the restrictions.

F-statistic for joint significance

\[F = \frac{(RSS_R - RSS_U)/J}{RSS_U/(N-K)} \sim F(J, N-K) \quad \text{under } H_0\]

  • \(J\) is the number of restrictions being tested.
  • \(N\) is the sample size.
  • \(K\) is the number of parameters in the unrestricted model.
  • A larger \(F\) means the restrictions worsen model fit substantially.

Kerala example: do rainfall terms matter for procurement?

  • Consider the unrestricted model \[\text{paddy procurement} = \beta_1 + \beta_2 price + \beta_3 rainfall + \beta_4 rainfall^2 + \varepsilon\]
  • The restricted model sets the rainfall terms to zero: \[H_0: \beta_3 = 0 \quad \text{and} \quad \beta_4 = 0\]
  • This is the Kerala analogue of testing whether advertising terms matter for sales.
  • If the unrestricted model fits much better, rainfall is jointly important for paddy procurement.

Implementing the rainfall F-test in Python

Estimating a multiple regression model

Running a t-test in statsmodels

  • Suppose we want to test whether fertilizer has any effect.
  • The null is \[H_0: \beta_{fertilizer} = 0\]
  • We can read the p-value from the summary table.
  • Or we can call .t_test() directly for an explicit restriction.

t-test for one coefficient

Joint significance with an F-test

  • Now test the joint null \[H_0: \beta_{fertilizer} = 0 \; \text{and} \; \beta_{rainfall} = 0\]
  • This asks whether both variables are irrelevant together.
  • The F-statistic compares model fit under the null and the unrestricted model.
  • A small p-value rejects the joint null.

F-test in Python

Interpreting t and F results

  • The t-test is about one coefficient at a time.
  • The F-test is about multiple coefficients jointly.
  • If the F-test rejects, at least one of the tested restrictions fails.
  • Joint significance is especially important when variables work together.
  • Interpretation should always return to the economic question.

Restricted versus unrestricted models

  • The unrestricted model estimates all coefficients freely.
  • The restricted model imposes the null hypothesis.
  • Example: set fertilizer and rainfall coefficients to zero.
  • The F-test compares fit across these two situations.
  • This logic extends to many econometric specifications.

Comparing models in code

Reporting test results well

  • Say which null hypothesis was tested.
  • Report the test statistic and p-value.
  • Mention the significance level used.
  • Translate the result into economic language.
  • Example: “Fertilizer and rainfall are jointly significant predictors of rice yield.”

Common pitfalls

  • Forgetting that rejection of the overall model F-test does not mean every coefficient is individually significant.
  • Ignoring multicollinearity when interpreting individual t-tests.
  • Testing too many hypotheses without a clear research plan.
  • Treating significance as proof of causality.
  • Reporting p-values without the underlying coefficient estimates.

Extracting key test information

Exercise

Simulate a multiple regression with yield_ as the dependent variable and fertilizer, rainfall, and labour as regressors. Then run a t-test for labour = 0 and an F-test for fertilizer = 0 and rainfall = 0 jointly.

Summary

  • ✅ A t-test examines one coefficient at a time.
  • ✅ An F-test examines several restrictions jointly.
  • statsmodels provides .t_test() and .f_test() for explicit hypothesis testing.
  • ✅ Joint significance matters in multiple regression.
  • ✅ Restricted and unrestricted model logic underlies the F-test.
  • ✅ Good reporting states the null, test statistic, p-value, and economic meaning.

Next Lecture

  • In the next unit we will extend the regression framework further.
  • The natural next step is multiple regression and richer model specification.