Datalens.ai
← All algorithms

STATISTICAL-TESTS

binomtest

Perform a test that the probability of success is p.

Example of usage

Python API reference included; executable data demonstration pending review.

Usage / limitations

+Use when: Evaluate statistical evidence.

−Limitations: Check input requirements, mathematical assumptions and version-specific behaviour before using.

Mathematical formula

See method documentation: implementation and assumptions vary.
Sample dataShow
{
  "variable": "clinical_study",
  "domain": "Illustrative clinical trial and laboratory measurements",
  "feature_names": [
    "baseline_score",
    "treated_score",
    "control_score"
  ],
  "records": [
    {
      "participant": "P01",
      "baseline_score": 12.0,
      "treated_score": 8.0,
      "control_score": 13.0
    },
    {
      "participant": "P02",
      "baseline_score": 15.0,
      "treated_score": 11.0,
      "control_score": 16.0
    },
    {
      "participant": "P03",
      "baseline_score": 14.0,
      "treated_score": 10.0,
      "control_score": 16.0
    },
    {
      "participant": "P04",
      "baseline_score": 18.0,
      "treated_score": 13.0,
      "control_score": 19.0
    },
    {
      "participant": "P05",
      "baseline_score": 16.0,
      "treated_score": 11.0,
      "control_score": 17.0
    },
    {
      "participant": "P06",
      "baseline_score": 20.0,
      "treated_score": 15.0,
      "control_score": 21.0
    },
    {
      "participant": "P07",
      "baseline_score": 17.0,
      "treated_score": 12.0,
      "control_score": 19.0
    },
    {
      "participant": "P08",
      "baseline_score": 19.0,
      "treated_score": 14.0,
      "control_score": 20.0
    },
    {
      "participant": "P09",
      "baseline_score": 21.0,
      "treated_score": 16.0,
      "control_score": 23.0
    },
    {
      "participant": "P10",
      "baseline_score": 22.0,
      "treated_score": 17.0,
      "control_score": 22.0
    },
    {
      "participant": "P11",
      "baseline_score": 24.0,
      "treated_score": 18.0,
      "control_score": 25.0
    },
    {
      "participant": "P12",
      "baseline_score": 23.0,
      "treated_score": 17.0,
      "control_score": 24.0
    }
  ]
}

Code example (Python)

# DataLens.ai example — binomtest
# Domain: illustrative clinical trial and laboratory measurements.
# Sample input is included by Copy input + code + test.
import numpy as np
from scipy import stats
baseline = np.array([row["baseline_score"] for row in clinical_study["records"]], dtype=float)
treated = np.array([row["treated_score"] for row in clinical_study["records"]], dtype=float)
control = np.array([row["control_score"] for row in clinical_study["records"]], dtype=float)

# Assess eight observed recoveries in ten patients against a 50% null rate.
result = stats.binomtest(k=8, n=10, p=0.5)
assert np.isclose(result.statistic, 0.8)
assert 0 <= result.pvalue <= 1

print("Expected output verified")