← All procedures

statistics.twoSamplePermutation

The two-sample permutation test (a split of the pooled values). It needs no normal distribution and no pairs, so it compares groups of different sizes. The p holds only if the values of the two groups can change places under the null.

CLI
Package
@procedures/statistics · README
Path
["statistics","twoSamplePermutation"]
CLI
mark statistics twoSamplePermutation --a <number[]> --b <number[]>
As data
{"$proc":["statistics","twoSamplePermutation"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/statistics/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["statistics","twoSamplePermutation"], { a: [], b: [] });
console.log(JSON.stringify(result));

From the command line

$ mark statistics twoSamplePermutation --a <number[]> --b <number[]>

As data, in a program

{
  "$proc": ["statistics", "twoSamplePermutation"],
  "input": { "a": [], "b": [] }
}

Input

FieldTypeRequiredDefaultDescription
anumber[]yes
bnumber[]yes
optionsobjectno

Output

FieldTypeRequiredDefaultDescription
exactbooleanyesThis field is true when the test read each split, so the p has no noise from the draws.
observednumberyesThe statistic of the observed differences `candidate[i] - baseline[i]`.
pnumberyesThe two-sided p: (1 + the flips with a statistic as far from 0 or farther) / (1 + runs).
runsnumberyes
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "a": {
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "b": {
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "options": {
        "type": "object",
        "properties": {
          "runs": {
            "type": "number",
            "description": "The largest number of splits that the test reads. The default is 10 000."
          },
          "seed": {
            "description": "The default is 1.",
            "type": [
              "string",
              "number"
            ]
          },
          "statistic": {
            "type": "object",
            "properties": {
              "$proc": {
                "minItems": 1,
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "input": {},
              "$when": {
                "type": "string",
                "const": "$never"
              }
            },
            "required": [
              "$proc"
            ],
            "additionalProperties": {},
            "x-procedures-program": {
              "params": [
                "a",
                "b"
              ],
              "inputs": [
                {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                },
                {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                }
              ],
              "output": {
                "type": "number"
              }
            },
            "description": "The statistic of the two groups. The default is the median of `a` minus the median of `b`."
          }
        },
        "additionalProperties": {}
      }
    },
    "required": [
      "a",
      "b"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "exact": {
        "type": "boolean",
        "description": "This field is true when the test read each split, so the p has no noise from the draws."
      },
      "observed": {
        "type": "number",
        "description": "The statistic of the observed differences `candidate[i] - baseline[i]`."
      },
      "p": {
        "type": "number",
        "description": "The two-sided p: (1 + the flips with a statistic as far from 0 or farther) / (1 + runs)."
      },
      "runs": {
        "type": "number"
      }
    },
    "required": [
      "exact",
      "observed",
      "p",
      "runs"
    ],
    "additionalProperties": {}
  }
}