Which Regression Model? A Decision Flow from Study Design and Outcome (Y) to the Stata Command

On this page
อ่านฉบับภาษาไทย (Thai version)
Abstract
Choosing a regression model is taught as a long list of commands, and the list hides the order of the questions. This article gives that order as one decision flow. Step 0 asks whether the rows are independent: matched sets, repeated measures and clustered patients change the model before anything else does. Step 1 asks what type the outcome is: continuous, count, rate, time to event, ordered, unordered or yes/no. Step 2, for a yes/no outcome only, asks which measure the question needs: an odds ratio, a risk ratio or a risk difference. How common the outcome is never picks the model. A lookup table gives, for each outcome type, the model, the Stata command and the name of the number it reports. One synthetic cohort of 1,200 adults admitted with pneumonia then walks the flow, and the same patients give six outcomes and nine estimates under eight names. This article shows how to choose; the next two parts show how to fit and how to check.
One cohort, six questions about diabetes
Picture a hospital network reviewing its pneumonia admissions: 1,200 adults in 12 hospitals, 327 of them with diabetes. The team asks one plain question: do patients with diabetes do worse?
"Worse" means six different things. They may stay longer, or need the ICU, as 25.8% of all patients did. They may reach a higher severity grade, or leave for a nursing home. They may be readmitted more often, or die sooner: 222 patients died within 365 days.
The exposure and the patients never change; only the outcome does, and each kind of outcome needs its own model. This post builds the flow that picks it, then walks these patients through. The cohort is synthetic, built by code, with no real patient in it.
Step 0: are the rows independent?
Every model in the flow assumes that, once the covariates are known, one row tells you nothing about another. Rows that come in groups break that promise, and the standard errors come out too small. So the design is checked before the outcome.
Individually matched case-control sets go to conditional logistic regression, which compares people only inside their own set: clogit y x, group(set_id). The same holds for risk-set sampling. Here each case's controls are drawn from the people still at risk when that case occurred (Control Sampling in Stata: Question, Controls and Model Are Three Different Things). With such controls, the number clogit reports estimates a rate ratio, which reads as a hazard ratio when hazards are proportional.
Frequency matching, where controls only share the overall age and sex mix, needs no special model: add the matching variables as covariates.
Repeated measures and patients clustered in hospitals keep their model and add vce(cluster id), which tells Stata that rows sharing an id are not independent. The alternatives are a mixed model, with its own intercept per cluster, or generalized estimating equations (GEE), which average over clusters (Population-Averaged Alternatives: GLS, GEE, and Where the Linear Model's Luck Runs Out).
Our patients appear once each and were not matched, but they share 12 hospitals. The usual fit gives an odds ratio for ICU admission of 1.65 (95% CI 1.24 to 2.19). With vce(cluster hospital) it stays 1.65 and the interval widens to 1.17 to 2.31, an interval that is itself rough with only 12 hospitals (Understanding the VCE: Robust Standard Errors, the Sandwich Estimator and vce(cluster id)).
One warning: clogit answers a design question, covered in Why Do Logistic and Conditional Logistic Regression Give Different Odds Ratios?. It does not rescue a logistic model that fails for another reason, such as separation (one group with only yes or only no outcomes), which Part 3 covers.
Step 1: what type of number is Y?
Once the rows are sorted out, the outcome decides the model: not what it measures, but what kind of number it is. Our cohort has six of the seven kinds.
A continuous outcome, like length of stay in days, takes any value on a scale; linear regression, regress, models its mean. A yes/no outcome, like ICU admission, goes on to Step 2. A count, like readmissions, is a whole number of events when everyone is followed for the same time. It goes to Poisson regression, poisson, or to negative binomial regression, nbreg, when the counts vary from patient to patient more than a Poisson model expects (Part 3 shows how to tell).
A rate is a count per unit of time watched. Our patients were followed for different lengths of time, so readmissions per person-year is the honest outcome. It goes to Poisson regression again, now told each patient's person-time: poisson with exposure(fu_years).
A time-to-event outcome, here days to death, is censored for patients alive at day 365: we know only that they lived at least that long. Days to death go to Cox proportional hazards regression. Stata learns the time and the event once, with stset time_d, failure(died). stcox then takes only the covariates, never the outcome.
Severity grade (mild, moderate, severe) is ordered, so use ordinal logistic regression, ologit, which keeps the order. Discharge destination (home, rehabilitation unit, nursing home) is not ordered, so use multinomial logistic regression, mlogit. It compares each destination with a base you name by its code, baseoutcome(0). Left alone, Stata picks the most frequent category as the base.
Step 2: for a yes/no outcome, which measure?
A yes/no outcome can be summarised three ways. The odds ratio compares odds, the risk ratio compares the risks themselves, and the risk difference subtracts them, as extra cases per 100 patients.
For ICU admission, diabetes gives an odds ratio of 1.65 but a risk ratio of 1.41. Neither is wrong: ICU admission is common here, 25.8% of patients, and the two ratios agree only when the outcome is rare.
On the risk scale the same adjusted comparison gives a risk difference of 0.094 (95% CI 0.035 to 0.152), about 9.4 more ICU admissions per 100 patients with diabetes. Because a quarter of all patients were admitted, odds run well above risks. That is why the odds ratio (1.65) sits further from 1 than the risk ratio (1.41).
So the question chooses. For an odds ratio, or for case-control data where risks cannot be estimated, use logistic, valid at any prevalence. For a risk ratio, fit a log-binomial model. It models the log of the risk, so exponentiating the coefficient gives a risk ratio: glm y x, family(binomial) link(log) eform.
It often fails to converge, meaning Stata's search for the estimates never settles. Then use modified Poisson (McNutt 2003; Zou 2004). It borrows the Poisson fit only to get the ratio, and a robust standard error corrects the interval: glm y x, family(poisson) link(log) vce(robust) eform.
For a risk difference, fit a binomial model with an identity link, so the coefficient is the risk difference itself: glm y x, family(binomial) link(identity). If it fails, regress y x, vce(robust) is the linear probability model (Cheung 2007). The step-downs are explained in Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall, and the link in Link and Family: One Picks Your Effect Measure, the Other Your Standard Error. Prevalence never picks the model; it only tells you whether an odds ratio will look like a risk ratio.
The whole flow on one page
Each indigo box is a question, the orange box holds the design answers, and each green box is a command. Tap the picture to enlarge it.
Walking the cohort through the flow
Here are the 1,200 patients again, one outcome at a time, comparing the 327 with diabetes with the rest, adjusted for age and sex. Step 0 gave one answer for all six: the rows are not matched, but the patients sit in 12 hospitals, so the flow says to add vce(cluster hospital) in a final report. To keep the six model families easy to compare, the walk below fits them without it; Step 0 showed what it does to the ICU interval (1.24 to 2.19 becomes 1.17 to 2.31).
- Length of stay, continuous:
regressgives a difference in means of 1.44 days (95% CI 1.16 to 1.71). - ICU admission, yes/no:
logisticgives an odds ratio of 1.65 (1.24 to 2.19), and the modified Poissonglma risk ratio of 1.41 (1.17 to 1.71), so admission was 1.41 times as likely. The identity-link binomialglmgives a risk difference of 0.094 (0.035 to 0.152). - Severity grade, ordered:
ologitgives a cumulative odds ratio of 1.90 (1.49 to 2.42). Diabetes multiplies the odds of being in a more severe grade, against that grade or a milder one, by 1.90, one number for every cut between grades (Part 3 checks the assumption behind it). - Discharge destination, unordered:
mlogitgives relative risk ratios of 1.19 (0.83 to 1.70) for a rehabilitation unit and 2.70 (1.87 to 3.90) for a nursing home, each against home as the base; Part 2 shows how to read them. - Readmissions, a rate:
poissonwithexposure(fu_years)(andvce(robust), the same robust standard error used for modified Poisson in Step 2) gives an incidence rate ratio of 1.58 (1.30 to 1.92), so 1.58 times as many readmissions per person-year. - Time to death, 222 deaths and the rest censored at day 365: after
stset,stcoxgives a hazard ratio of 1.92 (1.47 to 2.51).
Six outcomes, nine estimates, eight names. Each answers the question its own outcome asked, so each is reported by its own name.
The do-file behind the walk
version 18
set more off
clear all
use "trio_cohort.dta", clear
* ---- 1. A helper: add the diabetes row of the model just fitted to the table ----
* estimate = b, or exp(b) for a ratio; 95% CI = b +/- critical value x SE, then exp()
capture program drop add_row
program define add_row
args ratio equation
if "`equation'" == "" local equation "#1"
local crit = cond(missing(e(df_r)), invnormal(0.975), invttail(e(df_r), 0.025))
local b = [`equation']_b[1.diabetes]
local lo = `b' - `crit' * [`equation']_se[1.diabetes]
local hi = `b' + `crit' * [`equation']_se[1.diabetes]
if "`ratio'" == "ratio" matrix walk = nullmat(walk) \ (exp(`b'), exp(`lo'), exp(`hi'))
else matrix walk = nullmat(walk) \ (`b', `lo', `hi')
end
* ---- 2. Step 1, continuous Y: length of stay -> regress (difference in mean days) ----
quietly regress los i.diabetes age i.female
add_row difference
* ---- 3. Step 2, yes/no Y, odds ratio wanted: ICU admission -> logistic ----
quietly logistic icu i.diabetes age i.female
add_row ratio
* ---- 4. Step 0 check: the same model, patients grouped by hospital ----
quietly logistic icu i.diabetes age i.female, vce(cluster hospital)
add_row ratio
* ---- 5. Step 2, risk ratio wanted: ICU admission -> modified Poisson ----
* (Poisson working model + robust variance; the log-binomial attempt is in Part 2)
quietly glm icu i.diabetes age i.female, family(poisson) link(log) vce(robust) eform
add_row ratio
* ---- 6. Step 2, risk difference wanted: ICU admission -> identity-link binomial ----
* b is the risk difference itself (no exp); it is printed to 3 decimals in block 11
quietly glm icu i.diabetes age i.female, family(binomial) link(identity)
assert e(converged) == 1
local rd = _b[1.diabetes]
local rd_lo = _b[1.diabetes] - invnormal(0.975) * _se[1.diabetes]
local rd_hi = _b[1.diabetes] + invnormal(0.975) * _se[1.diabetes]
* ---- 7. Step 1, ordered Y: severity grade -> ologit (cumulative odds ratio) ----
quietly ologit severity i.diabetes age i.female, or
add_row ratio
* ---- 8. Step 1, unordered Y: discharge destination -> mlogit, base = home (0) ----
* equation #2 = rehabilitation unit (code 1), equation #3 = nursing home (code 2)
quietly mlogit dispo i.diabetes age i.female, baseoutcome(0) rrr
add_row ratio #2
add_row ratio #3
* ---- 9. Step 1, a rate: readmissions over unequal follow-up -> poisson + exposure() ----
* vce(robust): the same robust standard error as modified Poisson in block 5
quietly poisson readmit_n i.diabetes age i.female, exposure(fu_years) vce(robust) irr
add_row ratio
* ---- 10. Step 1, time to event: death within 365 days -> stset, then stcox ----
quietly stset time_d, failure(died)
quietly stcox i.diabetes age i.female
add_row ratio
* ---- 11. The summary table, the risk difference and the cohort counts ----
matrix colnames walk = estimate ci_lower ci_upper
matrix rownames walk = LOS:mean_diff ICU:OR ICU:OR_cluster ICU:RR Severity:cum_OR ///
Discharge:RRR_rehab Discharge:RRR_nursing Readmit:IRR Death:HR
matlist walk, format(%9.2f) title("Diabetes vs none, adjusted for age and sex")
display "ICU risk difference: " %5.3f `rd' " (95% CI " %5.3f `rd_lo' " to " %5.3f `rd_hi' ///
"), that is " %3.1f 100 * `rd' " more admissions per 100 patients"
quietly levelsof hospital
display "Patients: " _N "; hospitals: " r(r)
quietly count if diabetes == 1
display "With diabetes: " r(N)
quietly summarize icu
display "ICU admission: " %4.1f 100 * r(mean) "% of patients"
quietly count if died == 1
display "Deaths within 365 days: " r(N)
. matlist walk, format(%9.2f) title("Diabetes vs none, adjusted for age and sex
> ")
Diabetes vs none, adjusted for age and sex
| estimate ci_lower ci_upper
-------------+--------------------------------
LOS |
mean_diff | 1.44 1.16 1.71
-------------+--------------------------------
ICU |
OR | 1.65 1.24 2.19
OR_cluster | 1.65 1.17 2.31
RR | 1.41 1.17 1.71
-------------+--------------------------------
Severity |
cum_OR | 1.90 1.49 2.42
-------------+--------------------------------
Discharge |
RRR_rehab | 1.19 0.83 1.70
RRR_nursing | 2.70 1.87 3.90
-------------+--------------------------------
Readmit |
IRR | 1.58 1.30 1.92
-------------+--------------------------------
Death |
HR | 1.92 1.47 2.51
. display "ICU risk difference: " %5.3f `rd' " (95% CI " %5.3f `rd_lo' " to " %
> 5.3f `rd_hi' ///
> "), that is " %3.1f 100 * `rd' " more admissions per 100 patients"
ICU risk difference: 0.094 (95% CI 0.035 to 0.152), that is 9.4 more admissions
> per 100 patients
. quietly levelsof hospital
. display "Patients: " _N "; hospitals: " r(r)
Patients: 1200; hospitals: 12
. quietly count if diabetes == 1
. display "With diabetes: " r(N)
With diabetes: 327
. quietly summarize icu
. display "ICU admission: " %4.1f 100 * r(mean) "% of patients"
ICU admission: 25.8% of patients
. quietly count if died == 1
. display "Deaths within 365 days: " r(N)
Deaths within 365 days: 222
The lookup table
| Type of Y | Model | Stata command | What exp(b) or b is called | Read more |
|---|---|---|---|---|
| Continuous | Linear regression | regress y x | b: difference in means | Part 2, Fit |
| Yes/no, odds ratio wanted | Logistic regression | logistic y x | odds ratio | Link and Family: One Picks Your Effect Measure, the Other Your Standard Error |
| Yes/no, risk ratio wanted | Log-binomial; step-down: modified Poisson | glm y x, family(binomial) link(log) eform | risk ratio | Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall |
| Yes/no, risk difference wanted | Binomial with an identity link; step-down: linear probability model | glm y x, family(binomial) link(identity) | b: risk difference | Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall |
| Count, same follow-up | Poisson or negative binomial | poisson y x, irr or nbreg y x, irr | incidence rate ratio (IRR) | Part 3, Check |
| Rate, follow-up differs | Poisson with person-time | poisson y x, exposure(t) irr | incidence rate ratio (IRR) | Rates, Poisson Regression, and the Missing Lambda Backbone |
| Time to event | Cox proportional hazards | stset t, failure(d) then stcox x | hazard ratio (HR) | Cox Proportional Hazards Regression and Related Survival-Analysis Concepts |
| Ordered categories | Ordinal logistic | ologit y x, or | cumulative odds ratio | Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes |
| Unordered categories | Multinomial logistic | mlogit y x, baseoutcome(0) rrr | relative risk ratio (RRR) | Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes |
| Matched or risk-set sampled sets (Step 0) | Conditional logistic | clogit y x, group(set_id) or | matched odds ratio; with risk-set sampled controls, a rate ratio (HR under proportional hazards) | Why Do Logistic and Conditional Logistic Regression Give Different Odds Ratios? |
What the next two parts do
This post stopped at choosing. The other two parts use the same 1,200 patients.
- Part 2, fitting each model and reading the one line of output that matters
- Part 3, checking what each model assumes and what to fit when a check fails
References
- McNutt LA, Wu C, Xue X, Hafner JP. Estimating the relative risk in cohort studies and clinical trials of common outcomes. Am J Epidemiol. 2003;157(10):940-943. doi:10.1093/aje/kwg074 https://doi.org/10.1093/aje/kwg074
- Zou G. A modified Poisson regression approach to prospective studies with binary data. Am J Epidemiol. 2004;159(7):702-706. doi:10.1093/aje/kwh090 https://doi.org/10.1093/aje/kwh090
- Cheung YB. A modified least-squares regression approach to the estimation of risk difference. Am J Epidemiol. 2007;166(11):1337-1344. doi:10.1093/aje/kwm223 https://doi.org/10.1093/aje/kwm223
Key takeaways
- Ask about the design first: matched sets go to clogit; repeated or clustered rows add vce(cluster id), a mixed model or GEE.
- Then name the type of Y; each type has its own model and its own name for the number it reports.
- For a yes/no Y, name the measure first (odds ratio, risk ratio or risk difference); each has its own command and its own fallback.
- Prevalence never picks the model; it only tells you whether the odds ratio will sit near the risk ratio (1.65 against 1.41 for ICU admission here).
- The same 1,200 patients gave nine estimates with eight names; report each one by its name.
Related in the wiki: Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall · Link and Family: One Picks Your Effect Measure, the Other Your Standard Error · Understanding the VCE: Robust Standard Errors, the Sandwich Estimator and vce(cluster id) · Why Do Logistic and Conditional Logistic Regression Give Different Odds Ratios? · Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes