tsa-shiny-agent / agent /src /knowledge /tsa_algorithms.md
mmrech's picture
Initial deployment of TSA Shiny Agent
026774a verified
|
Raw
History Blame Contribute Delete
3.35 kB
# TSA Algorithms Reference
## Overview
Trial Sequential Analysis (TSA) applies sequential monitoring boundaries to cumulative meta-analysis, controlling for repeated significance testing as evidence accumulates.
## Core Algorithm: Z-Curve Calculation
### Step 1: Calculate Cumulative Effect
For each study k added to the meta-analysis:
```
Z_k = θ_k / SE_k
```
Where:
- θ_k = pooled effect estimate after k studies
- SE_k = standard error of pooled estimate
### Step 2: Information Fraction
```
t_k = V_k / V_OIS
```
Where:
- V_k = cumulative information (sum of inverse variances)
- V_OIS = required information size
### Step 3: Boundary Calculation
Using alpha-spending function a(t):
```
Z_upper(t) = Φ^(-1)(1 - a(t)/2)
Z_lower(t) = -Z_upper(t) [for symmetrical boundaries]
```
## Optimal Information Size (OIS)
### Dichotomous Outcomes
```
OIS = 4 * (Z_α + Z_β)² * p̄(1-p̄) / (p_C - p_I)²
```
Where:
- Z_α = critical value for type I error
- Z_β = critical value for type II error
- p̄ = average of control and intervention rates
- p_C = expected control event rate
- p_I = expected intervention event rate
### Heterogeneity Adjustment
```
OIS_adjusted = OIS / (1 - I²/100)
```
## Effect Size Calculations
### Odds Ratio (OR)
```
log(OR) = log(a*d / b*c)
SE(log(OR)) = √(1/a + 1/b + 1/c + 1/d)
```
### Relative Risk (RR)
```
log(RR) = log((a/(a+c)) / (b/(b+d)))
SE(log(RR)) = √(c/(a(a+c)) + d/(b(b+d)))
```
### Risk Difference (RD)
```
RD = a/(a+c) - b/(b+d)
SE(RD) = √(ac/(a+c)³ + bd/(b+d)³)
```
## Pooling Methods
### Fixed Effect (Inverse Variance)
```
θ_pooled = Σ(w_i * θ_i) / Σw_i
SE_pooled = √(1 / Σw_i)
where w_i = 1/SE_i²
```
### Random Effects (DerSimonian-Laird)
```
τ² = max(0, (Q - df) / (Σw_i - Σw_i²/Σw_i))
w_i* = 1/(SE_i² + τ²)
θ_pooled = Σ(w_i* * θ_i) / Σw_i*
```
## Heterogeneity Statistics
### Q Statistic
```
Q = Σw_i(θ_i - θ_pooled)²
```
### I-squared
```
I² = max(0, (Q - df) / Q * 100%)
```
### Tau-squared (τ²)
Between-study variance estimated via:
- DerSimonian-Laird: Method of moments
- REML: Restricted maximum likelihood
- Sidik-Jonkman: Alternative estimator
## Lan-DeMets Alpha Spending
### Implementation
The Lan-DeMets method approximates group sequential boundaries through:
1. Divide [0,1] into small increments
2. At each t: calculate cumulative alpha spent
3. Find Z-boundary that produces exact alpha spent
```java
// Simplified algorithm from LanDeMetsCalculus.java
for (int i = 1; i <= maxIterations; i++) {
t = i / maxIterations;
alpha_spent = spendingFunction(t, alpha);
z_boundary[i] = findBoundary(alpha_spent, previous_boundaries);
}
```
## Boundary Interpolation
For arbitrary information fractions, interpolate between calculated points:
```
Z(t) = Z(t_lower) + (Z(t_upper) - Z(t_lower)) * (t - t_lower) / (t_upper - t_lower)
```
## References
1. Lan GKK, DeMets DL (1983). Discrete sequential boundaries for clinical trials. Biometrika.
2. O'Brien PC, Fleming TR (1979). A multiple testing procedure for clinical trials. Biometrics.
3. Pocock SJ (1977). Group sequential methods in the design and analysis of clinical trials. Biometrika.
4. Wetterslev J, et al. (2008). Trial sequential analysis may establish when firm evidence is reached in cumulative meta-analysis. J Clin Epidemiol.