epidemiology-methodslisted
Install: claude install-skill choxos/BiostatAgent
# Epidemiology Methods in R
## Overview
Comprehensive epidemiological analysis methods covering study designs, measures of association, confounding control, propensity scores, and causal inference using R.
## Measures of Association
### Risk and Rate Measures
```r
library(epiR)
# 2x2 table data
# Outcome: +/-
# Exposure: +/-
table_data <- matrix(c(a, b, c, d), nrow = 2, byrow = TRUE)
colnames(table_data) <- c("Disease+", "Disease-")
rownames(table_data) <- c("Exposed", "Unexposed")
# Risk ratio, risk difference, odds ratio
epi.2by2(as.table(table_data), method = "cohort.count")
# For case-control
epi.2by2(as.table(table_data), method = "case.control")
# For cross-sectional
epi.2by2(as.table(table_data), method = "cross.sectional")
```
### Incidence Rates
```r
library(Epi)
# Person-time calculations
# Create Lexis object
lex <- Lexis(
entry = list(age = entry_age, cal = entry_date),
exit = list(cal = exit_date),
exit.status = event,
data = cohort_data
)
# Split person-time by age bands
lex_split <- splitLexis(lex, breaks = seq(30, 80, by = 10), time.scale = "age")
# Calculate rates
rates <- tapply(status(lex_split, "exit"),
timeBand(lex_split, "age", type = "factor"),
function(x) sum(x == 1))
pyrs <- tapply(dur(lex_split),
timeBand(lex_split, "age", type = "factor"),
sum)
# Incidence rates
rates / pyrs * 1000
```
### Standardized Rates
```r
library(epitools)
# Direct standardization
ageadju