# ttest

> Perform the Student's t hypothesis test

Latest version **4.0.0** (published 2021-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install ttest
pnpm add ttest
yarn add ttest
bun add ttest
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-12-29 |
| First published | 2013-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/ttest) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 21.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | Andreas Madsen |
| Maintainers | andreasmadsen |
| Keywords | hypothesis, student t |

## Links

- npm: https://www.npmjs.com/package/ttest
- Repository: https://github.com/AndreasMadsen/ttest
- Homepage: https://github.com/AndreasMadsen/ttest#readme
- Issues: https://github.com/AndreasMadsen/ttest/issues
- npm.io page: https://npm.io/package/ttest

## Dependencies (2)

- [summary](https://npm.io/package/summary.md) ^2.0.0
- [distributions](https://npm.io/package/distributions.md) ^2.1.0

## Recent versions

- 4.0.0 (latest) — 2021-12-29
- 3.0.0 — 2020-08-13
- 2.1.1 — 2019-12-19
- 2.1.0 — 2019-08-25
- 2.0.0 — 2018-12-04
- 1.1.0 — 2016-11-24
- 1.0.0 — 2016-08-12
- 0.3.1 — 2015-02-25
- 0.3.0 — 2013-07-24
- 0.2.0 — 2013-07-01

## README

# ttest

> Perform the Student t hypothesis test

## Installation

```sheel
npm install ttest
```

## Example

```javascript
var ttest = require('ttest');

// One sample t-test
ttest([0,1,1,1], {mu: 1}).valid() // true

// Two sample t-test
ttest([0,1,1,1], [1,2,2,2], {mu: -1}).valid() // true
```

## Documentation

```javascript
var ttest = require('ttest');
```

The `ttest` module supports both one and two sample t-testing, and both
equal and none equal variance.

If one array of data is given its a one sample t-test, and if two data arrays
are given its a two sample t-test.

`ttest()` supports data in the following format:

* an array of values, e.g. `ttest([1, 2, 3])`
* a [`Summary`](https://github.com/AndreasMadsen/summary) object,
  e.g. `ttest(new Summary([1, 2, 3]))`
* an object with the following properties: `mean`, `variance`,
  `size`, e.g. `ttest({mean: 123, variance: 1, size: 42})`

In all cases you can also pass an extra optional object, there takes the
following properties:

```javascript
const options = {
  // Default: 0
  // One sample case: this is the µ that the mean will be compared with.
  // Two sample case: this is the ∂ value that the mean diffrence will be compared with.
  mu: Number,

  // Default: false
  // If false don't assume variance is equal and use the Welch approximation.
  // This only applies if two samples are used.
  varEqual: Boolean,

  // Default: 0.05
  // The significance level of the test
  alpha: Number,

  // Default "not equal"
  // What should the alternative hypothesis be:
  // - One sample case: could the mean be less, greater or not equal to mu property.
  // - Two sample case: could the mean diffrence be less, greater or not equal to mu property.
  alternative: "less" || "greater" || "not equal"
};
```

The t-test object is finally created by calling the `ttest` constructor.

```javascript
const stat = ttest(sample, options);
const stat = ttest(sampleA, sampleB, options);
```

When the `ttest` object is created you can get the following information.

##### stat.testValue()

Returns the `t` value also called the `statistic` value.

##### stat.pValue()

Returns the `p-value`.

##### stat.confidence()

Returns an array containing the confidence interval, where the confidence level
is calculated as `1 - options.alpha`. Where the lower limit has index `0` and
the upper limit has index `1`. If the alternative hypothesis is `less` or
`greater` one of the sides will be `+/- Infinity`.

##### stat.valid()

Simply returns true if the `p-value` is greater or equal to the `alpha` value.

##### stat.freedom()

Returns the degrees of freedom used in the t-test.

---
_Source: https://npm.io/package/ttest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
