STATISTICAL-TESTS
chisquare
Perform Pearson's chi-squared test.
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)
clinical_study = {'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}]}
# DataLens.ai example — chisquare
# 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)
# Compare observed event counts with equal expected counts.
observed = [12, 18, 20]
result = stats.chisquare(observed, f_exp=[50/3]*3)
assert result.statistic > 0 and 0 <= result.pvalue <= 1
print("Expected output verified")
# DataLens.ai example — chisquare
# 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)
# Compare observed event counts with equal expected counts.
observed = [12, 18, 20]
result = stats.chisquare(observed, f_exp=[50/3]*3)
assert result.statistic > 0 and 0 <= result.pvalue <= 1
print("Expected output verified")