Stat.Recurrent­Event

This directory packages a finite-horizon Poisson recurrent-event experiment with independent death and censoring.

Counting­Process 85 core · 96 supporting · 20 submodules This directory develops finite iid right-censoring records, compensated censor counts, predictable-integral isometries, and zero-safe Nelson–Aalen squared-risk identities.
Basic 7 core · 0 supporting A generic arm, a finite Poisson sample of points with measurable event times, and independent death and censor times form a product experiment.

Finite-horizon stopped recurrent-event experiment

A generic arm, a finite Poisson sample of points with measurable event times, and independent death and censor times form a product experiment. The observed history retains only the points before the first exit or the fixed horizon. The primitive time-intensity law and cumulative-hazard survival equation are model assumptions; observable risk and event laws are derived in later files.

def hazardSurvival reviewed
Causalean.Stat.RecurrentEvent

A nonnegative hazard and a time determine the survival probability through that time: the exponential of minus the cumulative hazard, the integral of the hazard from time zero to that time.

Definition (Lean source)
h :
ℝ → ℝ≥0
t :
ℝ
hazardSurvival h t :
ℝ
exp (-(∫ u in (0 : ℝ)..t, (h u : ℝ)))
Causalean.Stat.RecurrentEvent.hazardSurvival · Causalean/Stat/RecurrentEvent/Basic.lean:24
structure Model reviewed
Causalean.Stat.RecurrentEvent

An arm space and a recurrence-mark space specify a finite-horizon Poisson recurrent-event model with independent assignment, death, and censoring blocks. The model consists of a probability law for the arm, a probability law for the recurrence marks together with a nonnegative Poisson rate, probability laws for the death and censoring times, a nonnegative horizon, a measurable map sending each mark to its event time, and measurable nonnegative hazard and intensity functions, the hazard being integrable from zero to the horizon. Two equations tie these together: the rate-scaled law of the event time has density equal to the intensity with respect to Lebesgue measure on the times from zero up to but excluding the horizon, and at every time between zero and the horizon the probability of death at or after that time equals the exponential of minus the cumulative hazard up to that time.

Definition (Lean source)
armLaw :
armProb :
pointLaw :
pointProb :
poissonRate :
ℝ≥0
deathLaw :
deathProb :
censorLaw :
censorProb :
horizon :
ℝ
horizon_nonneg :
0 ≤ horizon
time :
X → ℝ
measurable_time :
hazard :
ℝ → ℝ≥0
measurable_hazard :
Measurable hazard
hazard_integrable :
IntervalIntegrable (fun t : ℝ => (hazard t : ℝ)) volume 0 horizon
intensity :
ℝ → ℝ≥0
measurable_intensity :
Measurable intensity
primitive_intensity :
Measure.map time ((poissonRate : ℝ≥0∞) • pointLaw)
= (volume.restrict (Ico 0 horizon)).withDensity (fun t => (intensity t : ℝ≥0∞))
death_survival :
∀ t ∈ Icc (0 : ℝ) horizon, deathLaw (Ici t) = ofReal (hazardSurvival hazard t)
Causalean.Stat.RecurrentEvent.Model · Causalean/Stat/RecurrentEvent/Basic.lean:30
abbrev Outcome reviewed
Causalean.Stat.RecurrentEvent

An arm space and a recurrence-mark space determine one primitive outcome, consisting of an arm, a finite recurrence sample, a death time, and a censoring time.

Definition (Lean source)
A X :
Outcome A X :
Type (max u_3 u_4)
A × (FiniteSample X × (ℝ × ℝ))
Causalean.Stat.RecurrentEvent.Outcome · Causalean/Stat/RecurrentEvent/Basic.lean:67
def primitiveLaw reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model determines the independent product law of its assignment, recurrence, death, and censoring blocks.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
primitiveLaw M :
by letI := M.pointProb exact M.armLaw.prod ((finitePoissonSampleLaw M.pointLaw M.poissonRate).prod (M.deathLaw.prod M.censorLaw))
Causalean.Stat.RecurrentEvent.Model.primitiveLaw · Causalean/Stat/RecurrentEvent/Basic.lean:73 · uses FiniteSample , Model , Outcome
def stopTime reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and a primitive outcome determine the administrative stopping time, the earliest of death, censoring, and the fixed horizon.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
ω :
stopTime M ω :
ℝ
min (min ω.2.2.1 ω.2.2.2) M.horizon
Causalean.Stat.RecurrentEvent.Model.stopTime · Causalean/Stat/RecurrentEvent/Basic.lean:81 · uses Model , Outcome
def observe reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and a primitive outcome determine the stopped observed history: the arm, exit time, death indicator, and recurrence times retained before exit. Missing sequence positions use a value beyond the fixed horizon.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
ω :
observe M ω :
A × (ℝ × (Bool × (ℕ → ℝ)))
(ω.1, M.stopTime ω, decide (ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon), fun n => if hn : n < ω.2.1.1 then if M.time (ω.2.1.2 ⟨n, hn⟩) < M.stopTime ω then M.time (ω.2.1.2 ⟨n, hn⟩) else M.horizon + 1 else M.horizon + 1)
Causalean.Stat.RecurrentEvent.Model.observe · Causalean/Stat/RecurrentEvent/Basic.lean:87 · uses Model , Outcome
def observedLaw reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model determines the observed-history law by applying its stopped-observation rule to the independent primitive experiment.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
observedLaw M :
Measure (A × (ℝ × (Bool × (ℕ → ℝ))))
Measure.map M.observe M.primitiveLaw
Causalean.Stat.RecurrentEvent.Model.observedLaw · Causalean/Stat/RecurrentEvent/Basic.lean:100 · uses Model
Death­Event­Primitive 2 core · 1 supporting The observed death-time pushforward is reduced to the independent primitive arm, death, and censor laws before the hazard-density step. ★ death_primitive_weighted

Primitive representation of observed death events

The observed death-time pushforward is reduced to the independent primitive arm, death, and censor laws before the hazard-density step.

def deathEventMeasure reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm determine the observed armwise death-event measure, the distribution of exit times whose recorded exit is death.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
deathEventMeasure M a :
Measure.map (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => y.2.1) (M.observedLaw.restrict {y | y.1 = a ∧ y.2.2.1 = true})
Causalean.Stat.RecurrentEvent.Model.deathEventMeasure · Causalean/Stat/RecurrentEvent/DeathEventPrimitive.lean:22 · uses Model
theorem death_primitive_weighted reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm have a primitive recorded-death measure equal to the open-horizon death law weighted by assignment mass and censoring retention.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
Measure.map (fun ω : Outcome A X => ω.2.2.1) (M.primitiveLaw.restrict {ω | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon})
= (M.deathLaw.restrict (Ico 0 M.horizon)).withDensity (fun t => M.armLaw {a} * M.censorLaw (Ici t))
Proof (Lean source)
theorem Model.death_primitive_weighted (M : Model A X) (a : A) : Measure.map (fun ω : Outcome A X => ω.2.2.1) (M.primitiveLaw.restrict {ω | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon}) = (M.deathLaw.restrict (Ico 0 M.horizon)).withDensity (fun t => M.armLaw {a} * M.censorLaw (Ici t)) := by letI := M.armProb letI := M.pointProb letI := M.deathProb letI := M.censorProb have hzero : M.deathLaw (Ici (0 : ℝ)) = 1 := by simpa [hazardSurvival] using (M.death_survival 0 ⟨le_rfl, M.horizon_nonneg⟩) have hnonneg : ∀ᵐ t ∂M.deathLaw, 0 ≤ t := by rw [ae_iff] have hc : M.deathLaw (Ici (0 : ℝ))ᶜ = 0 := by rw [measure_compl measurableSet_Ici (by simp), hzero] simp have hset : {t : ℝ | ¬ 0 ≤ t} = (Ici (0 : ℝ))ᶜ := by ext t simp simpa only [hset] using hc apply Measure.ext intro s hs let E : Set (ℝ × ℝ) := {p | p.1 ∈ s ∧ p.1 ≤ p.2 ∧ p.1 < M.horizon} have hE : MeasurableSet E := by dsimp [E] measurability have htime : Measurable (fun ω : Outcome A X => ω.2.2.1) := by fun_prop have hset : {ω : Outcome A X | (ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon) ∧ ω.2.2.1 ∈ s} = ({a} : Set A) ×ˢ (univ ×ˢ E) := by ext ω simp [E, and_comm, and_assoc] have hleft : (Measure.map (fun ω : Outcome A X => ω.2.2.1) (M.primitiveLaw.restrict {ω | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon})) s = M.armLaw {a} * (M.deathLaw.prod M.censorLaw) E := by rw [Measure.map_apply htime hs, Measure.restrict_apply (hs.preimage htime)] rw [Set.inter_comm] change M.primitiveLaw {ω : Outcome A X | (ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon) ∧ ω.2.2.1 ∈ s} = _ rw [hset] unfold Model.primitiveLaw rw [Measure.prod_prod, Measure.prod_prod] simp rw [hleft] have hsection (t : ℝ) : M.censorLaw (Prod.mk t ⁻¹' E) = (s ∩ Iio M.horizon).indicator (fun u => M.censorLaw (Ici u)) t := by by_cases ht : t ∈ s ∩ Iio M.horizon · have heq : Prod.mk t ⁻¹' E = Ici t := by ext c have hlt : t < M.horizon := ht.2 simp [E, ht.1, hlt] simp [heq, ht] · have heq : Prod.mk t ⁻¹' E = ∅ := by ext c have hfail : t ∉ s ∨ ¬ t < M.horizon := by simpa [Set.mem_inter_iff] using (not_and_or.mp ht) rcases hfail with hns | hge · simp [E, hns] · simp [E, hge] simp [heq, ht] have hprod : (M.deathLaw.prod M.censorLaw) E = ∫⁻ t in s ∩ Iio M.horizon, M.censorLaw (Ici t) ∂M.deathLaw := by rw [Measure.prod_apply hE] simp_rw [hsection] exact lintegral_indicator (hs.inter measurableSet_Iio) _ have hsupport : M.deathLaw.restrict (s ∩ Iio M.horizon) = M.deathLaw.restrict (s ∩ Ico 0 M.horizon) := by apply Measure.restrict_congr_set filter_upwards [hnonneg] with t ht change (t ∈ s ∧ t < M.horizon) = (t ∈ s ∧ 0 ≤ t ∧ t < M.horizon) apply propext tauto have htail : Measurable (fun t : ℝ => M.censorLaw (Ici t)) := by let F : Set (ℝ × ℝ) := {p | p.1 ≤ p.2} have hF : MeasurableSet F := by dsimp [F] measurability have hf := measurable_measure_prodMk_left (ν := M.censorLaw) hF convert hf using 1 funext t congr 1 rw [hprod, withDensity_apply _ hs] rw [lintegral_const_mul (M.armLaw {a}) htail] rw [Measure.restrict_restrict hs] rw [hsupport]
Causalean.Stat.RecurrentEvent.Model.death_primitive_weighted · Causalean/Stat/RecurrentEvent/DeathEventPrimitive.lean:63 · uses FiniteSample , Model , primitiveLaw , Outcome
1 supporting declaration (lemmas, instances)
  • death_event_measure_primitive theorem — A recurrent-event model and an arm have an observed death-event measure equal to the primitive death-time law restricted to assigned subjects whose death occurs before censoring and the horizon.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a :
    A
    M.deathEventMeasure a
    = Measure.map (fun ω : Outcome A X => ω.2.2.1) (M.primitiveLaw.restrict {ω | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon})
    Proof (Lean source)
    theorem Model.death_event_measure_primitive (M : Model A X) (a : A) : M.deathEventMeasure a = Measure.map (fun ω : Outcome A X => ω.2.2.1) (M.primitiveLaw.restrict {ω | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon}) := by let s : Set (A × (ℝ × (Bool × (ℕ → ℝ)))) := {y | y.1 = a ∧ y.2.2.1 = true} have hs : MeasurableSet s := by dsimp [s] measurability have hpre : M.observe ⁻¹' s = {ω : Outcome A X | ω.1 = a ∧ ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon} := by ext ω simp [s, Model.observe] have hmeas : Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => y.2.1) := by fun_prop have htime : Measurable (fun ω : Outcome A X => ω.2.2.1) := by fun_prop unfold Model.deathEventMeasure Model.observedLaw rw [Measure.restrict_map M.measurable_observe hs, Measure.map_map hmeas M.measurable_observe, hpre] apply Measure.map_congr apply ae_restrict_of_forall_mem (hs := by rw [← hpre] exact hs.preimage M.measurable_observe) intro ω hω have hd : ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon := ⟨hω.2.1, hω.2.2⟩ have hdh : ω.2.2.1 ≤ M.horizon := le_of_lt hd.2 simp [comp, Model.observe, Model.stopTime, hd, hdh]
    Causalean.Stat.RecurrentEvent.Model.death_event_measure_primitive · Causalean/Stat/RecurrentEvent/DeathEventPrimitive.lean:29
Recurrence­Event­Primitive 3 core · 1 supporting The observed counting kernel is reduced to a finite primitive point sum, then integrated against independent stopping times and Poisson intensity. ★ recurrence_primitive_strict_tail

Primitive representation of observed recurrence events

The observed counting kernel is reduced to a finite primitive point sum, then integrated against independent stopping times and Poisson intensity.

def recurrenceEventMeasure reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm determine the observed armwise recurrence-event measure, which counts every retained recurrence time with multiplicity.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
recurrenceEventMeasure M a :
(M.observedLaw.restrict {y | y.1 = a}).bind (historyCountingKernel A)
Causalean.Stat.RecurrentEvent.Model.recurrenceEventMeasure · Causalean/Stat/RecurrentEvent/RecurrenceEventPrimitive.lean:23 · uses Model
def primitiveRecurrenceCountSet reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model, an arm, a requested time set, and a primitive outcome determine the retained primitive recurrence count in that set: the number of recurrence points whose event time lies in the set and strictly before the stopping time, with points counted by multiplicity, and zero when the outcome's arm is not the given arm.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
s :
Set ℝ
ω :
primitiveRecurrenceCountSet M a s ω :
ℝ≥0∞
by classical exact ∑ i : Fin ω.2.1.1, if ω.1 = a ∧
M.time (ω.2.1.2 i) < M.stopTime ω ∧
M.time (ω.2.1.2 i) ∈ s then (1 : ℝ≥0∞) else 0
Causalean.Stat.RecurrentEvent.Model.primitiveRecurrenceCountSet · Causalean/Stat/RecurrentEvent/RecurrenceEventPrimitive.lean:29 · uses Model , Outcome
theorem recurrence_primitive_strict_tail reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model, an arm, and a measurable time set have a primitive stopped recurrence count equal to Poisson intensity weighted by assignment mass and strict death and censoring retention.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
s :
Set ℝ
hs :
(∫⁻ ω, M.primitiveRecurrenceCountSet a s ω ∂M.primitiveLaw)
= ∫⁻ t in s ∩ Ico (0 : ℝ) M.horizon, M.armLaw {a} * M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞) ∂volume
Proof (Lean source)
theorem Model.recurrence_primitive_strict_tail (M : Model A X) (a : A) (s : Set ℝ) (hs : MeasurableSet s) : (∫⁻ ω, M.primitiveRecurrenceCountSet a s ω ∂M.primitiveLaw) = ∫⁻ t in s ∩ Ico (0 : ℝ) M.horizon, M.armLaw {a} * M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞) ∂volume := by classical letI := M.pointProb letI := M.armProb letI := M.deathProb letI := M.censorProb let μ := Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate let F : FiniteSample X × (ℝ × ℝ) → ℝ≥0∞ := fun z => ∑ i : Fin z.1.1, if M.time (z.1.2 i) ∈ s ∧ M.time (z.1.2 i) < z.2.1 ∧ M.time (z.1.2 i) < z.2.2 ∧ M.time (z.1.2 i) < M.horizon then 1 else 0 have hF : Measurable F := by have he (n : ℕ) : MeasurableEmbedding (fixedSizeEmbed (X := X) n) := by refine ⟨?_, ?_, ?_⟩ · intro x y h exact eq_of_heq (Sigma.mk.inj_iff.mp h).2 · exact measurable_fixedSizeEmbed n · intro u hu change @MeasurableSet _ (⨅ m, (inferInstance : MeasurableSpace (Fin m → X)).map (Sigma.mk m)) (fixedSizeEmbed n '' u) rw [MeasurableSpace.measurableSet_iInf] intro m change MeasurableSet ((fixedSizeEmbed (X := X) m) ⁻¹' ((fixedSizeEmbed (X := X) n) '' u)) by_cases h : m = n · subst m rw [Set.preimage_image_eq u (fun x y h => eq_of_heq (Sigma.mk.inj_iff.mp h).2)] exact hu · convert MeasurableSet.empty using 1 ext x simp only [Set.mem_preimage, Set.mem_image, Set.mem_empty_iff_false, iff_false] rintro ⟨y, _, heq⟩ exact h (congrArg fst heq).symm intro u hu have hset : F ⁻¹' u = ⋃ n : ℕ, (map (fixedSizeEmbed (X := X) n) id) '' {z : (Fin n → X) × (ℝ × ℝ) | F (⟨n, z.1⟩, z.2) ∈ u} := by ext ⟨⟨n, x⟩, dc⟩ constructor · intro ht refine Set.mem_iUnion.mpr ⟨n, ?_⟩ exact ⟨(x, dc), ht, rfl⟩ · intro ht obtain ⟨m, ⟨y, e⟩, hy, hz⟩ := Set.mem_iUnion.mp ht cases hz exact hy rw [hset] apply MeasurableSet.iUnion intro n apply ((he n).prodMap MeasurableEmbedding.id).measurableSet_image.mpr have hn : Measurable (fun z : (Fin n → X) × (ℝ × ℝ) => F (⟨n, z.1⟩, z.2)) := by change Measurable (fun z : (Fin n → X) × (ℝ × ℝ) => ∑ i : Fin n, if M.time (z.1 i) ∈ s ∧ M.time (z.1 i) < z.2.1 ∧ M.time (z.1 i) < z.2.2 ∧ M.time (z.1 i) < M.horizon then (1 : ℝ≥0∞) else 0) apply Finset.measurable_sum intro i hi have ht : Measurable (fun z : (Fin n → X) × (ℝ × ℝ) => M.time (z.1 i)) := M.measurable_time.comp ((measurable_pi_apply i).comp measurable_fst) apply Measurable.ite · convert ((hs.preimage ht).inter (measurableSet_lt ht (measurable_fst.comp measurable_snd))).inter ((measurableSet_lt ht (measurable_snd.comp measurable_snd)).inter (measurableSet_lt ht (measurable_const : Measurable (fun _ => M.horizon)))) using 1 <;> ext z <;> simp only [Set.mem_inter_iff, Set.mem_ofPred_eq, Set.mem_preimage, Function.comp_apply] <;> tauto · exact measurable_const · exact measurable_const exact hn hu let G : A × (FiniteSample X × (ℝ × ℝ)) → ℝ≥0∞ := fun z => if z.1 = a then F z.2 else 0 have hG : Measurable G := Measurable.ite ((measurableSet_singleton a).preimage measurable_fst) (hF.comp measurable_snd) measurable_const have hcount (z : Outcome A X) : M.primitiveRecurrenceCountSet a s z = G z := by unfold Model.primitiveRecurrenceCountSet G F Model.stopTime by_cases ha : z.1 = a · simp only [ha, if_true] apply Finset.sum_congr rfl intro i hi simp only [true_and, lt_min_iff] congr 1 apply propext tauto · simp [ha] have hprimitive : (∫⁻ z, M.primitiveRecurrenceCountSet a s z ∂M.primitiveLaw) = M.armLaw {a} * (∫⁻ z, F z ∂μ.prod (M.deathLaw.prod M.censorLaw)) := by change (∫⁻ z, M.primitiveRecurrenceCountSet a s z ∂M.armLaw.prod (μ.prod (M.deathLaw.prod M.censorLaw))) = _ simp_rw [hcount] rw [lintegral_prod_symm' G hG] have hinner (z : _) : (∫⁻ b, G (b, z) ∂M.armLaw) = M.armLaw {a} * F z := by change (∫⁻ b, ({a} : Set A).indicator (fun _ => F z) b ∂M.armLaw) = _ rw [lintegral_indicator_const (measurableSet_singleton a)] exact mul_comm _ _ simp_rw [hinner] rw [lintegral_const_mul (M.armLaw {a}) hF] rw [hprimitive] have hpoisson (dc : ℝ × ℝ) : (∫⁻ sample, F (sample, dc) ∂μ) = ∫⁻ t in Ico (0 : ℝ) M.horizon, (if t ∈ s ∧ t < dc.1 ∧ t < dc.2 then (M.intensity t : ℝ≥0∞) else 0) ∂volume := by let f : ℝ → ℝ≥0∞ := fun t => if t ∈ s ∧ t < dc.1 ∧ t < dc.2 ∧ t < M.horizon then 1 else 0 have hf : Measurable f := by apply Measurable.ite · convert ((hs.inter (measurableSet_Iio : MeasurableSet (Iio dc.1))).inter (measurableSet_Iio : MeasurableSet (Iio dc.2))).inter (measurableSet_Iio : MeasurableSet (Iio M.horizon)) using 1 <;> ext t <;> simp only [Set.mem_inter_iff, Set.mem_ofPred_eq, Set.mem_Iio] <;> tauto · exact measurable_const · exact measurable_const calc (∫⁻ sample, F (sample, dc) ∂μ) = ∫⁻ t in Ico (0 : ℝ) M.horizon, f t * (M.intensity t : ℝ≥0∞) ∂volume := by exact M.poisson_time_lintegral f hf _ = _ := by apply setLIntegral_congr_fun measurableSet_Ico intro t ht simp only [f] have hth : t < M.horizon := ht.2 by_cases h : t ∈ s ∧ t < dc.1 ∧ t < dc.2 <;> simp [h, hth] have hswap : (∫⁻ z, F z ∂μ.prod (M.deathLaw.prod M.censorLaw)) = ∫⁻ t in Ico (0 : ℝ) M.horizon, ∫⁻ dc : ℝ × ℝ, if t ∈ s ∧ t < dc.1 ∧ t < dc.2 then (M.intensity t : ℝ≥0∞) else 0 ∂(M.deathLaw.prod M.censorLaw) ∂volume := by rw [lintegral_prod_symm' F hF] simp_rw [hpoisson] have hH : Measurable (fun z : (ℝ × ℝ) × ℝ => if z.2 ∈ s ∧ z.2 < z.1.1 ∧ z.2 < z.1.2 then (M.intensity z.2 : ℝ≥0∞) else 0) := by have ht : Measurable (fun z : (ℝ × ℝ) × ℝ => z.2) := measurable_snd exact Measurable.ite ((hs.preimage ht).inter ((measurableSet_lt ht (measurable_fst.comp measurable_fst)).inter (measurableSet_lt ht (measurable_snd.comp measurable_fst)))) (M.measurable_intensity.coe_nnreal_ennreal.comp ht) measurable_const exact lintegral_lintegral_swap hH.aemeasurable rw [hswap] have htail (t : ℝ) : (∫⁻ dc : ℝ × ℝ, if t ∈ s ∧ t < dc.1 ∧ t < dc.2 then (M.intensity t : ℝ≥0∞) else 0 ∂(M.deathLaw.prod M.censorLaw)) = if t ∈ s then M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞) else 0 := by by_cases ht : t ∈ s · simp only [ht, true_and, if_true] have hfun : (fun dc : ℝ × ℝ => if t < dc.1 ∧ t < dc.2 then (M.intensity t : ℝ≥0∞) else 0) = (Ioi t ×ˢ Ioi t).indicator (fun _ => (M.intensity t : ℝ≥0∞)) := by funext dc simp [indicator, Set.mem_prod] rw [hfun] rw [lintegral_indicator_const (measurableSet_Ioi.prod measurableSet_Ioi)] rw [Measure.prod_prod] exact mul_comm _ _ · simp [ht] simp_rw [htail] have htailMeas (ν : Measure ℝ) [SFinite ν] : Measurable (fun t : ℝ => ν (Ioi t)) := by let E : Set (ℝ × ℝ) := {p | p.1 < p.2} have hE : MeasurableSet E := by dsimp [E] exact measurableSet_lt measurable_fst measurable_snd have h := measurable_measure_prodMk_left (ν := ν) hE convert h using 1 funext t congr 1 have hscore : Measurable (fun t : ℝ => if t ∈ s then M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞) else 0) := by exact Measurable.ite hs (((htailMeas M.deathLaw).mul (htailMeas M.censorLaw)).mul M.measurable_intensity.coe_nnreal_ennreal) measurable_const rw [← lintegral_const_mul (M.armLaw {a}) hscore] calc (∫⁻ t in Ico (0 : ℝ) M.horizon, M.armLaw {a} * if t ∈ s then M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞) else 0 ∂volume) = ∫⁻ t in Ico (0 : ℝ) M.horizon, s.indicator (fun t => M.armLaw {a} * M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * (M.intensity t : ℝ≥0∞)) t ∂volume := by congr 1 funext t by_cases ht : t ∈ s <;> simp [indicator, ht, mul_assoc] _ = _ := by rw [lintegral_indicator hs, Measure.restrict_restrict hs]
1 supporting declaration (lemmas, instances)
  • recurrence_event_measure_primitive theorem — A recurrent-event model, an arm, and a measurable time set have observed recurrence-event mass equal to the primitive expected retained count before the observed stop.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a :
    A
    s :
    Set ℝ
    hs :
    M.recurrenceEventMeasure a s = ∫⁻ ω, M.primitiveRecurrenceCountSet a s ω ∂M.primitiveLaw
    Proof (Lean source)
    theorem Model.recurrence_event_measure_primitive (M : Model A X) (a : A) (s : Set ℝ) (hs : MeasurableSet s) : M.recurrenceEventMeasure a s = ∫⁻ ω, M.primitiveRecurrenceCountSet a s ω ∂M.primitiveLaw := by classical have hcount (ω : Outcome A X) : (historyCountingKernel A (M.observe ω)) s = ∑ i : Fin ω.2.1.1, if M.time (ω.2.1.2 i) < M.stopTime ω ∧ M.time (ω.2.1.2 i) ∈ s then (1 : ℝ≥0∞) else 0 := by have hbad : ¬ M.horizon + 1 < M.stopTime ω := by have hle : M.stopTime ω ≤ M.horizon := min_le_right _ _ linarith change (Measure.sum (fun n : ℕ => if (M.observe ω).2.2.2 n < (M.observe ω).2.1 then Measure.dirac ((M.observe ω).2.2.2 n) else 0)) s = _ rw [Measure.sum_apply _ hs] rw [tsum_eq_sum (s := range ω.2.1.1)] · rw [← Fin.sum_univ_eq_sum_range] apply Finset.sum_congr rfl intro n hn have hn' : (n : ℕ) < ω.2.1.1 := n.isLt by_cases ht : M.time (ω.2.1.2 n) < M.stopTime ω · simp [Model.observe, hn', ht, Measure.dirac_apply, indicator] · simp [Model.observe, hn', ht, hbad] · intro n hn have hn' : ¬ n < ω.2.1.1 := by simpa using hn simp [Model.observe, hn', hbad] have hmeas : Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => (historyCountingKernel A y) s) := (historyCountingKernel A).measurable_coe hs have harm : MeasurableSet {y : A × (ℝ × (Bool × (ℕ → ℝ))) | y.1 = a} := (measurableSet_singleton a).preimage measurable_fst calc M.recurrenceEventMeasure a s = ∫⁻ y in {y | y.1 = a}, (historyCountingKernel A y) s ∂M.observedLaw := by unfold Model.recurrenceEventMeasure rw [Measure.bind_apply hs (historyCountingKernel A).aemeasurable] _ = ∫⁻ ω, ({y | y.1 = a}.indicator (fun y => (historyCountingKernel A y) s)) (M.observe ω) ∂M.primitiveLaw := by rw [← lintegral_indicator harm _] unfold Model.observedLaw exact lintegral_map (μ := M.primitiveLaw) (hmeas.indicator harm) M.measurable_observe _ = ∫⁻ ω, M.primitiveRecurrenceCountSet a s ω ∂M.primitiveLaw := by congr 1 funext ω change (if ω.1 = a then (historyCountingKernel A (M.observe ω)) s else 0) = M.primitiveRecurrenceCountSet a s ω by_cases ha : ω.1 = a · simp only [ha, if_true] rw [hcount ω] simp [Model.primitiveRecurrenceCountSet, ha] · simp [ha, Model.primitiveRecurrenceCountSet]
    Causalean.Stat.RecurrentEvent.Model.recurrence_event_measure_primitive · Causalean/Stat/RecurrentEvent/RecurrenceEventPrimitive.lean:43
Risk­Set 3 core · 0 supporting The observed risk probability and its model-side time measure factor through independent assignment, death, and censor blocks before the fixed horizon. ★ risk_factorization

Armwise observable risk sets

The observed risk probability and its model-side time measure factor through independent assignment, death, and censor blocks before the fixed horizon.

def riskProbability reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model, an arm, and a time determine that arm's observable risk probability: the joint probability, under the observed-history law, that the unit is assigned to that arm and its observed exit time (the earliest of death, censoring, and the fixed horizon) is at least that time. It is a joint probability with the arm, not a probability conditional on the arm.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
t :
ℝ
riskProbability M a t :
ℝ≥0∞
M.observedLaw {y | y.1 = a ∧ t ≤ y.2.1}
Causalean.Stat.RecurrentEvent.Model.riskProbability · Causalean/Stat/RecurrentEvent/RiskSet.lean:21 · uses Model
def riskSetMeasure reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm determine the armwise risk-set measure: the measure on the time axis that has, with respect to Lebesgue measure on the half-open interval from zero up to (but excluding) the fixed horizon, density equal at each time t to the arm's assignment probability times the probability that death occurs at or after t times the probability that censoring occurs at or after t.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
riskSetMeasure M a :
(volume.restrict (Ico 0 M.horizon)).withDensity (fun t => M.armLaw {a} * M.deathLaw (Ici t) * M.censorLaw (Ici t))
Causalean.Stat.RecurrentEvent.Model.riskSetMeasure · Causalean/Stat/RecurrentEvent/RiskSet.lean:30 · uses Model
theorem risk_factorization reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model, an arm, and a time between zero and the fixed horizon, endpoints included have an observable risk probability equal to the arm's assignment probability times the probability that death occurs at or after that time times the probability that censoring occurs at or after that time.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
t :
ℝ
ht :
t ∈ Icc (0 : ℝ) M.horizon
M.riskProbability a t = M.armLaw {a} * M.deathLaw (Ici t) * M.censorLaw (Ici t)
Proof (Lean source)
theorem Model.risk_factorization (M : Model A X) (a : A) (t : ℝ) (ht : t ∈ Icc (0 : ℝ) M.horizon) : M.riskProbability a t = M.armLaw {a} * M.deathLaw (Ici t) * M.censorLaw (Ici t) := by letI := M.armProb letI := M.pointProb letI := M.deathProb letI := M.censorProb have hs : MeasurableSet {y : A × (ℝ × (Bool × (ℕ → ℝ))) | y.1 = a ∧ t ≤ y.2.1} := by measurability have hpre : M.observe ⁻¹' {y : A × (ℝ × (Bool × (ℕ → ℝ))) | y.1 = a ∧ t ≤ y.2.1} = ({a} : Set A) ×ˢ (univ ×ˢ ((Ici t) ×ˢ (Ici t))) := by ext ω simp [Model.observe, Model.stopTime, ht.2, and_assoc, Prod.le_def] unfold Model.riskProbability Model.observedLaw rw [Measure.map_apply M.measurable_observe hs, hpre] unfold Model.primitiveLaw rw [Measure.prod_prod, Measure.prod_prod, Measure.prod_prod] simp only [measure_univ, one_mul, mul_assoc]
Causalean.Stat.RecurrentEvent.Model.risk_factorization · Causalean/Stat/RecurrentEvent/RiskSet.lean:40 · uses Model , riskProbability
Death­Stopped­Mean 2 core · 0 supporting A finite Poisson recurrence sample is stopped strictly before independent death and the fixed horizon, without censoring. ★ death_stopped_poisson_mean

Mean recurrence count stopped by independent death

A finite Poisson recurrence sample is stopped strictly before independent death and the fixed horizon, without censoring.

def deathStoppedCountMean reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model determines the expected count of primitive Poisson recurrence points before independent death and the fixed horizon, without censoring.

Definition (Lean source)
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
deathStoppedCountMean M :
ℝ≥0∞
letI := M.pointProb ∫⁻ z, ∑ i : Fin z.1.1, if M.time (z.1.2 i) < z.2 ∧
M.time (z.1.2 i) < M.horizon then (1 : ℝ≥0∞) else 0 ∂((finitePoissonSampleLaw M.pointLaw M.poissonRate).prod M.deathLaw)
Causalean.Stat.RecurrentEvent.Model.deathStoppedCountMean · Causalean/Stat/RecurrentEvent/DeathStoppedMean.lean:22 · uses Model
theorem death_stopped_poisson_mean reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model has an independently death-stopped Poisson recurrence mean equal to the integral of death survival times recurrence intensity over the fixed horizon.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
M.deathStoppedCountMean
= ∫⁻ t in Ico (0 : ℝ) M.horizon, M.deathLaw (Ici t) * (M.intensity t : ℝ≥0∞) ∂volume
Proof (Lean source)
theorem Model.death_stopped_poisson_mean (M : Model A X) : M.deathStoppedCountMean = ∫⁻ t in Ico (0 : ℝ) M.horizon, M.deathLaw (Ici t) * (M.intensity t : ℝ≥0∞) ∂volume := by letI := M.pointProb letI := M.deathProb let μ := Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate let F : FiniteSample X × ℝ → ℝ≥0∞ := fun z => ∑ i : Fin z.1.1, if M.time (z.1.2 i) < z.2 ∧ M.time (z.1.2 i) < M.horizon then 1 else 0 have hF : Measurable F := by have he (n : ℕ) : MeasurableEmbedding (fixedSizeEmbed (X := X) n) := by refine ⟨?_, ?_, ?_⟩ · intro x y h exact eq_of_heq (Sigma.mk.inj_iff.mp h).2 · exact measurable_fixedSizeEmbed n · intro s hs change @MeasurableSet _ (⨅ m, (inferInstance : MeasurableSpace (Fin m → X)).map (Sigma.mk m)) (fixedSizeEmbed n '' s) rw [MeasurableSpace.measurableSet_iInf] intro m change MeasurableSet ((fixedSizeEmbed (X := X) m) ⁻¹' ((fixedSizeEmbed (X := X) n) '' s)) by_cases h : m = n · subst m rw [Set.preimage_image_eq s (fun x y h => eq_of_heq (Sigma.mk.inj_iff.mp h).2)] exact hs · convert MeasurableSet.empty using 1 ext x simp only [Set.mem_preimage, Set.mem_image, Set.mem_empty_iff_false, iff_false] rintro ⟨y, _, heq⟩ exact h (congrArg fst heq).symm intro t ht have hset : F ⁻¹' t = ⋃ n : ℕ, (map (fixedSizeEmbed (X := X) n) id) '' {z : (Fin n → X) × ℝ | F (⟨n, z.1⟩, z.2) ∈ t} := by ext ⟨⟨n, x⟩, d⟩ constructor · intro ht refine Set.mem_iUnion.mpr ⟨n, ?_⟩ exact ⟨(x, d), ht, rfl⟩ · intro ht obtain ⟨m, ⟨y, e⟩, hy, hz⟩ := Set.mem_iUnion.mp ht cases hz exact hy rw [hset] apply MeasurableSet.iUnion intro n apply ((he n).prodMap MeasurableEmbedding.id).measurableSet_image.mpr have hn : Measurable (fun z : (Fin n → X) × ℝ => F (⟨n, z.1⟩, z.2)) := by change Measurable (fun z : (Fin n → X) × ℝ => ∑ i : Fin n, if M.time (z.1 i) < z.2 ∧ M.time (z.1 i) < M.horizon then (1 : ℝ≥0∞) else 0) apply Finset.measurable_sum intro i hi apply Measurable.ite · exact (measurableSet_lt (M.measurable_time.comp ((measurable_pi_apply i).comp measurable_fst)) measurable_snd).inter (measurableSet_lt (M.measurable_time.comp ((measurable_pi_apply i).comp measurable_fst)) measurable_const) · exact measurable_const · exact measurable_const exact hn ht change (∫⁻ z, F z ∂μ.prod M.deathLaw) = _ rw [lintegral_prod_symm' F hF] calc (∫⁻ d, ∫⁻ s, F (s, d) ∂μ ∂M.deathLaw) = ∫⁻ d, ∫⁻ t in Ico (0 : ℝ) M.horizon, if t < d then (M.intensity t : ℝ≥0∞) else 0 ∂volume ∂M.deathLaw := by apply lintegral_congr intro d exact M.poisson_count_before_death d _ = ∫⁻ t in Ico (0 : ℝ) M.horizon, ∫⁻ d, if t < d then (M.intensity t : ℝ≥0∞) else 0 ∂M.deathLaw ∂volume := by have hG : Measurable (fun z : ℝ × ℝ => if z.2 < z.1 then (M.intensity z.2 : ℝ≥0∞) else 0) := by exact Measurable.ite (measurableSet_lt measurable_snd measurable_fst) (M.measurable_intensity.coe_nnreal_ennreal.comp measurable_snd) measurable_const exact lintegral_lintegral_swap hG.aemeasurable _ = ∫⁻ t in Ico (0 : ℝ) M.horizon, M.deathLaw (Ioi t) * (M.intensity t : ℝ≥0∞) ∂volume := by apply setLIntegral_congr_fun measurableSet_Ico intro t ht change (∫⁻ d, (Ioi t).indicator (fun _ => (M.intensity t : ℝ≥0∞)) d ∂M.deathLaw) = _ rw [lintegral_indicator_const measurableSet_Ioi] exact mul_comm _ _ _ = ∫⁻ t in Ico (0 : ℝ) M.horizon, M.deathLaw (Ici t) * (M.intensity t : ℝ≥0∞) ∂volume := by apply lintegral_congr_ae filter_upwards [ae_restrict_of_ae (ae_measure_Ioi_eq_Ici M.deathLaw)] with t ht rw [ht]
Causalean.Stat.RecurrentEvent.Model.death_stopped_poisson_mean · Causalean/Stat/RecurrentEvent/DeathStoppedMean.lean:34 · uses Model , deathStoppedCountMean
Death­Density 1 core · 0 supporting Independent death and censor blocks yield the observable death-event law with hazard density relative to the armwise risk-set measure. ★ death_event_density

Observable death-event hazard density

Independent death and censor blocks yield the observable death-event law with hazard density relative to the armwise risk-set measure.

theorem death_event_density reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm have an observable death-event measure with the death hazard as density relative to the armwise risk-set measure, including the empty zero-horizon case.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
M.deathEventMeasure a = (M.riskSetMeasure a).withDensity (fun t => (M.hazard t : ℝ≥0∞))
Proof (Lean source)
theorem Model.death_event_density (M : Model A X) (a : A) : M.deathEventMeasure a = (M.riskSetMeasure a).withDensity (fun t => (M.hazard t : ℝ≥0∞)) := by let μ : Measure ℝ := volume.restrict (Ico 0 M.horizon) let w : ℝ → ℝ≥0∞ := fun t => M.armLaw {a} * M.censorLaw (Ici t) let s : ℝ → ℝ≥0∞ := fun t => ofReal (hazardSurvival M.hazard t) let h : ℝ → ℝ≥0∞ := fun t => (M.hazard t : ℝ≥0∞) have hcensor : Measurable (fun t : ℝ => M.censorLaw (Ici t)) := Antitone.measurable (fun _ _ hxy => measure_mono (Ici_subset_Ici.mpr hxy)) have hw : Measurable w := measurable_const.mul hcensor have hh : Measurable h := M.measurable_hazard.coe_nnreal_ennreal have hs : AEMeasurable s μ := by apply aemeasurable_restrict_of_antitoneOn measurableSet_Ico intro x hx y hy hxy change ofReal (hazardSurvival M.hazard y) ≤ ofReal (hazardSurvival M.hazard x) rw [← M.death_survival x ⟨hx.1, hx.2.le⟩, ← M.death_survival y ⟨hy.1, hy.2.le⟩] exact measure_mono (Ici_subset_Ici.mpr hxy) have hf : AEMeasurable (s * h) μ := hs.mul hh.aemeasurable calc M.deathEventMeasure a = (M.deathLaw.restrict (Ico 0 M.horizon)).withDensity w := by rw [M.death_event_measure_primitive, M.death_primitive_weighted] _ = (μ.withDensity (s * h)).withDensity w := by rw [M.death_law_restrict_eq_withDensity] rfl _ = μ.withDensity ((s * h) * w) := (withDensity_mul₀ hf hw.aemeasurable).symm _ = μ.withDensity ((w * s) * h) := by congr 1 funext t simp only [Pi.mul_apply] ac_rfl _ = (μ.withDensity (w * s)).withDensity h := withDensity_mul₀ (hw.aemeasurable.mul hs) hh.aemeasurable _ = (M.riskSetMeasure a).withDensity h := by congr 1 unfold Model.riskSetMeasure μ w s apply withDensity_congr_ae filter_upwards [ae_restrict_mem measurableSet_Ico] with t ht simp only [Pi.mul_apply] rw [M.death_survival t ⟨ht.1, ht.2.le⟩] ac_rfl
Causalean.Stat.RecurrentEvent.Model.death_event_density · Causalean/Stat/RecurrentEvent/DeathDensity.lean:23 · uses Model , deathEventMeasure , riskSetMeasure
Hazard­Density 1 core · 3 supporting The finite-horizon survival equation determines the death-time density on the open administrative horizon. ★ death_law_restrict_eq_withDensity

Hazard survival to death density

The finite-horizon survival equation determines the death-time density on the open administrative horizon. This is a primitive-law lemma, independent of observation and recurrence.

theorem death_law_restrict_eq_withDensity reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model has a death-time law on its open finite horizon with density equal to survival times hazard relative to Lebesgue measure.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
M.deathLaw.restrict (Ico 0 M.horizon)
= (volume.restrict (Ico 0 M.horizon)).withDensity (fun t => ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞))
Proof (Lean source)
theorem Model.death_law_restrict_eq_withDensity (M : Model A X) : M.deathLaw.restrict (Ico 0 M.horizon) = (volume.restrict (Ico 0 M.horizon)).withDensity (fun t => ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞)) := by letI := M.deathProb let f : ℝ → ℝ≥0∞ := fun t => ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞) let ν : Measure ℝ := (volume.restrict (Ico 0 M.horizon)).withDensity f have hν : ν = (volume.withDensity f).restrict (Ico 0 M.horizon) := (restrict_withDensity measurableSet_Ico f).symm change M.deathLaw.restrict (Ico 0 M.horizon) = ν apply Measure.ext_of_Ico' · intro a b hab exact measure_ne_top _ _ · intro a b hab let c := max a 0 let d := min b M.horizon have hset : Ico a b ∩ Ico 0 M.horizon = Ico c d := Set.Ico_inter_Ico have hsub : Ico c d ⊆ Ico 0 M.horizon := by intro t ht exact ⟨le_trans (le_max_right _ _) ht.1, lt_of_lt_of_le ht.2 (min_le_right _ _)⟩ have hleft : (M.deathLaw.restrict (Ico 0 M.horizon)) (Ico a b) = M.deathLaw (Ico c d) := by rw [Measure.restrict_apply measurableSet_Ico, hset] have hright : ν (Ico a b) = ν (Ico c d) := by calc ν (Ico a b) = (volume.withDensity f) (Ico c d) := by rw [hν, Measure.restrict_apply measurableSet_Ico, hset] _ = ν (Ico c d) := by rw [hν, Measure.restrict_apply measurableSet_Ico, Set.inter_eq_self_of_subset_left hsub] rw [hleft, hright] by_cases hcd : c ≤ d · have hc : 0 ≤ c := le_max_right _ _ have hd : d ≤ M.horizon := min_le_right _ _ change M.deathLaw (Ico c d) = ((volume.restrict (Ico 0 M.horizon)).withDensity f) (Ico c d) rw [M.death_law_Ico_eq_survival_sub c d hc hcd hd, M.survival_hazard_density_Ico c d hc hcd hd] · have hempty : Ico c d = ∅ := Set.Ico_eq_empty_of_le (le_of_not_ge hcd) simp [hempty]
Causalean.Stat.RecurrentEvent.Model.death_law_restrict_eq_withDensity · Causalean/Stat/RecurrentEvent/HazardDensity.lean:186 · uses Model , hazardSurvival
3 supporting declarations (lemmas, instances)
  • hazardSurvival_interval_integral theorem — A nonnegative hazard, a terminal horizon, and two ordered times with an integrable hazard over the horizon give survival-weighted hazard mass equal to the loss of survival over the interval.
    h :
    ℝ → ℝ≥0
    H a b :
    ℝ
    hh :
    IntervalIntegrable (fun t : ℝ => (h t : ℝ)) volume 0 H
    ha :
    0 ≤ a
    hab :
    a ≤ b
    hb :
    b ≤ H
    (∫ t in a..b, hazardSurvival h t * (h t : ℝ)) = hazardSurvival h a - hazardSurvival h b
    Proof (Lean source)
    theorem hazardSurvival_interval_integral (h : ℝ → ℝ≥0) (H a b : ℝ) (hh : IntervalIntegrable (fun t : ℝ => (h t : ℝ)) volume 0 H) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ H) : (∫ t in a..b, hazardSurvival h t * (h t : ℝ)) = hazardSurvival h a - hazardSurvival h b := by let G : ℝ → ℝ := fun t => ∫ u in (0 : ℝ)..t, (h u : ℝ) have h0H : 0 ≤ H := by linarith have hG : AbsolutelyContinuousOnInterval G 0 H := hh.absolutelyContinuousOnInterval_intervalIntegral (by simp [h0H]) have hsub : uIcc a b ⊆ uIcc (0 : ℝ) H := by rw [uIcc_of_le hab, uIcc_of_le h0H] exact Icc_subset_Icc ha hb have hG' : AbsolutelyContinuousOnInterval (fun t => -G t) a b := (hG.mono hsub).fun_neg obtain ⟨C, hC⟩ := hG'.exists_bound have hmap : Set.MapsTo (fun t => -G t) (uIcc a b) (Icc (-C) C) := by intro x hx have hx' := hC x hx exact mem_Icc.mpr (abs_le.mp (by simpa only [Real.norm_eq_abs] using hx')) obtain ⟨K, hK⟩ : ∃ K, LipschitzOnWith K exp (Icc (-C) C) := ((Real.contDiff_exp (n := 1)).contDiffOn).exists_lipschitzOnWith (by norm_num) (convex_Icc _ _) isCompact_Icc have hS : AbsolutelyContinuousOnInterval (hazardSurvival h) a b := by change AbsolutelyContinuousOnInterval (fun t => exp (-G t)) a b have hbound := hG'.const_mul (K : ℝ) unfold AbsolutelyContinuousOnInterval at hbound ⊢ apply squeeze_zero' ?_ ?_ (by simpa using hbound) · exact Filter.Eventually.of_forall (fun _ => Finset.sum_nonneg (fun _ _ => dist_nonneg)) · rw [eventually_inf_principal] filter_upwards with E hE apply Finset.sum_le_sum intro i hi have hi₁ := hmap (hE.1 i hi).1 have hi₂ := hmap (hE.1 i hi).2 calc _ ≤ (K : ℝ) * dist (-G (E.2 i).1) (-G (E.2 i).2) := hK.dist_le_mul _ hi₁ _ hi₂ _ = _ := by simp [Real.dist_eq, ← mul_sub, abs_mul, abs_of_nonneg K.coe_nonneg] have hderiv : ∀ᵐ x ∂volume.restrict (uIoc a b), deriv (hazardSurvival h) x = -(hazardSurvival h x * (h x : ℝ)) := by filter_upwards [ae_restrict_of_ae hh.ae_hasDerivAt_integral, ae_restrict_mem measurableSet_uIoc] with x hx hmem have hx0H : x ∈ uIcc (0 : ℝ) H := hsub (uIoc_subset_uIcc hmem) have hD : HasDerivAt G (h x : ℝ) x := by simpa only [G] using hx hx0H 0 (by simp [h0H]) have hD' : HasDerivAt (hazardSurvival h) (-(hazardSurvival h x * (h x : ℝ))) x := by convert (Real.hasDerivAt_exp (-G x)).comp x hD.neg using 1 <;> first | rfl | simp [hazardSurvival, G] exact hD'.deriv calc (∫ t in a..b, hazardSurvival h t * (h t : ℝ)) = ∫ t in a..b, -(deriv (hazardSurvival h) t) := by apply intervalIntegral.integral_congr_ae_restrict filter_upwards [hderiv] with x hx rw [hx, neg_neg] _ = hazardSurvival h a - hazardSurvival h b := by rw [intervalIntegral.integral_neg, hS.integral_deriv_eq_sub] ring
    Causalean.Stat.RecurrentEvent.hazardSurvival_interval_integral · Causalean/Stat/RecurrentEvent/HazardDensity.lean:22
  • death_law_Ico_eq_survival_sub theorem — A recurrent-event model and an ordered subinterval inside its administrative horizon give death-time mass equal to the decrease in hazard-generated survival.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a b :
    ℝ
    ha :
    0 ≤ a
    hab :
    a ≤ b
    hb :
    b ≤ M.horizon
    M.deathLaw (Ico a b)
    = ofReal (hazardSurvival M.hazard a - hazardSurvival M.hazard b)
    Proof (Lean source)
    theorem Model.death_law_Ico_eq_survival_sub (M : Model A X) (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ M.horizon) : M.deathLaw (Ico a b) = ofReal (hazardSurvival M.hazard a - hazardSurvival M.hazard b) := by /- Use `Ico a b = Ici a \ Ici b`, probability finiteness, and the two instances of `death_survival`. Convert the finite ENNReal subtraction to `ofReal` of the real survival difference. The case `a = b` is empty. -/ letI := M.deathProb have hsub : Ici b ⊆ Ici a := Ici_subset_Ici.mpr hab have hdiff : Ico a b = Ici a \ Ici b := by ext x; simp rw [hdiff, measure_sdiff hsub measurableSet_Ici.nullMeasurableSet (measure_ne_top M.deathLaw (Ici b))] rw [M.death_survival a ⟨ha, le_trans hab hb⟩, M.death_survival b ⟨le_trans ha hab, hb⟩] exact (ENNReal.ofReal_sub _ (le_of_lt (Real.exp_pos _))).symm
    Causalean.Stat.RecurrentEvent.Model.death_law_Ico_eq_survival_sub · Causalean/Stat/RecurrentEvent/HazardDensity.lean:86
  • survival_hazard_density_Ico theorem — A recurrent-event model and an ordered subinterval inside its administrative horizon give survival-weighted hazard mass equal to the survival decrease, including empty and horizon-endpoint intervals.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a b :
    ℝ
    ha :
    0 ≤ a
    hab :
    a ≤ b
    hb :
    b ≤ M.horizon
    ((volume.restrict (Ico 0 M.horizon)).withDensity (fun t => ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞))) (Ico a b)
    = ofReal (hazardSurvival M.hazard a - hazardSurvival M.hazard b)
    Proof (Lean source)
    theorem Model.survival_hazard_density_Ico (M : Model A X) (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ M.horizon) : ((volume.restrict (Ico 0 M.horizon)).withDensity (fun t => ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞))) (Ico a b) = ofReal (hazardSurvival M.hazard a - hazardSurvival M.hazard b) := by /- Intersect nested `Ico` sets, use `withDensity_apply` and `ofReal_integral_eq_lintegral_ofReal`, and close the real integral with `hazardSurvival_interval_integral`. Establish integrability from `hazard_integrable` and bounded survival on `[0, horizon]`. -/ let f : ℝ → ℝ := fun t => hazardSurvival M.hazard t * (M.hazard t : ℝ) have hsub : Icc a b ⊆ Icc (0 : ℝ) M.horizon := Icc_subset_Icc ha hb have hG := M.hazard_integrable.absolutelyContinuousOnInterval_intervalIntegral (c := 0) (by simp [M.horizon_nonneg]) have hcont : ContinuousOn (hazardSurvival M.hazard) (Icc 0 M.horizon) := by change ContinuousOn (fun t => exp (-(∫ u in (0 : ℝ)..t, (M.hazard u : ℝ)))) _ have hc : ContinuousOn (fun t => -(∫ u in (0 : ℝ)..t, (M.hazard u : ℝ))) (Icc 0 M.horizon) := by simpa [uIcc_of_le M.horizon_nonneg] using hG.fun_neg.continuousOn simpa only [Function.comp_def] using Real.continuous_exp.continuousOn.comp hc (fun _ _ => Set.mem_univ _) have hbounds : ∀ t ∈ Icc a b, 0 ≤ hazardSurvival M.hazard t ∧ hazardSurvival M.hazard t ≤ 1 := by intro t ht have ht0 : 0 ≤ t := le_trans ha ht.1 have hnonneg : 0 ≤ ∫ u in (0 : ℝ)..t, (M.hazard u : ℝ) := intervalIntegral.integral_nonneg_of_forall ht0 (fun u => NNReal.coe_nonneg _) constructor · exact le_of_lt (Real.exp_pos _) · simpa [hazardSurvival] using Real.exp_le_one_iff.mpr (neg_nonpos.mpr hnonneg) have hh : IntervalIntegrable (fun t : ℝ => (M.hazard t : ℝ)) volume a b := M.hazard_integrable.mono_set (by rw [uIcc_of_le hab, uIcc_of_le M.horizon_nonneg] exact hsub) have hf : IntegrableOn f (Ico a b) volume := by have hfm : AEStronglyMeasurable f (volume.restrict (Ico a b)) := by apply AEStronglyMeasurable.mul · exact (hcont.mono (fun x hx => hsub ⟨hx.1, hx.2.le⟩)).aestronglyMeasurable measurableSet_Ico · exact M.measurable_hazard.coe_nnreal_real.aestronglyMeasurable have hbound : (fun t => ‖f t‖) ≤ᵐ[volume.restrict (Ico a b)] (fun t => ‖(M.hazard t : ℝ)‖) := by filter_upwards [ae_restrict_mem measurableSet_Ico] with t ht have hs := hbounds t ⟨ht.1, ht.2.le⟩ simp only [f, Real.norm_eq_abs, abs_mul, abs_of_nonneg hs.1, abs_of_nonneg (NNReal.coe_nonneg (M.hazard t))] exact mul_le_of_le_one_left (NNReal.coe_nonneg _) hs.2 exact Integrable.mono (((intervalIntegrable_iff_integrableOn_Ico_of_le hab).mp hh) : Integrable (fun t : ℝ => (M.hazard t : ℝ)) (volume.restrict (Ico a b))) hfm hbound have hmeas : Ico a b ⊆ Ico 0 M.horizon := by intro t ht exact ⟨le_trans ha ht.1, lt_of_lt_of_le ht.2 hb⟩ rw [withDensity_apply _ measurableSet_Ico] change (∫⁻ t, ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞) ∂((volume.restrict (Ico 0 M.horizon)).restrict (Ico a b))) = _ rw [Measure.restrict_restrict_of_subset hmeas] have hnn : 0 ≤ᵐ[volume.restrict (Ico a b)] f := by filter_upwards [] with t exact mul_nonneg (le_of_lt (Real.exp_pos _)) (NNReal.coe_nonneg _) have heq : ∀ t, ofReal (f t) = ofReal (hazardSurvival M.hazard t) * (M.hazard t : ℝ≥0∞) := by intro t change ofReal (hazardSurvival M.hazard t * (M.hazard t : ℝ)) = _ have hp : 0 ≤ hazardSurvival M.hazard t := by unfold hazardSurvival positivity rw [ENNReal.ofReal_mul hp] simp simp_rw [← heq] rw [← ofReal_integral_eq_lintegral_ofReal hf hnn] rw [integral_Ico_eq_integral_Ioc, ← intervalIntegral.integral_of_le hab] exact congrArg ofReal (hazardSurvival_interval_integral M.hazard M.horizon a b M.hazard_integrable ha hab hb)
    Causalean.Stat.RecurrentEvent.Model.survival_hazard_density_Ico · Causalean/Stat/RecurrentEvent/HazardDensity.lean:105
Identification 1 core · 0 supporting Equal observed stopped-history laws identify hazard and recurrence intensity almost everywhere where the common observable risk set is positive. ★ identify_densities

Identification of recurrent-event intensities

Equal observed stopped-history laws identify hazard and recurrence intensity almost everywhere where the common observable risk set is positive.

theorem identify_densities reviewed
Causalean.Stat.RecurrentEvent.Model

Two recurrent-event models, an arm, and a sub-horizon time with equal stopped-history laws, positive assignment mass in the first model, and positive censoring retention of the first model throughout that interval have equal death hazards and recurrence intensities Lebesgue-almost everywhere on the interval.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
Y :
Type u_3
shared
M :
Model A X
N :
Model A Y
a :
A
T :
ℝ
hTM :
T < M.horizon
hTN :
T < N.horizon
hobs :
M.observedLaw = N.observedLaw
haM :
0 < M.armLaw {a}
hcM :
∀ t ∈ Icc (0 : ℝ) T, 0 < M.censorLaw (Ici t)
∀ᵐ t ∂(volume.restrict (Icc (0 : ℝ) T)), M.hazard t
= N.hazard t ∧ M.intensity t = N.intensity t
Proof (Lean source)
theorem Model.identify_densities (M : Model A X) (N : Model A Y) (a : A) (T : ℝ) (hTM : T < M.horizon) (hTN : T < N.horizon) (hobs : M.observedLaw = N.observedLaw) (haM : 0 < M.armLaw {a}) (hcM : ∀ t ∈ Icc (0 : ℝ) T, 0 < M.censorLaw (Ici t)) : ∀ᵐ t ∂(volume.restrict (Icc (0 : ℝ) T)), M.hazard t = N.hazard t ∧ M.intensity t = N.intensity t := by let s : Set ℝ := Icc 0 T let wM : ℝ → ℝ≥0∞ := fun t => M.armLaw {a} * M.deathLaw (Ici t) * M.censorLaw (Ici t) let wN : ℝ → ℝ≥0∞ := fun t => N.armLaw {a} * N.deathLaw (Ici t) * N.censorLaw (Ici t) have hsM : s ⊆ Ico 0 M.horizon := by intro t ht exact ⟨ht.1, lt_of_le_of_lt ht.2 hTM⟩ have hsN : s ⊆ Ico 0 N.horizon := by intro t ht exact ⟨ht.1, lt_of_le_of_lt ht.2 hTN⟩ have hw : ∀ t ∈ s, wM t = wN t := by intro t ht calc wM t = M.riskProbability a t := (M.risk_factorization a t ⟨ht.1, le_trans ht.2 hTM.le⟩).symm _ = N.riskProbability a t := by simp [Model.riskProbability, hobs] _ = wN t := N.risk_factorization a t ⟨ht.1, le_trans ht.2 hTN.le⟩ have hrisk : (M.riskSetMeasure a).restrict s = (N.riskSetMeasure a).restrict s := by change ((volume.restrict (Ico 0 M.horizon)).withDensity wM).restrict s = ((volume.restrict (Ico 0 N.horizon)).withDensity wN).restrict s rw [restrict_withDensity measurableSet_Icc, restrict_withDensity measurableSet_Icc, Measure.restrict_restrict_of_subset hsM, Measure.restrict_restrict_of_subset hsN] exact withDensity_congr_ae ((ae_restrict_mem measurableSet_Icc).mono fun t ht => hw t ht) have hdeath : M.deathEventMeasure a = N.deathEventMeasure a := by simp only [Model.deathEventMeasure, hobs] have hrec : M.recurrenceEventMeasure a = N.recurrenceEventMeasure a := by simp only [Model.recurrenceEventMeasure, hobs] have htail (ν : Measure ℝ) : Measurable (fun t : ℝ => ν (Ici t)) := Antitone.measurable (fun x y hxy => measure_mono (Ici_subset_Ici.mpr hxy)) have hmeas : Measurable wM := by dsimp [wM] exact (measurable_const.mul (htail M.deathLaw)).mul (htail M.censorLaw) letI := M.armProb letI := M.deathProb letI := M.censorProb have hfinite : ∀ t, wM t ≠ ⊤ := by intro t dsimp [wM] exact ENNReal.mul_ne_top (ENNReal.mul_ne_top (measure_ne_top M.armLaw {a}) (measure_ne_top M.deathLaw (Ici t))) (measure_ne_top M.censorLaw (Ici t)) haveI : SigmaFinite ((M.riskSetMeasure a).restrict s) := by have heq : (M.riskSetMeasure a).restrict s = (volume.restrict s).withDensity wM := by change ((volume.restrict (Ico 0 M.horizon)).withDensity wM).restrict s = _ rw [restrict_withDensity measurableSet_Icc, Measure.restrict_restrict_of_subset hsM] rw [heq] exact SigmaFinite.withDensity_of_ne_top (Filter.Eventually.of_forall hfinite) have hmh : (fun t => (M.hazard t : ℝ≥0∞)) =ᵐ[(M.riskSetMeasure a).restrict s] (fun t => (N.hazard t : ℝ≥0∞)) := by apply (withDensity_eq_iff_of_sigmaFinite M.measurable_hazard.coe_nnreal_ennreal.aemeasurable N.measurable_hazard.coe_nnreal_ennreal.aemeasurable).mp calc _ = (M.deathEventMeasure a).restrict s := by rw [← restrict_withDensity measurableSet_Icc, ← M.death_event_density] _ = (N.deathEventMeasure a).restrict s := by rw [hdeath] _ = _ := by rw [N.death_event_density, restrict_withDensity measurableSet_Icc, ← hrisk] have hmi : (fun t => (M.intensity t : ℝ≥0∞)) =ᵐ[(M.riskSetMeasure a).restrict s] (fun t => (N.intensity t : ℝ≥0∞)) := by apply (withDensity_eq_iff_of_sigmaFinite M.measurable_intensity.coe_nnreal_ennreal.aemeasurable N.measurable_intensity.coe_nnreal_ennreal.aemeasurable).mp calc _ = (M.recurrenceEventMeasure a).restrict s := by rw [← restrict_withDensity measurableSet_Icc, ← M.recurrence_event_density] _ = (N.recurrenceEventMeasure a).restrict s := by rw [hrec] _ = _ := by rw [N.recurrence_event_density, restrict_withDensity measurableSet_Icc, ← hrisk] have hpos : ∀ t ∈ s, wM t ≠ 0 := by intro t ht have hd : 0 < M.deathLaw (Ici t) := by rw [M.death_survival t ⟨ht.1, le_trans ht.2 hTM.le⟩] exact ENNReal.ofReal_pos.mpr (Real.exp_pos _) exact (ENNReal.mul_pos (ne_of_gt (ENNReal.mul_pos (ne_of_gt haM) (ne_of_gt hd))) (ne_of_gt (hcM t ht))).ne' have heq : (M.riskSetMeasure a).restrict s = (volume.restrict s).withDensity wM := by change ((volume.restrict (Ico 0 M.horizon)).withDensity wM).restrict s = _ rw [restrict_withDensity measurableSet_Icc, Measure.restrict_restrict_of_subset hsM] have hmh' := (ae_withDensity_iff hmeas).mp (heq ▸ hmh) have hmi' := (ae_withDensity_iff hmeas).mp (heq ▸ hmi) filter_upwards [hmh', hmi', ae_restrict_mem measurableSet_Icc] with t hh hi ht exact ⟨by exact_mod_cast (hh (hpos t ht)), by exact_mod_cast (hi (hpos t ht))⟩
Causalean.Stat.RecurrentEvent.Model.identify_densities · Causalean/Stat/RecurrentEvent/Identification.lean:22 · uses Model , observedLaw
Laws 1 core · 2 supporting In the finite-horizon Poisson recurrent-event model with independent treatment assignment, death and censoring, the observable death events and recurrence events of an arm have, relative to the armwise risk-set measure ( ★ death_stopped_mean_zero_horizon

Recurrent events with a terminal event: observable laws on a finite horizon

In the finite-horizon Poisson recurrent-event model with independent treatment assignment, death and censoring, the observable death events and recurrence events of an arm have, relative to the armwise risk-set measure (assignment probability × death survival × censoring survival, on times before the horizon), densities equal to the death hazard and the recurrence intensity. The mean number of recurrences before independent death equals the integral over the horizon of death survival times recurrence intensity, and two models with the same law of the observed stopped history have the same hazard and intensity almost everywhere where the risk set is positive. Those results are proved in the imported modules; this file adds their degenerate case of a zero horizon.

Main results

* Model.death_event_zero_horizon, Model.recurrence_event_zero_horizon — with horizon zero the observable death-event and recurrence-event measures vanish. * Model.death_stopped_mean_zero_horizon — with horizon zero the death-stopped mean recurrence count is zero.

Imported: Model.death_event_density, Model.recurrence_event_density, Model.death_stopped_poisson_mean (DeathStoppedMean) and Model.identify_densities (Identification).

theorem death_stopped_mean_zero_horizon reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model with a zero administrative horizon has an independently death-stopped Poisson recurrence mean of zero.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
hH :
M.horizon = 0
M.deathStoppedCountMean = 0
Proof (Lean source)
theorem Model.death_stopped_mean_zero_horizon (M : Model A X) (hH : M.horizon = 0) : M.deathStoppedCountMean = 0 := by rw [M.death_stopped_poisson_mean] simp [hH]
Causalean.Stat.RecurrentEvent.Model.death_stopped_mean_zero_horizon · Causalean/Stat/RecurrentEvent/Laws.lean:56 · uses Model , deathStoppedCountMean
2 supporting declarations (lemmas, instances)
  • death_event_zero_horizon theorem — A recurrent-event model, an arm, and a zero administrative horizon have no observable death event before exit.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a :
    A
    hH :
    M.horizon = 0
    M.deathEventMeasure a = 0
    Proof (Lean source)
    theorem Model.death_event_zero_horizon (M : Model A X) (a : A) (hH : M.horizon = 0) : M.deathEventMeasure a = 0 := by rw [M.death_event_density] simp [Model.riskSetMeasure, hH]
    Causalean.Stat.RecurrentEvent.Model.death_event_zero_horizon · Causalean/Stat/RecurrentEvent/Laws.lean:40
  • recurrence_event_zero_horizon theorem — A recurrent-event model, an arm, and a zero administrative horizon have no observable recurrence event before exit.
    A :
    Type u_1
    shared
    X :
    Type u_2
    shared
    M :
    Model A X
    a :
    A
    hH :
    M.horizon = 0
    M.recurrenceEventMeasure a = 0
    Proof (Lean source)
    theorem Model.recurrence_event_zero_horizon (M : Model A X) (a : A) (hH : M.horizon = 0) : M.recurrenceEventMeasure a = 0 := by rw [M.recurrence_event_density] simp [Model.riskSetMeasure, hH]
    Causalean.Stat.RecurrentEvent.Model.recurrence_event_zero_horizon · Causalean/Stat/RecurrentEvent/Laws.lean:48
Observation 2 core · 0 supporting The stopped observation of a finite recurrence sample is a measurable function into an arm, exit, death flag, and countable time sequence. ★ measurable_observe

Measurability of finite stopped histories

The stopped observation of a finite recurrence sample is a measurable function into an arm, exit, death flag, and countable time sequence.

theorem measurable_observe reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model has a measurable finite-horizon stopped-observation map.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
Measurable M.observe
Proof (Lean source)
theorem Model.measurable_observe (M : Model A X) : Measurable M.observe := by have hstop : Measurable M.stopTime := by unfold Model.stopTime fun_prop have hdeath : Measurable (fun ω : Outcome A X => decide (ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon)) := by change Measurable (fun ω : Outcome A X => if ω.2.2.1 ≤ ω.2.2.2 ∧ ω.2.2.1 < M.horizon then true else false) apply Measurable.ite ((measurableSet_le (show Measurable (fun ω : Outcome A X => ω.2.2.1) by fun_prop) (show Measurable (fun ω : Outcome A X => ω.2.2.2) by fun_prop)).inter (measurableSet_lt (show Measurable (fun ω : Outcome A X => ω.2.2.1) by fun_prop) measurable_const)) all_goals exact measurable_const have hsample (n : ℕ) : Measurable (fun s : FiniteSample X => if h : n < s.1 then M.time (s.2 ⟨n, h⟩) else M.horizon + 1) := by intro t ht rw [MeasurableSpace.measurableSet_iInf] intro m change MeasurableSet ((fun x : Fin m → X => if h : n < m then M.time (x ⟨n, h⟩) else M.horizon + 1) ⁻¹' t) by_cases h : n < m · simp only [dif_pos h] exact ht.preimage (M.measurable_time.comp (measurable_pi_apply (⟨n, h⟩ : Fin m))) · simp only [dif_neg h] exact measurable_const ht have hcoord (n : ℕ) : Measurable (fun ω : Outcome A X => if h : n < ω.2.1.1 then if M.time (ω.2.1.2 ⟨n, h⟩) < M.stopTime ω then M.time (ω.2.1.2 ⟨n, h⟩) else M.horizon + 1 else M.horizon + 1) := by let f : Outcome A X → ℝ := fun ω => if h : n < ω.2.1.1 then M.time (ω.2.1.2 ⟨n, h⟩) else M.horizon + 1 have hf : Measurable f := (hsample n).comp (measurable_fst.comp measurable_snd) have hc : Measurable (fun ω : Outcome A X => ω.2.1.1) := Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.measurable_finiteSample_count.comp (measurable_fst.comp measurable_snd) have heq : (fun ω : Outcome A X => if h : n < ω.2.1.1 then if M.time (ω.2.1.2 ⟨n, h⟩) < M.stopTime ω then M.time (ω.2.1.2 ⟨n, h⟩) else M.horizon + 1 else M.horizon + 1) = (fun ω => if n < ω.2.1.1 ∧ f ω < M.stopTime ω then f ω else M.horizon + 1) := by funext ω by_cases h : n < ω.2.1.1 <;> simp [f, h] rw [heq] exact Measurable.ite ((measurableSet_lt measurable_const hc).inter (measurableSet_lt hf hstop)) hf measurable_const unfold Model.observe exact measurable_fst.prodMk (hstop.prodMk (hdeath.prodMk (measurable_pi_lambda _ hcoord)))
Causalean.Stat.RecurrentEvent.Model.measurable_observe · Causalean/Stat/RecurrentEvent/Observation.lean:21 · uses FiniteSample , Model , observe , Outcome
def historyCountingKernel reviewed
Causalean.Stat.RecurrentEvent

An arm space determines the stopped-history counting kernel, which places one unit of mass at every retained recurrence time and preserves ties with their multiplicities.

Definition (Lean source)
A :
historyCountingKernel A :
Kernel (A × (ℝ × (Bool × (ℕ → ℝ)))) ℝ
clause 1
toFun y := Measure.sum (fun n : ℕ => if y.2.2.2 n < y.2.1 then Measure.dirac (y.2.2.2 n) else 0)
clause 2
measurable' := by apply Measure.measurable_of_measurable_coe intro s hs change Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => (Measure.sum (fun n : ℕ => if y.2.2.2 n < y.2.1 then Measure.dirac (y.2.2.2 n) else 0)) s) simp_rw [Measure.sum_apply _ hs] apply Measurable.tsum intro n have ht : Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => y.2.2.2 n) := by fun_prop have he : Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => y.2.1) := by fun_prop have hd : Measurable (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => (Measure.dirac (y.2.2.2 n)) s) := by simpa [Measure.dirac_apply, indicator] using (Measurable.ite (hs.preimage ht) (measurable_const : Measurable (fun _ : A × (ℝ × (Bool × (ℕ → ℝ))) => (1 : ℝ≥0∞))) measurable_const) have heq : (fun y : A × (ℝ × (Bool × (ℕ → ℝ))) => (if y.2.2.2 n < y.2.1 then Measure.dirac (y.2.2.2 n) else 0) s)
= (fun y => if y.2.2.2 n < y.2.1 then (Measure.dirac (y.2.2.2 n)) s else (0 : ℝ≥0∞)) := by funext y split <;> simp_all rw [heq] exact Measurable.ite (measurableSet_lt ht he) hd measurable_const
Causalean.Stat.RecurrentEvent.historyCountingKernel · Causalean/Stat/RecurrentEvent/Observation.lean:76
Poisson­Campbell 1 core · 2 supporting The expectation of a nonnegative sum over a finite Poisson sample is the integral against its primitive intensity measure. ★ finitePoissonSample_lintegral_sum

Finite Poisson sum formula

The expectation of a nonnegative sum over a finite Poisson sample is the integral against its primitive intensity measure. This is the independent count-and-stream calculation used by the stopped-event identities.

theorem finitePoissonSample_lintegral_sum reviewed
Causalean.Stat.RecurrentEvent

An observation law, a nonnegative Poisson rate, and a measurable nonnegative score give an expected finite-sample sum equal to its integral against the rate-scaled observation law.

Formal statement
X :
Type u_1
shared
rate :
ℝ≥0
f :
X → ℝ≥0∞
hf :
(∫⁻ s, ∑ i : Fin s.1, f (s.2 i) ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw P rate)
= ∫⁻ x, f x ∂((rate : ℝ≥0∞) • P)
Proof (Lean source)
theorem finitePoissonSample_lintegral_sum (P : Measure X) [IsProbabilityMeasure P] (rate : ℝ≥0) (f : X → ℝ≥0∞) (hf : Measurable f) : (∫⁻ s, ∑ i : Fin s.1, f (s.2 i) ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw P rate) = ∫⁻ x, f x ∂((rate : ℝ≥0∞) • P) := by /- Partition by the Poisson count using the finite-sample count-fibre theorem; exchange the finite point sum with the iid product integral; finish with the first moment of the scalar Poisson count. -/ classical let μ := Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw P rate let g : FiniteSample X → ℝ≥0∞ := fun s => ∑ i : Fin s.1, f (s.2 i) have hg : Measurable g := by intro t ht change @MeasurableSet _ (⨅ n, (inferInstance : MeasurableSpace (Fin n → X)).map (Sigma.mk n)) (g ⁻¹' t) rw [MeasurableSpace.measurableSet_iInf] intro n change MeasurableSet ((fun x : Fin n → X => ∑ i, f (x i)) ⁻¹' t) exact (Finset.measurable_sum _ (fun i _ => hf.comp (measurable_pi_apply i))) ht have hcount (n : ℕ) : (∫⁻ s, g s ∂μ.restrict (count ⁻¹' ({n} : Set ℕ))) = (poissonMeasure rate) {n} * (n : ℝ≥0∞) * (∫⁻ x, f x ∂P) := by rw [finitePoissonSampleLaw_restrict_count_eq] rw [lintegral_smul_measure, lintegral_map hg (measurable_fixedSizeEmbed n)] change (poissonMeasure rate) {n} * (∫⁻ x : Fin n → X, ∑ i : Fin n, f (x i) ∂Measure.pi (fun _ => P)) = _ rw [lintegral_finsetSum] swap · intro i _ exact hf.comp (measurable_pi_apply i) have hi (i : Fin n) : (∫⁻ x : Fin n → X, f (x i) ∂Measure.pi (fun _ => P)) = ∫⁻ x, f x ∂P := by exact (measurePreserving_eval (μ := fun _ : Fin n => P) i).lintegral_comp hf simp only [hi, Finset.sum_const, Finset.card_fin, nsmul_eq_mul] simp [mul_assoc] have hpart : (∫⁻ s, g s ∂μ) = ∑' n : ℕ, ∫⁻ s, g s ∂μ.restrict (count ⁻¹' ({n} : Set ℕ)) := by let S : ℕ → Set (FiniteSample X) := fun n => count ⁻¹' ({n} : Set ℕ) have hU : (⋃ n, S n) = univ := by ext s simp [S] rw [← lintegral_iUnion (μ := μ) (s := S)] · simp [hU, S] · intro n exact measurable_finiteSample_count (X := X) (MeasurableSet.singleton n) · intro i j hij exact Set.disjoint_left.mpr (by intro s hi hj exact hij (by simpa [S] using hi.symm.trans hj)) rw [hpart] simp_rw [hcount] rw [ENNReal.tsum_mul_right] have hm : (∫⁻ n : ℕ, (n : ℝ≥0∞) ∂poissonMeasure rate) = (rate : ℝ≥0∞) := by have h := poisson_natCast_first_moment rate have hi := (poisson_natCast_memLp_two rate).integrable (by norm_num) have hr := ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall (fun n : ℕ => Nat.cast_nonneg n)) rw [h] at hr simpa [ENNReal.ofReal_natCast, ENNReal.ofReal_coe_nnreal] using hr.symm have hsum : (∑' n : ℕ, (poissonMeasure rate) {n} * (n : ℝ≥0∞)) = (rate : ℝ≥0∞) := by rw [lintegral_countable'] at hm simpa only [mul_comm] using hm rw [hsum, lintegral_smul_measure, smul_eq_mul]
Causalean.Stat.RecurrentEvent.finitePoissonSample_lintegral_sum · Causalean/Stat/RecurrentEvent/PoissonCampbell.lean:26 · uses FiniteSample , finitePoissonSampleLaw
2 supporting declarations (lemmas, instances)
  • poisson_time_lintegral theorem — A recurrent-event model and a measurable nonnegative time score give a Poisson event-time sum whose mean is the integral against the model's time intensity.
    X :
    Type u_1
    shared
    A :
    Type u_2
    shared
    M :
    Model A X
    f :
    ℝ → ℝ≥0∞
    hf :
    (letI := M.pointProb ∫⁻ s, ∑ i : Fin s.1, f (M.time (s.2 i)) ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate)
    = ∫⁻ t in Ico (0 : ℝ) M.horizon, f t * (M.intensity t : ℝ≥0∞) ∂volume
    Proof (Lean source)
    theorem Model.poisson_time_lintegral (M : Model A X) (f : ℝ → ℝ≥0∞) (hf : Measurable f) : (letI := M.pointProb ∫⁻ s, ∑ i : Fin s.1, f (M.time (s.2 i)) ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate) = ∫⁻ t in Ico (0 : ℝ) M.horizon, f t * (M.intensity t : ℝ≥0∞) ∂volume := by letI := M.pointProb calc (∫⁻ s, ∑ i : Fin s.1, f (M.time (s.2 i)) ∂finitePoissonSampleLaw M.pointLaw M.poissonRate) = ∫⁻ x, (f ∘ M.time) x ∂((M.poissonRate : ℝ≥0∞) • M.pointLaw) := finitePoissonSample_lintegral_sum M.pointLaw M.poissonRate (f ∘ M.time) (hf.comp M.measurable_time) _ = ∫⁻ t, f t ∂Measure.map M.time ((M.poissonRate : ℝ≥0∞) • M.pointLaw) := (lintegral_map hf M.measurable_time).symm _ = ∫⁻ t in Ico (0 : ℝ) M.horizon, f t * (M.intensity t : ℝ≥0∞) ∂volume := by rw [M.primitive_intensity, lintegral_withDensity_eq_lintegral_mul _ M.measurable_intensity.coe_nnreal_ennreal hf] congr 1 funext t exact mul_comm _ _
    Causalean.Stat.RecurrentEvent.Model.poisson_time_lintegral · Causalean/Stat/RecurrentEvent/PoissonCampbell.lean:111
  • poisson_count_before_death theorem — A recurrent-event model and a fixed death time give a mean primitive recurrence count equal to intensity integrated before that death time and the fixed horizon.
    X :
    Type u_1
    shared
    A :
    Type u_2
    shared
    M :
    Model A X
    d :
    ℝ
    (letI := M.pointProb ∫⁻ s, ∑ i : Fin s.1, if M.time (s.2 i) < d ∧ M.time (s.2 i) < M.horizon then (1 : ℝ≥0∞) else 0 ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate)
    = ∫⁻ t in Ico (0 : ℝ) M.horizon, if t < d then (M.intensity t : ℝ≥0∞) else 0 ∂volume
    Proof (Lean source)
    theorem Model.poisson_count_before_death (M : Model A X) (d : ℝ) : (letI := M.pointProb ∫⁻ s, ∑ i : Fin s.1, if M.time (s.2 i) < d ∧ M.time (s.2 i) < M.horizon then (1 : ℝ≥0∞) else 0 ∂Causalean.Mathlib.Probability.FiniteMarkedPoissonPartition.finitePoissonSampleLaw M.pointLaw M.poissonRate) = ∫⁻ t in Ico (0 : ℝ) M.horizon, if t < d then (M.intensity t : ℝ≥0∞) else 0 ∂volume := by letI := M.pointProb /- Apply `M.poisson_time_lintegral` to the measurable indicator `fun t => if t < d ∧ t < M.horizon then 1 else 0`. On `Ico 0 M.horizon`, the second inequality is automatic; simplify the indicator and use `lintegral_congr` for the resulting pointwise equality. Keep the strict death inequality: an atom of the independent death law is removed only after averaging, not in this fixed-death identity. -/ have hf : Measurable (fun t : ℝ => if t < d ∧ t < M.horizon then (1 : ℝ≥0∞) else 0) := by exact Measurable.ite (measurableSet_Iio.inter measurableSet_Iio) measurable_const measurable_const calc (∫⁻ s, ∑ i : Fin s.1, if M.time (s.2 i) < d ∧ M.time (s.2 i) < M.horizon then (1 : ℝ≥0∞) else 0 ∂finitePoissonSampleLaw M.pointLaw M.poissonRate) = ∫⁻ t in Ico (0 : ℝ) M.horizon, (if t < d ∧ t < M.horizon then (1 : ℝ≥0∞) else 0) * (M.intensity t : ℝ≥0∞) ∂volume := M.poisson_time_lintegral _ hf _ = ∫⁻ t in Ico (0 : ℝ) M.horizon, if t < d then (M.intensity t : ℝ≥0∞) else 0 ∂volume := by apply setLIntegral_congr_fun measurableSet_Ico intro t ht have hth : t < M.horizon := ht.2 by_cases htd : t < d <;> simp [htd, hth]
    Causalean.Stat.RecurrentEvent.Model.poisson_count_before_death · Causalean/Stat/RecurrentEvent/PoissonCampbell.lean:142
Recurrence­Density 1 core · 0 supporting A finite Poisson recurrence sample stopped at independent death and censor times has observable event intensity relative to the armwise risk set. ★ recurrence_event_density

Observable recurrence-event intensity density

A finite Poisson recurrence sample stopped at independent death and censor times has observable event intensity relative to the armwise risk set.

theorem recurrence_event_density reviewed
Causalean.Stat.RecurrentEvent.Model

A recurrent-event model and an arm have an observable recurrence-event measure with primitive Poisson intensity as density relative to the armwise risk-set measure.

Formal statement
A :
Type u_1
shared
X :
Type u_2
shared
M :
Model A X
a :
A
M.recurrenceEventMeasure a
= (M.riskSetMeasure a).withDensity (fun t => (M.intensity t : ℝ≥0∞))
Proof (Lean source)
theorem Model.recurrence_event_density (M : Model A X) (a : A) : M.recurrenceEventMeasure a = (M.riskSetMeasure a).withDensity (fun t => (M.intensity t : ℝ≥0∞)) := by letI := M.deathProb letI := M.censorProb let μ : Measure ℝ := volume.restrict (Ico 0 M.horizon) let w : ℝ → ℝ≥0∞ := fun t => M.armLaw {a} * M.deathLaw (Ici t) * M.censorLaw (Ici t) let h : ℝ → ℝ≥0∞ := fun t => (M.intensity t : ℝ≥0∞) have hdeath : Measurable (fun t : ℝ => M.deathLaw (Ici t)) := Antitone.measurable (fun _ _ hxy => measure_mono (Ici_subset_Ici.mpr hxy)) have hcensor : Measurable (fun t : ℝ => M.censorLaw (Ici t)) := Antitone.measurable (fun _ _ hxy => measure_mono (Ici_subset_Ici.mpr hxy)) have hw : Measurable w := (measurable_const.mul hdeath).mul hcensor have hh : Measurable h := M.measurable_intensity.coe_nnreal_ennreal apply Measure.ext intro s hs calc M.recurrenceEventMeasure a s = ∫⁻ t in s ∩ Ico (0 : ℝ) M.horizon, M.armLaw {a} * M.deathLaw (Ioi t) * M.censorLaw (Ioi t) * h t ∂volume := by rw [M.recurrence_event_measure_primitive a s hs, M.recurrence_primitive_strict_tail a s hs] _ = ∫⁻ t in s ∩ Ico (0 : ℝ) M.horizon, w t * h t ∂volume := by apply lintegral_congr_ae filter_upwards [ae_restrict_of_ae (ae_measure_Ioi_eq_Ici M.deathLaw), ae_restrict_of_ae (ae_measure_Ioi_eq_Ici M.censorLaw)] with t hd hc simp only [w, hd, hc] _ = (μ.withDensity (w * h)) s := by rw [withDensity_apply _ hs] simp only [μ] rw [Measure.restrict_restrict hs] congr 1 _ = ((μ.withDensity w).withDensity h) s := by rw [withDensity_mul₀ hw.aemeasurable hh.aemeasurable] _ = ((M.riskSetMeasure a).withDensity h) s := by rfl
Causalean.Stat.RecurrentEvent.Model.recurrence_event_density · Causalean/Stat/RecurrentEvent/RecurrenceDensity.lean:23 · uses Model , recurrenceEventMeasure , riskSetMeasure
Tail­Retention 1 core · 0 supporting A finite real-time law has only countably many atoms. ★ ae_measure_Ioi_eq_Ici

Strict and weak retention for finite exit laws

A finite real-time law has only countably many atoms. Therefore its strict and weak tail probabilities agree at Lebesgue-almost every time. This is the endpoint conversion used for strict stopping of recurrence points.

theorem ae_measure_Ioi_eq_Ici reviewed
Causalean.Stat.RecurrentEvent

A finite exit-time law has equal strict and weak retention probabilities at Lebesgue-almost every time, including when the law has atoms.

Formal statement
∀ᵐ t ∂(volume : Measure ℝ), ν (Ioi t) = ν (Ici t)
Proof (Lean source)
theorem ae_measure_Ioi_eq_Ici (ν : Measure ℝ) [IsFiniteMeasure ν] : ∀ᵐ t ∂(volume : Measure ℝ), ν (Ioi t) = ν (Ici t) := by have hcount : {t : ℝ | 0 < ν {t}}.Countable := by simpa only [id_eq, ofPred_eq_eq_singleton] using (Measure.countable_meas_level_set_pos (μ := ν) (g := id) measurable_id) filter_upwards [hcount.ae_notMem (volume : Measure ℝ)] with t ht have hz : ν {t} = 0 := nonpos_iff_eq_zero.mp (not_lt.mp ht) have hdecomp : Ici t = {t} ∪ Ioi t := by simpa only [Icc_self] using (Icc_union_Ioi_eq_Ici (a := t) (b := t) le_rfl).symm have hdisj : Disjoint ({t} : Set ℝ) (Ioi t) := by simp calc ν (Ioi t) = ν {t} + ν (Ioi t) := by simp [hz] _ = ν ({t} ∪ Ioi t) := (measure_union hdisj measurableSet_Ioi).symm _ = ν (Ici t) := by rw [← hdecomp]
Causalean.Stat.RecurrentEvent.ae_measure_Ioi_eq_Ici · Causalean/Stat/RecurrentEvent/TailRetention.lean:20