Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • System Modeler

    Multidomain modeling and simulation of complex systems

  • Compute ServicesUse with Mathematica and Wolfram|One
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Wolfram|Alpha

  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs

AI Products

  • Wolfram AI Ecosystem
  • Wolfram Foundation Tool
  • Wolfram Cloud MCP
  • Wolfram Local MCP
  • Agent One API
  • CAG Component APIs

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • Linguistic Understanding

Additional Deployment Options

  • Wolfram Cloud
  • Wolfram Web Engine
  • wolframscript
  • WSTPServer
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

Wolfram Consulting

Data Science, Finance & Business

  • Artificial Intelligence
  • Data Science
  • Healthcare
  • Real Estate

Engineering

  • Civil Engineering
  • Automotive Engineering
  • Sustainable Energy

Science & Technology

  • AgTech
  • Biosciences
  • Environmental Science
  • Food Science
  • Quantum Computation
  • Social and Behavioral Sciences

More Wolfram Solutions

Technology for Education

  • Research Universities
  • Colleges & Teaching Universities
  • High Schools
  • Resources for Students

Education Initiatives

  • Next-Gen EdTech
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
For AIs
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • System Modeler
    • Compute ServicesUse with Mathematica and Wolfram|One
    • AI AccessUse with Mathematica and Wolfram|One
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Wolfram|Alpha
      • Wolfram|Alpha Website
      • Wolfram|Alpha APIs
    • AI Products
      • Wolfram AI Ecosystem
      • Wolfram Foundation Tool
      • Wolfram Cloud MCP
      • Wolfram Local MCP
      • Agent One API
      • CAG Component APIs
    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • Linguistic Understanding
    • Additional Deployment Options
      • Wolfram Cloud
      • Wolfram Web Engine
      • wolframscript
      • WSTPServer
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions
    • Wolfram Consulting

    Data Science, Finance & Business

    • Artificial Intelligence
    • Data Science
    • Healthcare
    • Real Estate

    Engineering

    • Civil Engineering
    • Automotive Engineering
    • Sustainable Energy

    Science & Technology

    • AgTech
    • Biosciences
    • Environmental Science
    • Food Science
    • Quantum Computation
    • Social and Behavioral Sciences

    More Wolfram Solutions

    Technology for Education

    • Research Universities
    • Colleges & Teaching Universities
    • High Schools
    • Resources for Students

    Education Initiatives

    • Next-Gen EdTech
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • For AIs
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
TTest
  • See Also
    • HypothesisTestData
    • LocationTest
    • LocationEquivalenceTest
    • VarianceTest
    • VarianceEquivalenceTest
    • DistributionFitTest
    • MannWhitneyTest
    • PairedTTest
    • PairedZTest
    • SignTest
    • SignedRankTest
    • ZTest
  • Related Guides
    • Hypothesis Tests
    • See Also
      • HypothesisTestData
      • LocationTest
      • LocationEquivalenceTest
      • VarianceTest
      • VarianceEquivalenceTest
      • DistributionFitTest
      • MannWhitneyTest
      • PairedTTest
      • PairedZTest
      • SignTest
      • SignedRankTest
      • ZTest
    • Related Guides
      • Hypothesis Tests

TTest[data]

tests whether the mean of data is zero.

TTest[{data1,data2}]

tests whether the means of data1 and data2 are equal.

TTest[dspec,μ0]

tests the mean against μ0.

TTest[dspec,μ0,"property"]

returns the value of "property".

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Testing  
Reporting  
Options  
AlternativeHypothesis  
SignificanceLevel  
VerifyTestAssumptions  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • HypothesisTestData
    • LocationTest
    • LocationEquivalenceTest
    • VarianceTest
    • VarianceEquivalenceTest
    • DistributionFitTest
    • MannWhitneyTest
    • PairedTTest
    • PairedZTest
    • SignTest
    • SignedRankTest
    • ZTest
  • Related Guides
    • Hypothesis Tests
    • See Also
      • HypothesisTestData
      • LocationTest
      • LocationEquivalenceTest
      • VarianceTest
      • VarianceEquivalenceTest
      • DistributionFitTest
      • MannWhitneyTest
      • PairedTTest
      • PairedZTest
      • SignTest
      • SignedRankTest
      • ZTest
    • Related Guides
      • Hypothesis Tests

TTest

TTest[data]

tests whether the mean of data is zero.

TTest[{data1,data2}]

tests whether the means of data1 and data2 are equal.

TTest[dspec,μ0]

tests the mean against μ0.

TTest[dspec,μ0,"property"]

returns the value of "property".

Details and Options

  • TTest tests the null hypothesis against the alternative hypothesis :
  • data
    {data1,data2}
  • where μi is the population mean for datai.
  • By default, a probability value or -value is returned.
  • A small -value suggests that it is unlikely that is true.
  • The data in dspec can be univariate {x1,x2,…} or multivariate {{x1,y1,…},{x2,y2,…},…}.
  • The argument μ0 can be a real number or a real vector with length equal to the dimension of the data.
  • TTest assumes that the data is normally distributed but is fairly robust to this assumption. TTest also assumes that the samples are independent in the two sample cases.
  • TTest[dspec,μ0,"HypothesisTestData"] returns a HypothesisTestData object htd that can be used to extract additional test results and properties using the form htd["property"].
  • TTest[dspec,μ0,"property"] can be used to directly give the value of "property".
  • Properties related to the reporting of test results include:
  • "DegreesOfFreedom"the degrees of freedom used in a test
    "PValue"list of -values
    "PValueTable"formatted table of -values
    "ShortTestConclusion"a short description of the conclusion of a test
    "TestConclusion"a description of the conclusion of a test
    "TestData"list of pairs of test statistics and -values
    "TestDataTable"formatted table of -values and test statistics
    "TestStatistic"list of test statistics
    "TestStatisticTable"formatted table of test statistics
  • For univariate samples, TTest performs a Student test. The test statistic is assumed to follow a StudentTDistribution[df].
  • For multivariate samples, TTest performs Hotelling's test. The test statistic is assumed to follow a HotellingTSquareDistribution[p,df] where p is the dimension of data.
  • The degrees of freedom df, used to specify the distribution of the test statistic, depend on the sample size, number of samples, and in the case of two univariate samples, the results of a test for equal variances.
  • The following options can be used:
  • AlternativeHypothesis "Unequal"the inequality for the alternative hypothesis
    SignificanceLevel 0.05cutoff for diagnostics and reporting
    VerifyTestAssumptions Automaticwhat assumptions to verify
  • For the TTest, a cutoff is chosen such that is rejected only if . The value of used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the SignificanceLevel option. This value is also used in diagnostic tests of assumptions, including tests for normality, equal variance, and symmetry. By default, is set to 0.05.
  • Named settings for VerifyTestAssumptions in TTest include:
  • "Normality"verify that all data is normally distributed
    "EqualVariance"verify that data1 and data2 have equal variance

Examples

open all close all

Basic Examples  (3)

Test whether the mean of a population is zero:

Wolfram Language code: data = RandomVariate[NormalDistribution[0.05, 1], 10^4];
Wolfram Language code: TTest[data]

The full test table:

Wolfram Language code: TTest[data, Automatic, "TestDataTable"]

Test whether the means of two populations differ by 2:

Wolfram Language code: BlockRandom[SeedRandom[1];data1 = RandomVariate[NormalDistribution[1.85, 1], 1000]; data2 = RandomVariate[NormalDistribution[0, 1], 1000]];

The mean difference :

Wolfram Language code: Mean[data1] - Mean[data2]
Wolfram Language code: SmoothHistogram[{data1, data2 + 2}]

At the 0.05 level, is significantly different from 2:

Wolfram Language code: TTest[{data1, data2}, 2]

Compare the locations of multivariate populations:

Wolfram Language code: BlockRandom[SeedRandom[1];data1 = RandomVariate[MultinormalDistribution[{1, 2}, IdentityMatrix[2]], 1000]; data2 = RandomVariate[MultinormalDistribution[{0, 0}, IdentityMatrix[2]], 1000]];

The mean difference vector :

Wolfram Language code: Mean[data1] - Mean[data2]
Wolfram Language code: Histogram3D[{data1, Transpose[Transpose[data2] + {1, 2}]}]

At the 0.05 level, is not significantly different from {1,2}:

Wolfram Language code: TTest[{data1, data2}, {1, 2}]

Scope  (13)

Testing  (10)

Test versus :

Wolfram Language code: SeedRandom[1]; data1 = RandomVariate[NormalDistribution[0, 1], 500]; data2 = RandomVariate[NormalDistribution[3, 1], 500];

The -values are typically large when the mean is close to :

Wolfram Language code: TTest[data1]

The -values are typically small when the location is far from :

Wolfram Language code: TTest[data2]

Using Automatic is equivalent to testing for a mean of zero:

Wolfram Language code: data = RandomVariate[NormalDistribution[0, 1], 500];
Wolfram Language code: TTest[data, 0]
Wolfram Language code: TTest[data, Automatic]

Test versus :

Wolfram Language code: SeedRandom[1]; data1 = RandomVariate[NormalDistribution[3, 1], 500]; data2 = RandomVariate[NormalDistribution[0, 1], 200];

The -values are typically large when the mean is close to :

Wolfram Language code: TTest[data1, 3]

The -values are typically small when the location is far from :

Wolfram Language code: TTest[data2, 3]

Test whether the mean vector of a multivariate dataset is the zero vector:

Wolfram Language code: SeedRandom[1];data = RandomVariate[MultinormalDistribution[{.1, 0, -.05, 0}, IdentityMatrix[4]], 10^3];
Wolfram Language code: TTest[data]

Alternatively, test against {0.1,0,–0.05,0}:

Wolfram Language code: TTest[data, {0.1, 0, -.05, 0}]

Test versus :

Wolfram Language code: SeedRandom[1];data1 = RandomVariate[NormalDistribution[0, 1], 100]; data2 = RandomVariate[NormalDistribution[1, 1], 150]; data3 = RandomVariate[NormalDistribution[0, 2], 130];

The -values are generally small when the locations are not equal:

Wolfram Language code: TTest[{data1, data2}, 0]

The -values are generally large when the locations are equal:

Wolfram Language code: TTest[{data1, data3}, 0]

Test versus :

Wolfram Language code: SeedRandom[1];data1 = RandomVariate[NormalDistribution[3, 1], 135]; data2 = RandomVariate[NormalDistribution[0, 1], 100];

The order of the datasets affects the test results:

Wolfram Language code: TTest[{data1, data2}, 3]
Wolfram Language code: TTest[{data2, data1}, 3]

Test whether the mean difference vector of two multivariate datasets is the zero vector:

Wolfram Language code: SeedRandom[1];data1 = RandomVariate[MultinormalDistribution[{.5, 0, -.5, 0}, IdentityMatrix[4]], 122];
Wolfram Language code: data2 = RandomVariate[MultinormalDistribution[{-.5, 0, .5, 0}, IdentityMatrix[4]], 135];
Wolfram Language code: TTest[{data1, data2}]

Alternatively, test against {1,0,–1,0}:

Wolfram Language code: TTest[{data1, data2}, {1, 0, -1, 0}]

Create a HypothesisTestData object for repeated property extraction:

Wolfram Language code: SeedRandom[1];data = RandomVariate[NormalDistribution[], {2, 10^4}];
Wolfram Language code: ℋ = TTest[data, 0, "HypothesisTestData"];

The properties available for extraction:

Wolfram Language code: ℋ["Properties"]

Extract some properties from a HypothesisTestData object:

Wolfram Language code: SeedRandom[2];data = RandomVariate[NormalDistribution[], {2, 10^4}];
Wolfram Language code: ℋ = TTest[data, 0, "HypothesisTestData"];

The -value, test statistic, and degrees of freedom:

Wolfram Language code: ℋ["PValue"]
Wolfram Language code: ℋ["TestStatistic"]
Wolfram Language code: ℋ["DegreesOfFreedom"]

Extract any number of properties simultaneously:

Wolfram Language code: SeedRandom[2];data = RandomVariate[NormalDistribution[], {2, 10^4}];
Wolfram Language code: ℋ = TTest[data, 0, "HypothesisTestData"];

The -value, test statistic, and degrees of freedom:

Wolfram Language code: ℋ["PValue", "TestStatistic", "DegreesOfFreedom"]

Reporting  (3)

Tabulate the test results:

Wolfram Language code: SeedRandom[1];data = RandomVariate[NormalDistribution[], {2, 20}];
Wolfram Language code: ℋ = TTest[data, 0, "HypothesisTestData"];
Wolfram Language code: ℋ["TestDataTable"]

Retrieve the entries from a test table for customized reporting:

Wolfram Language code: SeedRandom[1];data = RandomVariate[NormalDistribution[], {1000, 25}];
Wolfram Language code: res = Table[TTest[v, 0, "TestData", VerifyTestAssumptions -> None], {v, data}];
Wolfram Language code: ListPlot[res, FrameLabel -> {"T", "p-value"}, Frame -> True, PlotRange -> All]

Tabulate -values or test statistics:

Wolfram Language code: SeedRandom[1];data = RandomVariate[NormalDistribution[], {2, 10^2}];
Wolfram Language code: ℋ = TTest[data, 0, "HypothesisTestData"];
Wolfram Language code: ℋ["PValueTable"]

The -value from the table:

Wolfram Language code: ℋ["PValue"]
Wolfram Language code: ℋ["TestStatisticTable"]

The test statistic from the table:

Wolfram Language code: ℋ["TestStatistic"]

Options  (11)

AlternativeHypothesis  (3)

A two-sided test is performed by default:

Wolfram Language code: SeedRandom[1]; data = RandomVariate[NormalDistribution[], 100];

Test versus :

Wolfram Language code: TTest[data, 0, AlternativeHypothesis -> "Unequal"]
Wolfram Language code: TTest[data, 0, AlternativeHypothesis -> Automatic]

Perform a two-sided test or a one-sided alternative:

Wolfram Language code: SeedRandom[1]; data = RandomVariate[NormalDistribution[], 100];

Test versus :

Wolfram Language code: TTest[data, 0, AlternativeHypothesis -> "Unequal"]

Test versus :

Wolfram Language code: TTest[data, 0, AlternativeHypothesis -> "Less"]

Test versus :

Wolfram Language code: TTest[data, 0, AlternativeHypothesis -> "Greater"]

Perform tests with one-sided alternatives when is given:

Wolfram Language code: SeedRandom[1]; data1 = RandomVariate[NormalDistribution[2.9, 1], 1000]; data2 = RandomVariate[NormalDistribution[0, 1], 1000];
Wolfram Language code: Mean[data1] - Mean[data2]

Test versus :

Wolfram Language code: TTest[{data1, data2}, 3, AlternativeHypothesis -> "Less"]

Test versus :

Wolfram Language code: TTest[{data1, data2}, 2.9, AlternativeHypothesis -> "Less"]

SignificanceLevel  (2)

Set the significance level for diagnostic tests:

Wolfram Language code: data = BlockRandom[SeedRandom[2];RandomVariate[StudentTDistribution[3], 50]];
Wolfram Language code: TTest[data, 0, SignificanceLevel -> .0001]

By default, 0.05 is used:

Wolfram Language code: TTest[data, 0]

The significance level is also used for "TestConclusion" and "ShortTestConclusion":

Wolfram Language code: BlockRandom[SeedRandom[1];data = RandomVariate[NormalDistribution[0, 1], 100]];
Wolfram Language code: Mean[data]
Wolfram Language code: ℋ1 = TTest[data, .2, "HypothesisTestData", SignificanceLevel -> .1];
Wolfram Language code: ℋ2 = TTest[data, .2, "HypothesisTestData", SignificanceLevel -> .005];
Wolfram Language code: ℋ1["TestConclusion"]//TraditionalForm
Wolfram Language code: ℋ2["TestConclusion"]//TraditionalForm
Wolfram Language code: ℋ1["ShortTestConclusion"]
Wolfram Language code: ℋ2["ShortTestConclusion"]

VerifyTestAssumptions  (6)

By default, normality and equal variance are tested:

Wolfram Language code: data1 = RandomVariate[NormalDistribution[0, 1], 100]; data2 = RandomVariate[NormalDistribution[0, 2], 100];
Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> Automatic]

If assumptions are not checked, some test results may differ:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> None]

Diagnostics can be controlled as a group using All or None:

Wolfram Language code: data1 = RandomVariate[NormalDistribution[0, 1], 100]; data2 = RandomVariate[NormalDistribution[0, 2], 100];

Verify all assumptions:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> All]

Check no assumptions:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> None]

Diagnostics can be controlled independently:

Wolfram Language code: data1 = RandomVariate[NormalDistribution[0, 1], 100]; data2 = RandomVariate[NormalDistribution[0, 2], 100];

Assume normality but check for equal variances:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> "EqualVariance"]

Only check for normality:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> "Normality"]

Set the equal variance assumption to False:

Wolfram Language code: TTest[{data1, data2}, 0, VerifyTestAssumptions -> "EqualVariance" -> False]

Unlisted assumptions are not tested:

Wolfram Language code: data = RandomVariate[CauchyDistribution[0, 1], 100];

Here, normality is assumed:

Wolfram Language code: TTest[data, 0, VerifyTestAssumptions -> "EqualVariance"]

The result is the same but a warning is issued:

Wolfram Language code: TTest[data, 0, VerifyTestAssumptions -> All]

Bypassing diagnostic tests can save compute time:

Wolfram Language code: data = RandomVariate[MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]], 10 ^ 4];
Wolfram Language code: TTest[data, Automatic, "TestDataTable", VerifyTestAssumptions -> All]//AbsoluteTiming
Wolfram Language code: TTest[data, Automatic, "TestDataTable", VerifyTestAssumptions -> None]//AbsoluteTiming

It is often useful to bypass diagnostic tests for simulation purposes:

Wolfram Language code: data = RandomVariate[NormalDistribution[], {1000, 100}];
Wolfram Language code: AbsoluteTiming[T = Quiet@TTest[#, Automatic, "TestStatistic"]& /@ data;]

The assumptions of the test hold by design, so a great deal of time can be saved:

Wolfram Language code: AbsoluteTiming[T2 = Quiet@TTest[#, Automatic, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;]

The results are identical:

Wolfram Language code: SmoothHistogram[{T, T2}]

Applications  (4)

Test whether the means of some populations are equal:

Wolfram Language code: SeedRandom[1];data1 = RandomVariate[NormalDistribution[0, 1], 100]; data2 = RandomVariate[NormalDistribution[0, 1], 100]; data3 = RandomVariate[NormalDistribution[2, 1], 100];
Wolfram Language code: BoxWhiskerChart[{data1, data2, data3}]

The means of the first two populations are similar:

Wolfram Language code: TTest[{data1, data2}, Automatic, "TestDataTable"]

The mean of the third population is different from the first:

Wolfram Language code: TTest[{data1, data3}, Automatic, "TestDataTable"]

The "third series" of measurements of the passage time of light was recorded by Newcomb in 1882. The given values divided by 1000 plus 24 give the time in millionths of a second for light to traverse a known distance. The true value is now considered to be 33.02:

Wolfram Language code: lspeed = ExampleData[{"Statistics", "NewcombLightSpeed"}];
Wolfram Language code: SmoothHistogram[lspeed, PlotRange -> All]

Use Chauvenet's criterion to identify outlying observations:

Wolfram Language code: ChauvenetOutlier[d_, data_] := Probability[x <= d, xNormalDistribution[Mean[data], StandardDeviation[data]]] < (1/2Length[data])
Wolfram Language code: outliers = Select[lspeed, ChauvenetOutlier[#, lspeed]&]
Wolfram Language code: newcomb = DeleteCases[lspeed, Alternatives@@outliers];

A -test on the bulk of the data suggests that Newcomb's measure of the speed of light was significantly lower than reality:

Wolfram Language code: Mean[newcomb]//N
Wolfram Language code: TTest[newcomb, 33.02, "TestDataTable"]

The vitamin C content and head weight were recorded for 30 samples from each of two experimental cabbage cultivars:

Wolfram Language code: ExampleData[{"Statistics", "Cabbages"}, "ColumnDescriptions"]
Wolfram Language code: cabbageData = ExampleData[{"Statistics", "Cabbages"}];
Wolfram Language code: cultivar = cabbageData[[All, 1]];

Plots of the head weight and vitamin C content by cultivar:

Wolfram Language code: w39 = Pick[cabbageData[[All, 3]], cultivar, "c39"]; w52 = Pick[cabbageData[[All, 3]], cultivar, "c52"]; c39 = Pick[cabbageData[[All, 4]], cultivar, "c39"]; c52 = Pick[cabbageData[[All, 4]], cultivar, "c52"];
Wolfram Language code: {SmoothHistogram[{w39, w52}, PlotLabel -> "Head Weight"], SmoothHistogram[{c39, c52}, PlotLabel -> "Vitamin C", PlotLegends -> {"c39", "c52"}]}

The vitamin C content is significantly higher for the c52 cultivar:

Wolfram Language code: TTest[{c52, c39}, 0, "TestDataTable"]

The weight data is not normally distributed for c52, so MannWhitneyTest is used to show that a significantly lighter cabbage produced significantly more vitamin C:

Wolfram Language code: DistributionFitTest[w52]
Wolfram Language code: MannWhitneyTest[{w52, w39}, 0, "TestDataTable"]

Fifty samples from each of three species of iris flowers were collected. The samples consist of measures of the length and width of the irises' sepals and petals. It is difficult to distinguish the species virginica and versicolor from one another:

Wolfram Language code: iris = ExampleData[{"Statistics", "FisherIris"}];
Wolfram Language code: species = iris[[All, -1]];
Wolfram Language code: versicolorData = Pick[iris[[All, 1 ;; -2]], species, "versicolor"]; virginicaData = Pick[iris[[All, 1 ;; -2]], species, "virginica"];

A Hotelling test suggests a difference in the measures for the two similar species:

Wolfram Language code: TTest[{versicolorData, virginicaData}, 0, "TestDataTable"]

A visualization of the data suggests this difference is most prominent in the petal dimensions:

Wolfram Language code: clmnDescr = ExampleData[{"Statistics", "FisherIris"}, "ColumnDescriptions"][[1 ;; -2]]; lgnd = Placed[LineLegend[{RGBColor[0.368417, 0.506779, 0.709798], RGBColor[0.880722, 0.611041, 0.142051]}, {"versicolor", "virginica"}, LegendLayout -> "Row"], Bottom];
Wolfram Language code: Legended[Table[SmoothHistogram[{versicolorData[[All, i]], virginicaData[[All, i]]}, PlotLabel -> clmnDescr[[i]]], {i, Length[clmnDescr]}], lgnd]

Properties & Relations  (11)

For univariate data, the test statistic follows StudentTDistribution under :

Wolfram Language code: data = RandomVariate[NormalDistribution[], {1000, 15}];
Wolfram Language code: T = Table[TTest[i, Automatic, "TestStatistic", VerifyTestAssumptions -> None], {i, data}];
Wolfram Language code: DistributionFitTest[T, StudentTDistribution[14]]

For multivariate data, the test statistic follows HotellingTSquareDistribution under :

Wolfram Language code: data = RandomVariate[BinormalDistribution[.5], {1000, 25}];
Wolfram Language code: T = Table[TTest[i, Automatic, "TestStatistic", VerifyTestAssumptions -> None], {i, data}];
Wolfram Language code: DistributionFitTest[T, HotellingTSquareDistribution[2, 23]]

The degrees of freedom are data-dependent for univariate data:

Wolfram Language code: 𝒹1 = RandomVariate[NormalDistribution[0, 1], 100]; 𝒹2 = RandomVariate[NormalDistribution[0, 1], 95]; 𝒹3 = RandomVariate[NormalDistribution[0, 5], 100];
Wolfram Language code: L[x_] := Length[x];v[x_] := Variance[x]

One sample:

Wolfram Language code: TTest[𝒹1, 0, "DegreesOfFreedom"]
Wolfram Language code: L[𝒹1] - 1

Two samples with equal variances:

Wolfram Language code: TTest[{𝒹1, 𝒹2}, 0, "DegreesOfFreedom"]
Wolfram Language code: L[𝒹1] + L[𝒹2] - 2

Two samples with unequal variances (Satterthwaite approximation):

Wolfram Language code: TTest[{𝒹1, 𝒹3}, 0, "DegreesOfFreedom"]
Wolfram Language code: (((v[𝒹1]/L[𝒹1]) + (v[𝒹3]/L[𝒹3]))^2/((v[𝒹1]/L[𝒹1]))^2 / (L[𝒹1] - 1) + ((v[𝒹3]/L[𝒹3]))^2 / (L[𝒹3] - 1))

The type of degrees of freedom used can be controlled using VerifyTestAssumptions:

Wolfram Language code: 𝒹1 = RandomVariate[NormalDistribution[0, 1], 95]; 𝒹2 = RandomVariate[NormalDistribution[0, 5], 100];

Explicitly assume equal variances and test for normality:

Wolfram Language code: TTest[{𝒹1, 𝒹2}, 0, "DegreesOfFreedom", VerifyTestAssumptions -> {"EqualVariance" -> True, "Normality"}]

Explicitly assume unequal variances to use the Satterthwaite approximation:

Wolfram Language code: TTest[{𝒹1, 𝒹2}, 0, "DegreesOfFreedom", VerifyTestAssumptions -> {"EqualVariance" -> False, "Normality"}]

For multivariate data, the squared Mahalanobis distance is used to compute Hotelling's statistic:

Wolfram Language code: data = RandomVariate[MultinormalDistribution[{1, 2, 3}, IdentityMatrix[3]], 100];
Wolfram Language code: MahalanobisDistanceSquared[data_, mu_] := With[{inv = Inverse@Covariance[data], m = Mean[data]}, (m - mu).inv.(m - mu)]
Wolfram Language code: Subscript[μ, 0] = {1, 2, 3};
Wolfram Language code: T2 = Length[data] * MahalanobisDistanceSquared[data, Subscript[μ, 0]]

Under , the test statistic follows HotellingTSquareDistribution[p,n-1]:

Wolfram Language code: pvalue = SurvivalFunction[HotellingTSquareDistribution[3, 99], T2]
Wolfram Language code: TTest[data, {1, 2, 3}, "TestDataTable"]

If the population variance is known, the more powerful ZTest can be used:

Wolfram Language code: σ = .25;
Wolfram Language code: data = RandomVariate[NormalDistribution[2.5, Sqrt[σ]], {1000, 15}];
Wolfram Language code: T = TTest[#, 2, VerifyTestAssumptions -> None]& /@ data;
Wolfram Language code: Z = ZTest[#, σ, 2, VerifyTestAssumptions -> None]& /@ data;
Wolfram Language code: α = 0.05;

ZTest correctly rejects more frequently than TTest:

Wolfram Language code: Probability[x < α, xT]//N
Wolfram Language code: Probability[x < α, xZ]//N

TTest is robust to mild deviations from normality:

Wolfram Language code: data = BlockRandom[SeedRandom[1];RandomVariate[𝒹 = StudentTDistribution[5], {1000, 35}]];
Wolfram Language code: Plot[{PDF[𝒹, x], PDF[NormalDistribution[], x]}, {x, -4, 4}, PlotLegends -> {"𝒹", NormalDistribution}]
Wolfram Language code: pvals = TTest[#, VerifyTestAssumptions -> None]& /@ data;

The -value can still be interpreted in the usual way:

Wolfram Language code: DistributionFitTest[pvals, UniformDistribution[]]

Large deviations from normality require the use of median-based tests:

Wolfram Language code: data = BlockRandom[SeedRandom[1];RandomVariate[𝒹 = CauchyDistribution[0, 1], {1000, 35}]];
Wolfram Language code: Plot[{PDF[𝒹, x], PDF[NormalDistribution[], x]}, {x, -4, 4}, PlotLegends -> {"𝒹", NormalDistribution}]
Wolfram Language code: tpvals = TTest[#, VerifyTestAssumptions -> None]& /@ data;
Wolfram Language code: srpvals = SignedRankTest /@ data//Quiet;

The -value can be interpreted in the usual way for SignedRankTest but not TTest:

Wolfram Language code: DistributionFitTest[tpvals, UniformDistribution[]]
Wolfram Language code: DistributionFitTest[srpvals, UniformDistribution[]]

For two-sample testing of non-normal data, use MannWhitneyTest:

Wolfram Language code: data1 = RandomVariate[LaplaceDistribution[0, 1], {1000, 35}]; data2 = RandomVariate[LaplaceDistribution[.5, 1], {1000, 25}];
Wolfram Language code: t = MapThread[TTest[{#1, #2}, VerifyTestAssumptions -> None]&, {data1, data2}];
Wolfram Language code: mw = MapThread[MannWhitneyTest[{#1, #2}]&, {data1, data2}];

For non-normal data, MannWhitneyTest can be more powerful than TTest:

Wolfram Language code: Probability[x ≤ .05, xt]//N
Wolfram Language code: Probability[x ≤ 0.05, xmw]//N

TTest works with the values only when the input is a TimeSeries:

Wolfram Language code: ts = TemporalData[TimeSeries, {{{1.224578634529677, 0.47929635789978015, 0.6572781300178168, 0.21496048742669355, 0.7299608014554928, -0.2495111111278263, -1.3286551762002712, 0.552725018274874, 0.19272112205837066, 1.1809144012420882, -1.1671 ... 40938613662046, 1.052394590214582, 0.9345044123980388, 0.38537803109557855, -0.48660931166089394, -0.71203560340161}}, {{0, 100, 1}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];
Wolfram Language code: TTest[ts]
Wolfram Language code: TTest[ts["Values"]]

TTest works with all the values together when the input is a TemporalData:

Wolfram Language code: td = TemporalData[Automatic, {{{-0.25275046867718637, -0.7175779198306353, -1.9370139837317764, 0.006665621735740701, -0.3730807122324292, 0.6740106823161018, 0.8562214990564344, 0.955785083955732, 1.7020898014886303, 1.8523009430646802, 0.244 ... 3951759101545, -1.1611722313627828, 1.1602446901533021, 1.1052173095128992, 1.1089143920161917, -0.13837156328402}}, {{0, 100, 1}}, 2, {"Continuous", 2}, {"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];
Wolfram Language code: TTest[td]

Test all the values only:

Wolfram Language code: data = td["ValueList"]//Flatten; TTest[data]

Test whether the means of the two paths are equal:

Wolfram Language code: {data1, data2} = td["ValueList"];
Wolfram Language code: TTest[{data1, data2}]

Possible Issues  (2)

TTest assumes that the data is normally distributed:

Wolfram Language code: data = RandomVariate[ParetoDistribution[1, 2], 100];
Wolfram Language code: TTest[data]

Use a median-based test that does not assume normality:

Wolfram Language code: SignTest[data]

The covariance matrix of multivariate data may not be invertible:

Wolfram Language code: data = BlockRandom[SeedRandom[3];RandomVariate[SuzukiDistribution[0.3, 38], {15, 2}]];
Wolfram Language code: Quiet[TTest[data], {TTest::nortst}]

Neat Examples  (1)

Compute the statistic when the null hypothesis is true:

Wolfram Language code: data = RandomVariate[NormalDistribution[], {2500, 100}];
Wolfram Language code: T1 = TTest[#, 0, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;

The test statistic given a particular alternative:

Wolfram Language code: T2 = TTest[#, 1, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;

Compare the distributions of the test statistics:

Wolfram Language code: SmoothHistogram[{T1, T2}, Filling -> Axis, PlotLegends -> {"SubscriptBox[H, 0] is True", "SubscriptBox[H, 0] is False"}, PlotStyle -> Thick]

See Also

HypothesisTestData  LocationTest  LocationEquivalenceTest  VarianceTest  VarianceEquivalenceTest  DistributionFitTest  MannWhitneyTest  PairedTTest  PairedZTest  SignTest  SignedRankTest  ZTest

Function Repository: WelchTest

Related Guides

    ▪
  • Hypothesis Tests

History

Introduced in 2010 (8.0)

Wolfram Research (2010), TTest, Wolfram Language function, https://reference.wolfram.com/language/ref/TTest.html.

Text

Wolfram Research (2010), TTest, Wolfram Language function, https://reference.wolfram.com/language/ref/TTest.html.

CMS

Wolfram Language. 2010. "TTest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TTest.html.

APA

Wolfram Language. (2010). TTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TTest.html

BibTeX

@misc{reference.wolfram_2026_ttest, author="Wolfram Research", title="{TTest}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/TTest.html}", note=[Accessed: 01-September-2026]}

BibLaTeX

@online{reference.wolfram_2026_ttest, organization={Wolfram Research}, title={TTest}, year={2010}, url={https://reference.wolfram.com/language/ref/TTest.html}, note=[Accessed: 01-September-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • AI Access
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English