Relative risk calculator
40 events among 200 exposed people versus 20 among 400 unexposed give a relative risk of 4, so the outcome is four times as common with the exposure. You also see the risk in each group. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Exposed events
- 40
- Exposed total
- 200
- Unexposed events
- 20
- Unexposed total
- 400
- Risk exposed
- 0.2
- Risk unexposed
- 0.05
- Relative risk
- 4
Relative risk, also called the risk ratio, is the standard way epidemiology and clinical research compare how often an outcome occurs in people who were exposed to a factor versus those who were not. You enter four non-negative counts—events and totals in the exposed group, events and totals in the unexposed group—and this calculator returns the incidence in each arm plus the single number RR that answers “how many times more (or less) likely is the outcome among the exposed?”
What relative risk means and how the two risks combine
Relative risk compares two incidence proportions drawn from the same study period. In the exposed arm, risk is the number of people who experienced the outcome divided by the total number of people who were exposed. In the unexposed arm, risk is the number of people who experienced the outcome divided by the total number of people who were not exposed.
Relative risk is simply the first risk divided by the second: RR equals (exposed events over exposed total) divided by (unexposed events over unexposed total). An RR of one means the outcome was equally common in both groups. An RR greater than one means the outcome was more common among the exposed; for example RR equals two means twice the risk.
An RR less than one means the outcome was less common among the exposed, which is how protective associations appear when exposure reduces incidence. This definition matches textbooks that build a two-by-two table with cell a for exposed cases, cell b for exposed non-cases, cell c for unexposed cases, and cell d for unexposed non-cases: risk among exposed is a over (a plus b), risk among unexposed is c over (c plus d), and RR is their ratio.
The calculator does not invent confidence intervals or p-values; it returns the point estimate of RR together with both component risks so you can verify the arithmetic by hand. Incidence is only defined when each arm has a positive total, so a zero group total is rejected rather than treated as a silent divide-by-zero.
What you can do with it
Cohort and clinical study tables
Turn a 2×2 table of exposed and unexposed event counts into risk in each arm and a single relative risk for crude association summaries.
Dashboards and newsroom fact-checks
Compute “times the risk” language from published counts without hand arithmetic errors or infinite ratios from empty comparison arms.
FAQ
What happens if a group total is zero?
Risk is events divided by total, so a zero total makes risk (and therefore relative risk) undefined. These failures are not billed.
What if there are no events in the unexposed group?
Relative risk is undefined when unexposed risk is zero (division by zero).
How do I calculate relative risk from a 2×2 table?
Divide the exposed cases by everyone exposed, do the same for the unexposed group, then divide the first risk by the second. With 40 of 200 and 20 of 400, the risks are 0.2 and 0.05, so the relative risk is 4.
What does a relative risk below 1 mean?
It means the outcome was less common among the exposed than among the unexposed. That is how a protective factor shows up, while a value of exactly 1 means both groups had the same risk.
Does the calculator give a confidence interval or a p-value?
No. It returns the point estimate of the relative risk together with the risk in each group, so you can check the arithmetic by hand. It does not invent intervals or significance values.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/relative-risk \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"exposed_events":40,"exposed_total":200,"unexposed_events":20,"unexposed_total":400}'const res = await fetch("https://api.kit.forhosting.com/stat/relative-risk", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"exposed_events": 40,
"exposed_total": 200,
"unexposed_events": 20,
"unexposed_total": 400
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/relative-risk",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"exposed_events": 40,
"exposed_total": 200,
"unexposed_events": 20,
"unexposed_total": 400
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/relative-risk", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"exposed_events":40,"exposed_total":200,"unexposed_events":20,"unexposed_total":400}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"exposed_events":40,"exposed_total":200,"unexposed_events":20,"unexposed_total":400}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/relative-risk", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"exposed_events": 40,
"exposed_total": 200,
"unexposed_events": 20,
"unexposed_total": 400
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.relative_risk",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
When either group total is zero, risk itself is undefined and the task fails with invalid_input instead of inventing a ratio. When the unexposed arm has no events, RR is undefined and the call fails cleanly.
What relative risk means and how the two risks combine
When the unexposed risk is exactly zero—no events among the unexposed—the ratio has no finite value, and the endpoint reports invalid_input instead of Infinity or NaN that would break downstream JSON clients.
Input contract, response shape, and error behaviour
Event counts and totals must be greater than or equal to zero. Event counts must not exceed their matching totals, because you cannot observe more outcomes than people in a group. POST a JSON body with four required finite numbers: exposed_events and exposed_total for the exposed cohort, unexposed_events and unexposed_total for the comparison cohort. Each field may arrive as a JSON number or as a numeric string; non-finite values, missing fields, and empty strings fail with invalid_input naming the field. Both totals must be strictly greater than zero: a group total of zero makes risk undefined, and the error message states that explicitly so graders and API clients can distinguish empty cohorts from other bad input. On success the body echoes the four counts, returns risk_exposed and risk_unexposed as cleaned decimals, returns relative_risk as the ratio of those two risks, and includes a short formula string restating RR equals risk_exposed over risk_unexposed in count form. Example: forty events among two hundred exposed people and twenty events among four hundred unexposed people yields risk_exposed equals zero point two, risk_unexposed equals zero point zero five, and relative_risk equals four—four times the risk among the exposed. Failed validation does not consume prepaid balance. Pair this endpoint with your own software for confidence intervals or Mantel-Haenszel stratification if you need inference beyond the point estimate; this capability is intentionally a pure analytic RR from four counts.
Where a relative risk API earns its keep
Public-health dashboards and cohort study notebooks need a deterministic relative risk calculator that never silently returns Infinity when a comparison arm has zero events. Clinical research assistants use RR to summarise crude associations from two-by-two tables before handing off to a full biostatistics package for adjusted models. Teaching platforms and exam generators need an oracle that marks zero totals and zero unexposed risk as errors rather than empty success payloads a buggy grader might treat as correct. Content sites that rank for relative risk calculator gain a live tool with clear SEO title and keywords, while automation scripts call the same type over the KIT API at the published $0.002 base price with no model tokens and no outbound network.
Integration use cases
Homework and biostatistics teaching
Let students submit four counts and check RR against textbook methods, with clear invalid_input when a group total is zero.
Technical questions
How do I calculate relative risk from counts?
Send exposed_events, exposed_total, unexposed_events, and unexposed_total. The API returns risk_exposed = exposed_events/exposed_total, risk_unexposed = unexposed_events/unexposed_total, and relative_risk = risk_exposed/risk_unexposed.
Does RR greater than 1 mean higher risk among the exposed?
Yes. RR = 1 means equal risk; RR > 1 means higher incidence among the exposed; RR < 1 means lower incidence among the exposed (a protective association on the crude scale).
What does the relative risk calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.