Skip to content

[Feature] Extend personal pattern discovery across behavioral, treatment, and environmental factors #616

Description

@lutzkind

Summary

Extend HealthLog’s personal correlation-discovery system so it can analyze timed and quantified contextual factors—including medication events, lifestyle events, illness, symptoms, workouts, sleep timing, travel, cycle context, and environmental exposure—and surface only evidence-backed, confidence-gated explanations through Coach and Insights.

This request combines the analytical engine and its Coach presentation because the evidence contract, confidence thresholds, causal wording, and source traceability must remain consistent from computation to narration.

Problem

HealthLog already contains many potentially relevant contributors and outcomes, but they are not analyzed through one general contextual-pattern framework.

Examples include:

  • Medication intake, missed doses, schedule changes, and dose changes.
  • Alcohol, caffeine, nicotine, meals, hydration, stress, and sleep aids.
  • Workouts and training load.
  • Illness episodes and symptom severity.
  • Mood tags and rated factors.
  • Sleep timing and naps.
  • Menstrual-cycle context when enabled.
  • Travel and timezone changes.
  • Temperature, daylight, pollution, pollen, pressure, heat, and smoke.

The existing correlation infrastructure is a strong foundation: bounded channel sets, lagging, minimum paired-day requirements, statistical testing, false-discovery correction, effect-size floors, shrinkage, confidence tiers, and non-causal framing.

However, many meaningful questions require more than one daily yes/no channel:

  • Does alcohol quantity or time of last drink relate to nocturnal heart rate, HRV, or sleep stages?
  • Does late caffeine differ from morning caffeine?
  • Are symptoms more common after missed medication doses or after a dose revision?
  • Does outdoor exercise during high heat or poor air quality relate to recovery differently from indoor exercise?
  • Do late meals, travel, illness, or weekends explain an apparent sleep pattern?
  • Are several weak factors repeatedly present together before the same outcome change?

Goals

  1. Consume existing and new contextual contributors through a common, source-aware interface.
  2. Support timing, duration, quantity, and dose where relevant.
  3. Match factor-specific exposure windows to plausible outcome windows.
  4. Preserve HealthLog’s current statistical safeguards and strengthen them for a larger hypothesis space.
  5. Produce an explicit evidence object that Insights and Coach must follow.
  6. Surface proactive explanations only when evidence and user preferences justify them.
  7. Never convert association into diagnosis or causal certainty.

Input architecture

The engine should consume authoritative records through adapters rather than copying them into a second analytics ledger.

Potential inputs:

Each input should preserve:

  • Factor key/category.
  • Timestamp, duration, and timezone.
  • Quantity and unit where available.
  • Source and authoritative-record link.
  • Confirmed versus inferred status.
  • Confidence and data-quality metadata.

Time relationships

A single fixed D → D+1 lag is insufficient for all factors. Support a curated set of factor-specific windows, for example:

Same window or same day

  • Workout intensity versus exercise heart rate or symptoms.
  • Heat/pollution during an outdoor workout versus workout performance.
  • Medication intake versus near-term symptom response where clinically appropriate and user configured.

Same night

  • Alcohol, caffeine, nicotine, late meals, stress, exercise timing, bedroom/environmental context versus:
    • Sleep duration.
    • Sleep stages.
    • Awakenings or fragmentation.
    • Nocturnal/resting heart rate.
    • HRV.
    • Respiratory rate.
    • Oxygen saturation or breathing disturbances.

Next morning or next day

  • Prior-evening factors versus readiness, recovery, mood, resting pulse, HRV, activity, or symptoms.
  • Missed medication or adherence changes versus subsequent symptoms or vital drift.
  • Daylight, activity, and stress versus later sleep timing or quality.

Multi-day or cumulative windows

  • Consecutive poor-air-quality or high-heat days.
  • Training load over several days versus recovery.
  • Medication changes versus gradual symptom or vital trends.
  • Repeated short sleep versus mood and activity.

Windows should be curated by factor family rather than allowing an unrestricted combinatorial scan over arbitrary lags.

Quantity, timing, and dose-response

Where data permits, analyze more than factor present/absent:

  • Alcohol standard drinks or grams of ethanol.
  • Caffeine milligrams and hours before sleep.
  • Nicotine quantity and timing.
  • Meal timing and approximate size.
  • Medication dose and dose changes.
  • Workout duration/intensity/load.
  • Heat hours, pollutant concentration, or pollen level.
  • Sleep opportunity and bedtime shift.

Potential methods:

  • Bounded bins with minimum support.
  • Continuous association when assumptions and sample size are sufficient.
  • Monotonic trend or simple regression with robust checks.
  • With/without comparison as a fallback when quantity is too sparse.

Do not infer a dose-response from only a few events.

Confounder-aware comparisons

Passive personal data is observational. The engine should attempt to reduce obvious confounding where sufficient data exists.

Potential matching or adjustment variables:

  • Weekday versus weekend.
  • Travel/timezone change.
  • Illness episode.
  • Exercise load.
  • Sleep opportunity and bedtime.
  • Medication changes.
  • Temperature when evaluating pollution.
  • Alcohol when evaluating late meals.
  • Seasonal or long-term trend.
  • Data-source/device changes.

The engine should degrade to an unadjusted descriptive association when adjustment is not defensible, and label it accordingly.

Statistical safeguards

Preserve and extend the current quality discipline:

  • Minimum paired observations.
  • Minimum exposed and unexposed support where applicable.
  • Effect-size floor.
  • Multiple-comparison/FDR control across the tested family.
  • Sample-size shrinkage.
  • Confidence tiers.
  • Outlier-resistant summaries where appropriate.
  • Explicit missing-data and source-coverage checks.
  • Avoid same-family tautologies and duplicated derived channels.
  • Version the analysis method so old and new results remain explainable.
  • Do not surface a pattern solely because p < 0.05.

Because the number of possible factors and outcomes can grow substantially, the tested hypothesis set must remain curated, bounded, and inspectable.

Multi-factor coincidences

A useful later capability is detecting repeated combinations, for example:

Late alcohol plus a late meal and a hotter-than-usual night often preceded higher nocturnal pulse.

This should not be unrestricted association-rule mining. Suggested safeguards:

  • Curated combinations of at most two or three factors.
  • Strong minimum support.
  • Holdout or stability checks where data volume allows.
  • Multiple-comparison control.
  • Comparison against the strongest single-factor explanation.
  • Never describe a combination as causal.
  • Do not surface a cluster that is merely a proxy for weekend, travel, or illness.

Evidence contract

Every surfaced pattern should produce a structured evidence object containing at least:

  • Factor and outcome.
  • Time window/lag.
  • Analysis window dates.
  • Exposed and comparison sample counts.
  • Quantity/timing definition where relevant.
  • Outcome difference and effect size.
  • Raw and adjusted significance/confidence information where applicable.
  • Confidence tier.
  • Data sources used.
  • Missing-data or source-change warnings.
  • Adjustment/matching variables used.
  • Whether the result is established, emerging, or insufficient.
  • Plain-language non-causal interpretation.
  • Links to the underlying days/events where privacy and UX permit.

Insights, notifications, briefings, and Coach should render from this contract rather than independently inventing stronger wording.

Coach and proactive explanations

Proactive behavior

Coach may proactively surface a pattern only when:

  • The user has enabled contextual insights/Coach use.
  • The pattern passes the configured statistical and effect-size gates.
  • There is enough recent or retrospective support.
  • It has not already been dismissed or repeatedly shown without new evidence.
  • The message is actionable or meaningfully explanatory.
  • No higher-priority safety or data-quality warning contradicts it.

Confidence-gated language

Examples:

Established personal association

Across 24 comparable evenings, alcohol-logged nights were associated with a higher nocturnal pulse and lower HRV. The result is observational and does not prove alcohol caused the change.

Emerging signal

There is an early hint that caffeine within six hours of bedtime coincides with shorter sleep. This is based on seven paired nights, so more data is needed.

Treatment context

Symptoms were logged more often on days after a missed dose during this period. Other changes, including illness and sleep, may also contribute. Do not change medication without professional guidance.

Environmental context

Resting pulse was somewhat higher after high-PM2.5 days in the available data. This is modeled ambient exposure, not a measurement of your personal inhaled dose.

Language that should not be allowed

  • “Alcohol caused your poor sleep.”
  • “Pollution caused your high heart rate.”
  • “Your medication is ineffective.”
  • “Stop or change this medication.”
  • “This pattern proves you have a condition.”

User controls and feedback

  • Show why the insight appeared.
  • Expand to evidence and source days.
  • Mark useful, not useful, incorrect event, or not relevant.
  • Dismiss a pattern or mute a factor.
  • Correct underlying events.
  • Choose whether Coach can use lifestyle, medication, reproductive, or environmental context.
  • Avoid repeating the same insight unless evidence materially changes.

Optional guided N-of-1 experiments

A later phase could turn a passive association into a user-chosen experiment, for example:

  • No caffeine after 14:00 for two weeks.
  • Earlier dinner period.
  • Air purifier on versus normal routine.
  • Stable bedtime period.
  • Alcohol-free comparison period.

Requirements:

  • Explicit user opt-in.
  • Clear protocol and duration.
  • Adherence tracking.
  • Predefined outcomes.
  • No experiment involving medication changes without clinician direction.
  • Honest reporting when results are inconclusive.

This can be implemented later, but the evidence contract should not block it.

Privacy and safety

  • Sensitive contextual categories remain optional.
  • Existing domain authorization rules apply to every adapter.
  • Prompt payloads should contain only the evidence needed for the current explanation, not an unbounded raw timeline.
  • No plaintext sensitive events in logs or telemetry.
  • Inferred factors must never be silently promoted to confirmed facts.
  • Medication findings must carry a stronger safety frame and must not recommend dose changes.
  • Reproductive and substance-use context require explicit module/user controls.
  • Environmental data must retain modeled/measured provenance.

Acceptance criteria

  • The engine can consume existing medication, workout, illness, mood, sleep, cycle, travel, and environmental contributors without duplicating their records.
  • Timed and quantified lifestyle events from [Feature] Add a unified contextual-factor timeline and structured lifestyle-event logging #613 can participate in analysis.
  • Factor-specific same-day, same-night, next-day, and bounded cumulative windows are supported.
  • Quantity/timing analysis degrades safely to present/absent when data is sparse.
  • Tested pairs are bounded and pass minimum-support, effect-size, and FDR safeguards.
  • Obvious source changes and missing-data problems can suppress or downgrade results.
  • Every surfaced result provides a structured evidence object with sample counts, lag, effect, confidence, provenance, and non-causal wording.
  • Coach, Insights, and proactive notifications cannot exceed the evidence object’s confidence tier.
  • Users can inspect, dismiss, mute, correct, and give feedback on surfaced patterns.
  • Medication-related insights cannot recommend starting, stopping, or changing treatment.
  • Tests cover timing windows, timezone/travel behavior, dose normalization, source projection, FDR family construction, confidence wording, suppression, redaction, and evidence-to-Coach rendering.

Dependencies and related issues

The engine can begin with existing contributors, while #613 and #615 expand the available factor set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions