rStats.js v1.3.0
    Preparing search index...

    Function tTest

    • Student's t-test. Equivalent to R's t.test().

      Performs a one-sample, two-sample (Welch's by default, or pooled-variance with varEqual: true) or paired t-test. NaN values are dropped. As in R, each sample needs 2 observations, except that with varEqual: true a two-sample test needs 1 in each and 3 in all; an error is also thrown if the data are essentially constant.

      Parameters

      Returns TTestResult

      The test result, with statisticName "t"; see TTestResult.

      const r = tTest([5.1, 4.9, 5.6, 5.8, 6.0, 5.4], { mu: 5 });
      r.statistic; // 2.7351263280759737
      r.parameter; // 5
      r.pValue; // 0.04102919855187924
      r.confInt; // [5.028074545960439, 5.905258787372895]

      tTest([1, 2, 3, 4, 5], [3, 4, 5, 6, 8]).pValue; // 0.0849560662972433 (Welch)

      There is also a formula form, tTest("y ~ g", data, options) (next overload).

    • Student's t-test from a formula and a data frame. As R's t.test(formula, data): "y ~ g" compares the two levels of g (the first level is x; estimateNames and nullValueName name the levels, as in R), "y ~ 1" is the one-sample test and "Pair(a, b) ~ 1" the paired test of a and b (the option paired is not allowed). Only the variables of the formula count: the rows where one of them is missing are dropped.

      Parameters

      • formula: string

        "y ~ g", "y ~ 1" or "Pair(a, b) ~ 1".

      • data: DataFrame

        The data frame: an object of columns (null or NaN for a missing value).

      • Optionaloptions: TTestOptions

      Returns TTestResult

      tTest("y ~ g", { y: [5.1, 4.9, 5.6, 5.8, 6.0, 5.4], g: ["a", "a", "a", "b", "b", "b"] }).estimateNames;
      // ["mean in group a", "mean in group b"]