Catalog/stat-sample-size

Calculators

Required sample size API

Compute the sample size needed to estimate a proportion (n = z²·p(1−p)/E²) or a mean (n = (z·sd/E)²) within a target margin of error at a confidence level, rounded up. Auditable: echoes the z value and formula. Answers 'how many people do I need to survey','sample size for 95% confidence and 5% margin','required n for this study'.

Price$0.01per request
MethodPOST
Route/v1/calc/stat-sample-size
StatusLive
MIME typeapplication/json
Rate limit120/minute
CacheNo cache
calcstatisticssample-sizesurveymargin-of-errorpowerproportionplanning
API URLhttps://x402.hexl.dev/v1/calc/stat-sample-size
Integration docs
Example request
{
  "type": "proportion",
  "marginOfError": 0.05,
  "p": 0.5,
  "confidence": 0.95
}
Example response
{
  "type": "proportion",
  "confidence": 0.95,
  "z": 1.96,
  "marginOfError": 0.05,
  "p": 0.5,
  "formula": "n = z^2·p(1-p) / E^2",
  "requiredSampleSize": 385,
  "exactN": 384.1459,
  "rating": "moderate",
  "interpretation": "Need n=385 to estimate the proportion within ±0.05 at 95% confidence."
}
Input schema
{
  "type": "object",
  "required": [
    "marginOfError"
  ],
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "proportion",
        "mean"
      ],
      "default": "proportion"
    },
    "marginOfError": {
      "type": "number",
      "description": "target half-width E (>0)",
      "examples": [
        0.05
      ]
    },
    "p": {
      "type": "number",
      "default": 0.5,
      "description": "assumed proportion (proportion mode)"
    },
    "sd": {
      "type": "number",
      "description": "assumed sd (mean mode)"
    },
    "confidence": {
      "type": "number",
      "default": 0.95
    }
  }
}
Output schema
{
  "type": "object",
  "additionalProperties": true
}