ttest is a focused JavaScript library for performing Student's t-hypothesis tests. It supports both one-sample and two-sample t-tests, and accommodates scenarios with both equal and unequal variances by defaulting to Welch's t-test for two-sample cases. The library offers flexibility in data input, accepting raw arrays of values, `Summary` objects, or plain objects containing `mean`, `variance`, and `size`. Users can configure critical test parameters such as the null hypothesis mean (`mu`), the significance level (`alpha`), and the alternative hypothesis (e.g., 'less', 'greater', 'not equal'). The current stable version is 4.0.0. It provides a programmatic API to retrieve key statistical outcomes including the t-value (`testValue`), p-value (`pValue`), confidence interval (`confidence`), and degrees of freedom (`freedom`), along with a `valid()` method to check significance against alpha. Its main differentiator is its concise API specifically tailored for t-test computations.
npm install ttestVerified import paths — ran on the pinned version, not inferred.
Demonstrates both one-sample and two-sample t-tests, showing how to construct tests with various options and retrieve key statistical results like t-value, p-value, and confidence intervals. It highlights usage of different options such as 'mu', 'alpha', 'alternative', and 'varEqual'.
Instead of relying solely on `.valid()`, compare `.pValue()` directly against your chosen `alpha` level (e.g., `ttest.pValue() < options.alpha`) to determine statistical significance.
If you specifically require Student's two-sample t-test (assuming equal variances), ensure to pass `{ varEqual: true }` in the options object.Always ensure your `alpha` parameter (e.g., `0.05` for 95% confidence) is within the valid range `[0, 1]`.
Use `const ttest = require('ttest')` for CommonJS environments or `import ttest from 'ttest'` for ESM contexts to correctly import the default export.Ensure data is either an array of numbers (e.g., `[1, 2, 3]`), a `Summary` object (if `summary` package is used), or a plain object with `{mean: Number, variance: Number, size: Number}` properties.No dependency data recorded yet.