Dengue Risk Model
Who becomes a dengue case? A logistic regression built step by step: which variables earn a place, whether age acts as a straight line, which link to use — ending with two defensible models and the trade-off between them.
- data
- course dataset · 196 individuals · age, level, sector, case (yes/no)
- model
- binomial GLM · logit link · profile-likelihood intervals
- tools
- R 4.1 · DHARMa · pROC · car · ggplot2 · R Markdown
- checks
- likelihood-ratio tests · link comparison · simulated residuals · Cook · AUC
- model card
- huggingface.co/igorlimamillis/dengue-logistic-regression
- status
- course project · final model choice left open on purpose
196 people, one yes/no outcome
Each row is one individual: age, socioeconomic level (1 high, 2 medium, 3 low), city sector (1 or 2) and whether they became a case. Of the 196 individuals, 57 (29.1%) are cases. The charts show raw shares, before any model.
Two things stand out. The share of cases is much higher in sector 2 than in sector 1, while the three levels look alike. By age, the share jumps after the first decade and then wanders — but only 36 people are 40 or older, so the intervals there are wide.
Which variables earn a place
The starting point is caso ~ nivel + idade + setor (case, level, age, sector — the variable names of the dataset) with a logit link. Age and sector are clearly associated with the outcome; the two level coefficients cannot be told apart from zero. Coefficients are shown as odds ratios, holding the other variables fixed.
Those p-values compare each level with level 1. Whether the whole factor helps — and whether any interaction does — is a question for likelihood-ratio tests between nested models:
| added term | Δ deviance | d.f. | p-value |
|---|---|---|---|
| level, with linear age | 0.419 | 2 | 0.811 |
| level, with quadratic age | 1.317 | 2 | 0.518 |
| age × sector, with linear age | 0.263 | 1 | 0.608 |
| age × sector, with quadratic age | 0.299 | 1 | 0.584 |
| age and age² × sector | 1.884 | 2 | 0.390 |
None improves the fit, so the candidate models drop level and keep the effects additive.
Age is not a straight line
A single OR per year assumes every extra year adds the same amount to the log-odds. Adding an age² term tests that assumption: the deviance drops by 8.06 with one degree of freedom (p = 0.0045) and the AIC goes from 217.64 to 211.58. The fitted curve peaks near 47.5 years (95% CI 36 to 59) — wide enough that the exact position of the peak is uncertain.
The quadratic term never enters without the linear one: dropping it would force the vertex to age zero. The figure compares the two age models by sector.
Bands are 95% confidence intervals; circles are the observed shares in the bands 0–20, 20–40, 40–60 and 60+. The models agree up to about 40 years; beyond that the data are scarce and the bands of the quadratic model widen a lot.
No age × sector interaction was found, so the sector effect is the same at every age: the two panels differ only by a vertical shift on the logit scale.
One odds ratio per interval, not per year
For ages a₁ and a₂ the log-odds difference is b₁(a₂−a₁) + b₂(a₂²−a₁²); the intercept and the sector term cancel. Model A gives the same OR for any 10-year interval, model B does not. Only 36 individuals are 40 or older (17 are 60 or older), so the intervals in that region are wide and lean on the assumed quadratic shape.
| 10-year interval | model A · OR (95% CI) | model B · OR (95% CI) |
|---|---|---|
| 20 → 30 | 1.31 (1.10 to 1.55) | 1.71 (1.30 to 2.24) |
| 30 → 40 | 1.31 (1.10 to 1.55) | 1.35 (1.12 to 1.62) |
| 40 → 50 | 1.31 (1.10 to 1.55) | 1.06 (0.84 to 1.34) |
| 50 → 60 | 1.31 (1.10 to 1.55) | 0.84 (0.58 to 1.21) |
| 60 → 70 | 1.31 (1.10 to 1.55) | 0.66 (0.39 to 1.12) |
In model B the OR is clearly above 1 for 20–30 and 30–40 years. From 40 on every interval includes 1, so the data do not show whether risk plateaus or falls.
Link function and diagnostics
The logit link was compared with probit and complementary log-log in both models. They have the same number of parameters, so AIC compares them directly; the differences are below 2, meaning the data do not tell them apart. The logit stays because its coefficients are odds ratios. A link test (adding the squared linear predictor) gives p = 0.441 for model A and p = 0.188 for model B: no sign of a misspecified link.
| link function (AIC) | model A | model B |
|---|---|---|
| logit | 217.64 | 211.58 |
| probit | 217.34 | 210.85 |
| cloglog | 218.11 | 212.56 |
Lower is better; differences under 2 are not meaningful.
| check (p-value unless noted) | model A | model B |
|---|---|---|
| uniformity of simulated residuals (KS) | 0.977 | 0.976 |
| dispersion | 0.840 | 0.812 |
| outliers | 1.000 | 1.000 |
| largest Cook's distance | 0.053 | 0.037 |
| AUC | 0.725 | 0.745 |
Simulated residuals (DHARMa, 500 simulations). Usual Cook's distance cut-offs are 0.5 and 1. The AUC is computed on the same data used to fit.
No check flags a problem, which is weaker evidence than it sounds: with a binary outcome and n = 196, residual-based tests have little power to detect curvature. Model A passes them, yet the likelihood-ratio test of section 03 found the curvature — a reminder to test the specific structure you care about.
Two defensible models, one open decision
The analysis ends with two candidates that differ only in how age enters.
| A · linear age | B · quadratic age | |
|---|---|---|
| formula | caso ~ idade + setor | caso ~ idade + idade² + setor |
| AIC | 217.64 | 211.58 |
| BIC | 227.47 | 224.69 |
| AUC | 0.725 | 0.745 |
| R² McFadden | 0.104 | 0.139 |
| OR, sector 2 vs 1 (95% CI) | 3.26 [1.70, 6.39] | 3.59 [1.83, 7.23] |
| effect of age | one OR per year (1.027) | a curve: one OR per interval |
What this does not settle
- Association, not cause. Observational data: odds ratios describe associations.
- Same data to choose and to judge. The model was selected and assessed on the same sample; p-values ignore the selection and the AUC is apparent, with no external validation.
- Few older people. Only 36 individuals are 40 or older, so the right end of the age curve is poorly estimated and the quadratic shape extrapolates there.
- Low-power checks. Residual diagnostics and the link test detect little with a binary outcome and 196 observations.
- Data. The raw file comes from a course and is not redistributed here; this page shows only aggregated results.
- Model card. Hugging Face ↗ — coefficients of both models, the full R report and the analysis code (no raw data).