T Test Aggregation Usage

edit

A t_test metrics aggregation that performs a statistical hypothesis test in which the test statistic follows a Student’s t-distribution under the null hypothesis on numeric values extracted from the aggregated documents or generated by provided scripts. In practice, this will tell you if the difference between two population means are statistically significant and did not occur by chance alone.

Available in Elasticsearch 7.8.0+ with at least basic license level

Be sure to read the Elasticsearch documentation on T-Test Aggregation.

Fluent DSL example

edit
a => a
.TTest("commits_visibility", c => c
    .A(t => t
        .Field(f => f.NumberOfCommits)
        .Filter(f => f
            .Term(ff => ff.Visibility, Visibility.Public)
        )
    )
    .B(t => t
        .Field(f => f.NumberOfCommits)
        .Filter(f => f
            .Term(ff => ff.Visibility, Visibility.Private)
        )
    )
    .Type(TTestType.Heteroscedastic)
)

Object Initializer syntax example

edit
new TTestAggregation("commits_visibility")
{
    A = new TTestPopulation
    {
        Field = Field<Project>(f => f.NumberOfCommits),
        Filter = new TermQuery
        {
            Field = Field<Project>(f => f.Visibility),
            Value = Visibility.Public
        }
    },
    B = new TTestPopulation
    {
        Field = Field<Project>(f => f.NumberOfCommits),
        Filter = new TermQuery
        {
            Field = Field<Project>(f => f.Visibility),
            Value = Visibility.Private
        }
    },
    Type = TTestType.Heteroscedastic
}

Example json output.

{
  "commits_visibility": {
    "t_test": {
      "a": {
        "field": "numberOfCommits",
        "filter": {
          "term": {
            "visibility": {
              "value": "Public"
            }
          }
        }
      },
      "b": {
        "field": "numberOfCommits",
        "filter": {
          "term": {
            "visibility": {
              "value": "Private"
            }
          }
        }
      },
      "type": "heteroscedastic"
    }
  }
}

Handling Responses

edit
response.ShouldBeValid();
var tTest = response.Aggregations.TTest("commits_visibility");
tTest.Should().NotBeNull();
tTest.Value.Should().BeGreaterThan(0);