T-tests in R, Python, Excel and SPSS
The most common reason two people get different t-test answers from the same data is that their software ran different tests by default. Here is one dataset run each way, with the numbers each tool gives.
Sources checked on November 21, 2026. Results computed by the site's engine and tested against R and SciPy.
The dataset
We use R's mtcars fuel economy data: miles per gallon for 19 automatic and 13 manual cars. Welch's test gives t = −3.7671, df = 18.33, p = 0.0014. Student's test gives t = −4.1061, df = 30, p = 2.850 × 10−4. Every tool below produces one of these two answers; which one depends on its default.
R
R's t.test runs Welch's test unless you set var.equal = TRUE. Its printed output for this example, from R's reference output, reads: t = -3.7671, df = 18.332, p-value = 0.001374, with the 95% interval −11.280194 to −3.209684. R rounds what it prints (here three decimals of df and four significant figures of p); our calculator agrees with R's unrounded values to at least ten significant figures.
x <- mtcars$mpg[mtcars$am == 0] # automatic
y <- mtcars$mpg[mtcars$am == 1] # manual
t.test(x, y) # Welch (default)
t.test(x, y, var.equal = TRUE) # Student
# paired data of equal length: t.test(before, after, paired = TRUE)Paired and one-sample tests use paired = TRUE and mu = value.
Python (SciPy)
SciPy's ttest_ind defaults to equal_var=True, so it runs Student's test unless you ask for Welch. This is the opposite of R and the most common source of R versus Python disagreements. With equal_var=False it gives Welch's t = −3.7671 and df = 18.33. Recent SciPy versions return the df and a confidence_interval() method on the result.
from scipy import stats
x = [21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 21.5, 15.5, 15.2, 13.3, 19.2] # automatic
y = [21, 21, 22.8, 32.4, 30.4, 33.9, 27.3, 26, 30.4, 15.8, 19.7, 15, 21.4] # manual
w = stats.ttest_ind(x, y, equal_var=False) # Welch
s = stats.ttest_ind(x, y) # Student (default)
print(w.statistic, w.df, w.pvalue, w.confidence_interval(0.95))
# paired data: stats.ttest_rel(before, after)
# one-sample: stats.ttest_1samp(x, 0)For rank tests, mannwhitneyu reports U for the first sample, the same number as R's W, and wilcoxon skips the continuity correction by default, unlike R.
Excel
Excel's T.TEST worksheet function returns only a p-value. Its syntax is T.TEST(array1, array2, tails, type), where tails is 1 or 2 and type is 1 for a paired test, 2 for the two-sample equal-variance (Student) test and 3 for the two-sample unequal-variance (Welch) test (Microsoft T.TEST documentation). With the automatic cars in A2:A20 and the manual cars in B2:B14, =T.TEST(A2:A20, B2:B14, 2, 2) is Student's two-tailed test, which should return the 0.000285 above, and =T.TEST(A2:A20, B2:B14, 2, 3) is the Welch version, about 0.0014.
The Analysis ToolPak offers the same tests as menu tools that also print t and df. Type 2 is the usual trap: it gives Student's answer, not R's default. To turn a two-tailed p back into |t|, use T.INV.2T(p, df).
SPSS
IBM's documentation says the Independent-Samples T Test procedure gives Levene's test for equality of variances and both the pooled-variances and the separate-variances t tests (IBM SPSS Independent-Samples T Test). So the output has two results side by side: the pooled one should match Student's values above (t = −4.1061, df 30) and the separate-variances one should match Welch's (t = −3.7671, df 18.33). Choosing between them based on Levene's test is the two-step habit discussed in Welch vs Student; decide in advance and report the separate-variances result.
Graphing calculators
Calculators such as the TI-84 have a two-sample t-test with a Pooled setting. Pooled: No is Welch's test and Pooled: Yes is Student's. Check the setting before you calculate: with the mtcars data, Pooled: No should show df of about 18.33 and Pooled: Yes df 30, so the df on screen tells you which test you ran.
A checklist when answers differ
- Same test? Welch versus Student is the usual culprit.
- Same direction? A one-sided p is half the two-sided p only when t points the predicted way.
- Same data? Check for a missing value or a misaligned pair.
- Same input type? Results from rounded means and SDs differ slightly from raw-data results.
- Same df? Rounding Welch's df to a whole number changes p slightly, usually in the third significant figure or later.
Every result on this site includes R and Python code that reproduces it exactly, under "Reproduce this result in R or Python".
Sources
- R source code, stats package, t.test.R checked November 21, 2026
- R reference example output, stats-Ex.Rout.save checked November 21, 2026
- SciPy documentation: scipy.stats.ttest_ind checked November 21, 2026
- SciPy documentation: scipy.stats.mannwhitneyu checked November 21, 2026
- SciPy documentation: scipy.stats.wilcoxon checked November 21, 2026
- Microsoft Support: T.TEST function checked November 21, 2026
- IBM SPSS Statistics 29 documentation: Independent-Samples T Test checked November 21, 2026