Skip to content

DPredict · Guide test 004

Regression coefficient t test

Tests a specified linear regression coefficient or contrast under the fitted model’s error assumptions.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Regression coefficient t test

40
0.25
0.000

Adds curve × (x − 5)².

0.00

Error SD grows like exp(h · (x − 5)/5).

0.00

Errors in collection order carry φ × the previous error.

0.00
0.050

Alternative

Your data

Simulated with a known ρ

If H₀ were true

t = 4.13
  1. The reference: how t varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = < .001).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

t=β^1se^(β^1),ν=n−2t = \dfrac{\hat\beta_1}{\widehat{\mathrm{se}}(\hat\beta_1)},\qquad \nu = n-2

With your numbers

t=0.240.06=4.13,ν=38t = \dfrac{0.24}{0.06} = 4.13,\qquad \nu = 38
β^1\hat\beta_1
least-squares slope
se^(β^1)\widehat{\mathrm{se}}(\hat\beta_1)
its standard error
ν\nu
residual degrees of freedom

The verdict

t(38) = 4.13, p < .001, R² = 0.31

p ≤ α = .050: reject H₀

Effect size: share of variance explained R² = 0.309

The workhorse of regression output: the slope in standard-error units on a t reference. Its square is the one-degree-of-freedom F.

Statistic
4.126
p-value
0.0002
Regression coefficient t test on 40 (x, y) pairs: t(38) = 4.13, p < .001, R² = 0.31. The p-value is below α = .050, so the data are hard to reconcile with H0.

Regression coefficient t test on 40 (x, y) pairs: t(38) = 4.13, p < .001, R² = 0.31. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: cᵀβ=b0; H1: cᵀβ differs, is larger, or is smaller.

Assumptions

For exact t inference: a full rank fixed design, independent normal errors with common variance, and a correctly specified linear mean. With nonnormal or dependent errors, choose justified robust inference instead.

Formula

t=cTβ^−b0scT(XTX)−1c,s2=RSSn−pt∼tn−p\begin{gathered}t=\frac{c^T\widehat\beta-b_0}{s\sqrt{c^T(X^TX)^{-1}c}},\qquad s^2=\frac{\mathrm{RSS}}{n-p}\\[5pt] t\sim t_{n-p}\end{gathered}

Parameters and notation

X has n rows and p fitted coefficients including the intercept; c selects a slope or contrast; RSS is the residual sum of squares.

Structure of the method

A least-squares solver estimates the regression coefficients, residual sum of squares estimates noise, and a selected coefficient or linear contrast is divided by its model-based standard error. Under the classical Gaussian model this pivot has a t distribution with residual rather than total sample degrees of freedom.

Estimated and nuisance parameters

Fitted coefficients and residual variance are estimated. The contrast vector, null contrast value, and model formula are specified. Leverage enters through the inverse design cross-product, so the uncertainty of a slope depends on predictor geometry as well as sample size and residual variability.

Settings and design choices

Choose the covariate set, interactions, transformations, contrast, alternative direction, significance level, and simultaneous-testing family in advance. Robust standard errors require a stated covariance estimator and reference approximation. A p-value threshold is not a fitting hyperparameter and should not drive predictor inclusion without selection adjustment.

Fitting and adaptation

Refit the entire regression after any design change; merely recomputing a t ratio from an old covariance matrix is invalid. Scaling a predictor consistently changes its coefficient units but not a test of zero. New-population use calls for checking the mean relation and error structure again.

Sensitivity and robustness

Collinearity widens uncertainty and exact aliasing removes estimability. High-leverage points can dominate a slope while residual plots look unremarkable. Autocorrelation or clustered sampling changes the effective information. Classical coefficient t tests are conditional on the fitted model and do not remove confounding or selection bias.

How to use and calibrate

Fit ordinary least squares. Divide the estimated contrast minus its null value by its standard error. For a two sided test use 2P(tν≥|tobs|); choose one sided hypotheses before examining the sign.

Example application

Assess a temperature slope in a linear calibration model; also report the estimated response change per degree and its interval.

Interpretation and pitfalls

Watch out

A significant slope is conditional on included predictors and is not proof of causality. Selection using the same data changes inference. Heteroskedasticity invalidates the ordinary standard error.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Each coefficient tests a conditional effect; read its estimate, standard error, t statistic, confidence interval and p-value.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy, statsmodels

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
import statsmodels.api as sm
n=100
x=rng.normal(size=n); z=rng.normal(size=n); y=1+.5*x+.3*z+rng.normal(size=n)
X=sm.add_constant(np.column_stack([x,z])); fit=sm.OLS(y,X).fit(); reduced=sm.OLS(y,X[:,:2]).fit()
print(fit.summary())
Output
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                      y   R-squared:                       0.271
Model:                            OLS   Adj. R-squared:                  0.256
Method:                 Least Squares   F-statistic:                     18.02
Date:                Tue, 03 Nov 2026   Prob (F-statistic):           2.22e-07
Time:                        19:41:42   Log-Likelihood:                -140.85
No. Observations:                 100   AIC:                             287.7
Df Residuals:                      97   BIC:                             295.5
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const          1.1035      0.101     10.925      0.000       0.903       1.304
x1             0.5668      0.099      5.723      0.000       0.370       0.763
x2             0.2011      0.087      2.311      0.023       0.028       0.374
==============================================================================
Omnibus:                        2.654   Durbin-Watson:                   1.529
Prob(Omnibus):                  0.265   Jarque-Bera (JB):                2.331
Skew:                           0.374   Prob(JB):                        0.312
Kurtosis:                       3.034   Cond. No.                         1.23
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
R

Validated — Executed successfully in the validation environment · needs lmtest

set.seed(2026)
n <- 100; x <- rnorm(n); z <- rnorm(n); y <- 1+.5*x+.3*z+rnorm(n)
d <- data.frame(y,x,z); fit <- lm(y~x+z,data=d); reduced <- lm(y~x,data=d)
print(lmtest::coeftest(fit))
Output
t test of coefficients:

            Estimate Std. Error t value  Pr(>|t|)    
(Intercept) 1.095291   0.090102 12.1561 < 2.2e-16 ***
x           0.502080   0.089352  5.6191 1.837e-07 ***
z           0.352793   0.093563  3.7706 0.0002799 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 004, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT004.