Predictive Analytics
src/lib/analytics/predictive-analytics.ts is the deterministic forecasting layer for launch analytics. It uses normalized case facts, historical benchmarks, legal actor profiles, judge patterns, and marketing channel economics to produce forecastable outputs without external model calls.
Covered Predictions
- Case value: blended estimate from case value, medical-specials multiplier, historical case-type benchmark, liability, comparative fault, and policy limits.
- Time-to-resolution: stage progress, historical resolution days, elapsed age, and SOL acceleration.
- Pipeline revenue: expected gross and fee revenue distributed into monthly buckets with confidence bands.
- Settlement probability: stage baseline, case-type settlement rate, liability, demand-package readiness, and actor behavior.
- Demand timing: readiness score, recommended demand date, blockers, and confidence.
- Opposing counsel / adjuster behavior: pressure index, response timing, negotiation rounds, trial tendency, and strategy hint.
- Judge patterns: plaintiff win rate, median verdict, time-to-trial, motion risk, settlement pressure, and strategy hint.
- Marketing ROI: source spend, retained cases, settlement fee revenue, pipeline fee value, payback multiple, and ROI.
Output Contract
buildPredictiveAnalyticsReport(input) returns:
casePredictions: per-case value range, resolution date, settlement/trial/dismissal probabilities, demand timing, actor profile, judge pattern, expected gross, and expected fee revenue.pipelineRevenue: total expected gross/fees, monthly buckets, low/high ranges, and confidence buckets.actorBehavior: sorted opposing-counsel and adjuster pressure profiles.judgePatterns: sorted judge strategy profiles.marketingRoi: channel ROI table plus best/weakest source.recommendations: deterministic next actions for demand timing, actor strategy, forecast confidence, and marketing reallocation.
Product Guidance
- Feed this engine from firm-scoped Prisma queries in analytics routes; keep data fetching outside the engine.
- Treat predictions as decision support, not legal advice or guaranteed outcomes.
- Show confidence, drivers, and source sample sizes anywhere these forecasts appear in the UI.
- Prefer this shared engine over route-local formulas when consolidating
/api/analytics/predictions, case value predictors, revenue forecast, marketing analytics, adjuster pages, and judge research.
Verification
Focused coverage lives in src/__tests__/lib/predictive-analytics.test.ts.
Run:
npm run test:run -- predictive-analytics
npx eslint src/lib/analytics/predictive-analytics.ts src/__tests__/lib/predictive-analytics.test.ts
npm run typecheck