tpmjs/packages/tools/official/permutation-test
Ajax Davis 5c9f1a1d0a chore: update dependencies with compatibility fixes
- Update all packages to latest versions via pnpm update --latest
- Downgrade Prisma 7 to 6 (v7 requires schema migration)
- Downgrade Tailwind CSS 4 to 3 (v4 requires PostCSS migration)
- Downgrade Storybook 10 to 8 (addons not available in v10)
- Pin cheerio to 1.0.0-rc.12 via pnpm override (type exports changed)
- Fix AI SDK tool definitions: parameters -> inputSchema
- Fix cheerio types in extract-meta and table-extract tools
- Add explicit type annotations to tool execute functions
- Migrate biome config to v2.3.11 schema

All type-checks, tests, and builds pass.
2026-01-09 22:49:41 +10:00
..
src feat: add 55 new business tools and improve existing implementations 2026-01-01 19:23:32 +10:00
CHANGELOG.md chore: version packages 2025-12-31 23:54:47 +10:00
package.json chore: update dependencies with compatibility fixes 2026-01-09 22:49:41 +10:00
README.md feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsconfig.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsup.config.ts feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00

@tpmjs/tools-permutation-test

Perform a permutation test to assess the statistical significance of the difference in means between two groups.

Installation

npm install @tpmjs/tools-permutation-test

Usage

import { permutationTestTool } from '@tpmjs/tools-permutation-test';

// Use with AI SDK
const result = await permutationTestTool.execute({
  group1: [23, 25, 27, 29, 31],
  group2: [18, 20, 22, 24, 26],
  iterations: 10000, // optional, default: 10000
});

console.log(result);
// {
//   pValue: 0.0234,
//   observedDiff: 5,
//   significant: true,
//   iterations: 10000,
//   metadata: {
//     group1Size: 5,
//     group2Size: 5,
//     group1Mean: 27,
//     group2Mean: 22,
//     alpha: 0.05
//   }
// }

Parameters

  • group1 (number[], required): First group of numeric values
  • group2 (number[], required): Second group of numeric values
  • iterations (number, optional): Number of permutations to perform (default: 10000, min: 100, max: 100000)

Returns

{
  pValue: number;              // Two-tailed p-value
  observedDiff: number;        // Absolute difference in means
  significant: boolean;        // Whether p < 0.05
  iterations: number;          // Number of permutations performed
  metadata: {
    group1Size: number;
    group2Size: number;
    group1Mean: number;
    group2Mean: number;
    alpha: number;             // Significance level (0.05)
  }
}

How it works

The permutation test is a non-parametric method that doesn't assume normal distribution:

  1. Calculate the observed difference in means between the two groups
  2. Combine all values from both groups
  3. Randomly shuffle the combined data and split into two groups
  4. Calculate the difference in means for each permutation
  5. Count how many permutations have a difference as extreme or more extreme than observed
  6. Calculate p-value as the proportion of extreme permutations

When to use

  • When you can't assume normal distribution
  • With small sample sizes
  • When comparing means between two independent groups
  • Alternative to t-test when assumptions aren't met

License

MIT