|
| 1 | +# TSCSMethods.jl Visualization Plan |
| 2 | + |
| 3 | +This document outlines high-level Mermaid diagrams to illustrate the statistical methodology, user workflows, and package design of TSCSMethods.jl. |
| 4 | + |
| 5 | +## 1. Statistical Methodology Flow |
| 6 | + |
| 7 | +### Diagram 1A: Core TSCS Matching Methodology |
| 8 | +```mermaid |
| 9 | +flowchart TD |
| 10 | + A[Time-Series Cross-Sectional Data] --> B[Treatment Event Detection] |
| 11 | + B --> C[Define Time Windows] |
| 12 | + C --> D[F: Post-Treatment Periods] |
| 13 | + C --> E[L: Pre-Treatment Periods] |
| 14 | + |
| 15 | + D --> F[Matching Process] |
| 16 | + E --> F |
| 17 | + |
| 18 | + F --> G[Mahalanobis Distance Calculation] |
| 19 | + G --> H[Covariate Balancing] |
| 20 | + H --> I[Treatment Effect Estimation] |
| 21 | + I --> J[Bootstrap Inference] |
| 22 | + J --> K[ATT with Confidence Intervals] |
| 23 | + |
| 24 | + style A fill:#e1f5fe |
| 25 | + style K fill:#c8e6c9 |
| 26 | +``` |
| 27 | + |
| 28 | +### Diagram 1B: Advanced Features & Validation |
| 29 | +```mermaid |
| 30 | +flowchart LR |
| 31 | + A[Core Estimation] --> B{Advanced Features} |
| 32 | + |
| 33 | + B --> C[Stratified Estimation] |
| 34 | + B --> D[Caliper Matching] |
| 35 | + B --> E[Refinement Procedures] |
| 36 | + B --> F[Auto-balancing] |
| 37 | + |
| 38 | + C --> G[Statistical Validation] |
| 39 | + D --> G |
| 40 | + E --> G |
| 41 | + F --> G |
| 42 | + |
| 43 | + G --> H[Coverage Tests] |
| 44 | + G --> I[Placebo Tests] |
| 45 | + G --> J[Noiseless Recovery] |
| 46 | + |
| 47 | + H --> K[96% Coverage ✓] |
| 48 | + I --> L[6.87% Type I ✓] |
| 49 | + J --> M[Exact Recovery ✓] |
| 50 | + |
| 51 | + style G fill:#fff3e0 |
| 52 | + style K fill:#c8e6c9 |
| 53 | + style L fill:#c8e6c9 |
| 54 | + style M fill:#c8e6c9 |
| 55 | +``` |
| 56 | + |
| 57 | +## 2. User Workflow Diagrams |
| 58 | + |
| 59 | +### Diagram 2A: Basic User Workflow |
| 60 | +```mermaid |
| 61 | +flowchart TD |
| 62 | + A[Load Data] --> B[Create Model with makemodel()] |
| 63 | + B --> C[Specify Time Windows F & L] |
| 64 | + C --> D[Define Covariates & Time-Varying Dict] |
| 65 | + |
| 66 | + D --> E[Match Phase] |
| 67 | + E --> F[match!(model, data)] |
| 68 | + F --> G[Balance Phase] |
| 69 | + G --> H[balance!(model, data)] |
| 70 | + H --> I[Estimation Phase] |
| 71 | + I --> J[estimate!(model, data)] |
| 72 | + |
| 73 | + J --> K[Results] |
| 74 | + K --> L[model.overall.ATT] |
| 75 | + K --> M[Confidence Intervals] |
| 76 | + K --> N[Bootstrap Distributions] |
| 77 | + |
| 78 | + style A fill:#e3f2fd |
| 79 | + style E fill:#fff3e0 |
| 80 | + style G fill:#f3e5f5 |
| 81 | + style I fill:#e8f5e8 |
| 82 | + style K fill:#fff8e1 |
| 83 | +``` |
| 84 | + |
| 85 | +### Diagram 2B: Advanced Workflows |
| 86 | +```mermaid |
| 87 | +flowchart TD |
| 88 | + A[Basic Workflow Complete] --> B{Advanced Options} |
| 89 | + |
| 90 | + B --> C[Stratified Analysis] |
| 91 | + B --> D[Refinement & Calipers] |
| 92 | + B --> E[Auto-balancing] |
| 93 | + B --> F[Multiple Outcomes] |
| 94 | + |
| 95 | + C --> G[stratify(model)] |
| 96 | + C --> H[CICStratified models] |
| 97 | + |
| 98 | + D --> I[refine(model)] |
| 99 | + D --> J[caliper(model)] |
| 100 | + |
| 101 | + E --> K[autobalance(model)] |
| 102 | + |
| 103 | + F --> L[Vector outcomes in makemodel()] |
| 104 | + |
| 105 | + G --> M[Subgroup Analysis] |
| 106 | + H --> M |
| 107 | + I --> N[Improved Matching] |
| 108 | + J --> N |
| 109 | + K --> O[Optimized Balance] |
| 110 | + L --> P[Simultaneous Estimation] |
| 111 | + |
| 112 | + style B fill:#e1f5fe |
| 113 | + style M fill:#c8e6c9 |
| 114 | + style N fill:#c8e6c9 |
| 115 | + style O fill:#c8e6c9 |
| 116 | + style P fill:#c8e6c9 |
| 117 | +``` |
| 118 | + |
| 119 | +### Diagram 2C: Data Requirements & Validation |
| 120 | +```mermaid |
| 121 | +flowchart LR |
| 122 | + A[Input Data] --> B{Data Structure} |
| 123 | + |
| 124 | + B --> C[Time Variable :t] |
| 125 | + B --> D[Unit ID :id] |
| 126 | + B --> E[Treatment :treatment] |
| 127 | + B --> F[Outcome :outcome] |
| 128 | + B --> G[Covariates :X1, :X2, ...] |
| 129 | + |
| 130 | + C --> H[Validation Checks] |
| 131 | + D --> H |
| 132 | + E --> H |
| 133 | + F --> H |
| 134 | + G --> H |
| 135 | + |
| 136 | + H --> I[Time Window Validation] |
| 137 | + H --> J[Missing Data Handling] |
| 138 | + H --> K[Treatment Event Detection] |
| 139 | + |
| 140 | + I --> L{Valid Windows?} |
| 141 | + J --> L |
| 142 | + K --> L |
| 143 | + |
| 144 | + L -->|Yes| M[Proceed to Analysis] |
| 145 | + L -->|No| N[Informative Error Messages] |
| 146 | + |
| 147 | + style A fill:#e3f2fd |
| 148 | + style H fill:#fff3e0 |
| 149 | + style M fill:#c8e6c9 |
| 150 | + style N fill:#ffcdd2 |
| 151 | +``` |
| 152 | + |
| 153 | +## 3. Package Design Architecture |
| 154 | + |
| 155 | +### Diagram 3A: Module Structure & Dependencies |
| 156 | +```mermaid |
| 157 | +graph TD |
| 158 | + A[TSCSMethods.jl] --> B[core/] |
| 159 | + A --> C[matching/] |
| 160 | + A --> D[balancing/] |
| 161 | + A --> E[estimation/] |
| 162 | + A --> F[advanced/] |
| 163 | + A --> G[utilities/] |
| 164 | + |
| 165 | + B --> B1[types.jl - 37 type definitions] |
| 166 | + B --> B2[construction.jl - makemodel()] |
| 167 | + |
| 168 | + C --> C1[matching_setup.jl] |
| 169 | + C --> C2[distancing.jl - Mahalanobis distances] |
| 170 | + C --> C3[match.jl - Core matching algorithm] |
| 171 | + C --> C4[ranking.jl - Match ranking] |
| 172 | + C --> C5[retrieve_matches*.jl - 3 files] |
| 173 | + |
| 174 | + D --> D1[balancing.jl - Manual balancing] |
| 175 | + D --> D2[autobalancing.jl - P-value optimization] |
| 176 | + D --> D3[meanbalancing.jl] |
| 177 | + D --> D4[fullbalancing.jl - Multiple strategies] |
| 178 | + |
| 179 | + E --> E1[estimation.jl - ATT calculation] |
| 180 | + E --> E2[bootstrapping.jl - Inference] |
| 181 | + E --> E3[overall.jl - Result compilation] |
| 182 | + E --> E4[estimation_stratified.jl] |
| 183 | + |
| 184 | + F --> F1[stratification.jl] |
| 185 | + F --> F2[refine.jl - Match refinement] |
| 186 | + F --> F3[groupindices.jl] |
| 187 | + |
| 188 | + G --> G1[inspection.jl - Diagnostics] |
| 189 | + G --> G2[storage.jl - Save/load] |
| 190 | + G --> G3[example_data.jl] |
| 191 | + |
| 192 | + style A fill:#1976d2,color:#fff |
| 193 | + style B fill:#4fc3f7 |
| 194 | + style C fill:#81c784 |
| 195 | + style D fill:#ffb74d |
| 196 | + style E fill:#f06292 |
| 197 | + style F fill:#ba68c8 |
| 198 | + style G fill:#90a4ae |
| 199 | +``` |
| 200 | + |
| 201 | +### Diagram 3B: Type Hierarchy & Model Flow |
| 202 | +```mermaid |
| 203 | +classDiagram |
| 204 | + class VeryAbstractCICModel { |
| 205 | + +title: String |
| 206 | + +data_info: Dict |
| 207 | + } |
| 208 | + |
| 209 | + class AbstractCICModel { |
| 210 | + +covariates: Vector{Symbol} |
| 211 | + +timevary: Dict |
| 212 | + +F: UnitRange |
| 213 | + +L: UnitRange |
| 214 | + } |
| 215 | + |
| 216 | + class AbstractCICModelStratified { |
| 217 | + +strata: Dict |
| 218 | + } |
| 219 | + |
| 220 | + class CIC { |
| 221 | + +matches: Vector{TreatmentObservationMatches} |
| 222 | + +overall: Overall |
| 223 | + +iterations: Int |
| 224 | + } |
| 225 | + |
| 226 | + class CICStratified { |
| 227 | + +strata_results: Dict |
| 228 | + } |
| 229 | + |
| 230 | + class CaliperCIC { |
| 231 | + +caliper_constraints: Dict |
| 232 | + } |
| 233 | + |
| 234 | + class RefinedCIC { |
| 235 | + +refinement_history: Vector |
| 236 | + } |
| 237 | + |
| 238 | + VeryAbstractCICModel <|-- AbstractCICModel |
| 239 | + VeryAbstractCICModel <|-- AbstractCICModelStratified |
| 240 | + AbstractCICModel <|-- CIC |
| 241 | + AbstractCICModel <|-- CaliperCIC |
| 242 | + AbstractCICModel <|-- RefinedCIC |
| 243 | + AbstractCICModelStratified <|-- CICStratified |
| 244 | +``` |
| 245 | + |
| 246 | +### Diagram 3C: Testing & Validation Architecture |
| 247 | +```mermaid |
| 248 | +flowchart TB |
| 249 | + A[Test Suite: 8,146 Tests] --> B[Unit Tests] |
| 250 | + A --> C[Integration Tests] |
| 251 | + A --> D[Correctness Tests] |
| 252 | + A --> E[Validation Gates] |
| 253 | + |
| 254 | + B --> B1[test/unit/ - By Subsystem] |
| 255 | + B1 --> B2[Construction, Matching, Balancing] |
| 256 | + B1 --> B3[Estimation, Utilities] |
| 257 | + |
| 258 | + C --> C1[test/integration/] |
| 259 | + C1 --> C2[Complete Workflows] |
| 260 | + C1 --> C3[API Integration] |
| 261 | + |
| 262 | + D --> D1[test/correctness/] |
| 263 | + D1 --> D2[Statistical Correctness] |
| 264 | + D1 --> D3[Known Effect Recovery] |
| 265 | + D1 --> D4[Noiseless Scenarios] |
| 266 | + |
| 267 | + E --> E1[Coverage Validation: 96%] |
| 268 | + E --> E2[Placebo Tests: 6.87%] |
| 269 | + E --> E3[Performance Benchmarks] |
| 270 | + |
| 271 | + style A fill:#1976d2,color:#fff |
| 272 | + style E1 fill:#4caf50,color:#fff |
| 273 | + style E2 fill:#4caf50,color:#fff |
| 274 | + style E3 fill:#4caf50,color:#fff |
| 275 | +``` |
| 276 | + |
| 277 | +## 4. Implementation Plan |
| 278 | + |
| 279 | +### Phase 1: Statistical Methodology Diagrams |
| 280 | +1. Create comprehensive methodology flow showing TSCS matching process |
| 281 | +2. Include validation framework diagram |
| 282 | +3. Show relationship between F/L windows and estimation |
| 283 | + |
| 284 | +### Phase 2: User Workflow Diagrams |
| 285 | +1. Basic workflow from data input to results |
| 286 | +2. Advanced features and options |
| 287 | +3. Error handling and validation paths |
| 288 | + |
| 289 | +### Phase 3: Package Architecture Diagrams |
| 290 | +1. Module dependency graph with 37 files |
| 291 | +2. Type hierarchy showing inheritance relationships |
| 292 | +3. Testing infrastructure and validation gates |
| 293 | + |
| 294 | +### Phase 4: Integration & Documentation |
| 295 | +1. Embed diagrams in main documentation |
| 296 | +2. Create interactive examples linking diagrams to code |
| 297 | +3. Add to README.md for quick reference |
| 298 | + |
| 299 | +## Diagram Specifications |
| 300 | + |
| 301 | +- **Format**: Mermaid syntax for GitHub compatibility |
| 302 | +- **Style**: Consistent color coding by functional area |
| 303 | +- **Detail Level**: High-level overview suitable for both technical and non-technical audiences |
| 304 | +- **Interactivity**: Link to relevant documentation sections |
| 305 | +- **Maintenance**: Update diagrams with major version releases |
| 306 | + |
| 307 | +## Usage Context |
| 308 | + |
| 309 | +These diagrams will be used in: |
| 310 | +- Package documentation (docs/src/) |
| 311 | +- README.md overview |
| 312 | +- Tutorial materials |
| 313 | +- Academic presentations |
| 314 | +- GitHub release notes |
| 315 | +- Developer onboarding materials |
| 316 | + |
| 317 | +The diagrams provide visual understanding of: |
| 318 | +1. **Statistical rigor** - Methodology validation and correctness |
| 319 | +2. **User experience** - Clear workflow guidance |
| 320 | +3. **Technical architecture** - Professional code organization |
| 321 | +4. **Quality assurance** - Comprehensive testing approach |
0 commit comments