Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ARCHITECTURE.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ All notable changes to TEPP are documented here. The format follows Keep a Chang

## [Unreleased]

- `psychometric_core` recovers the 2017-era commented-out `asymTOTALVAR` after `addedTIPREDVAR` as `-q / (2 a) + trait / a² + (B / a)² v` on current main. 2017-era ctsem `summary.ctsemFit.R` (cran/ctsem 2.5.0) comments `asymTOTALVAR <- asymDIFFUSION + asymTRAITVAR` with `asymTRAITVAR <- solve(DRIFT) %*% TRAITVAR %*% t(solve(DRIFT))`, then later comments `asymTOTALVAR <- asymTOTALVAR + addedTIPREDVAR` immediately after forming `addedTIPREDVAR`. Driver, Oud, and Voelkle (2017, Eq. 1, p. 4; Eq. 4, p. 5; Table 2, p. 12; §4.3, p. 9; §7.2, pp. 20–21; JSS PDF re-opened 2026-08-31T04:40Z from https://www.jstatsoft.org/index.php/jss/article/download/v077i05/1104) write `dη = (Aη + ξ + Bz + Mx) dt + G dW`. Form the two-term total first (`1 / a`, then square, then multiply by `trait`, then add `asymDIFFUSION`). Then include `addedTIPREDVAR` (unit asymptotic effect, then square, then multiply by `v`). Then add. This crate does not currently export `recover_asymptotic_total_variance` or `recover_asymptotic_trait_variance`; form those terms inline. Table 2/3 do not name `asymTOTALVAR`. A zero trait, a zero diffusion, and a zero TI extra is exactly zero even if `a ≥ 0`. `a ≥ 0` with a nonzero contribution fails closed. A zero TI extra keeps the two-term total. A zero trait and a zero diffusion keep `addedTIPREDVAR`. `p + trait / a²` is the two-term commented total and is not this map when `addedTIPREDVAR ≠ 0`. Stationary `T0VAR` `trait + p + (B / a)² v` keeps `TRAITVAR` in process units and is not this map. `(B / a)² v` is `addedTIPREDVAR` and equals this total when `q = 0` and `trait = 0` and remains a distinct named quantity. This slice does not duplicate queued `#340` two-term `asymTOTALVAR`. Meredith (1993) remains unread (web search 2026-08-31T04:40Z: Springer/Cambridge Core paywalled; Unpaywall historically `is_oa: false`; Springer `content/pdf` is an HTML stub). Mislevy (1991, *Psychometrika, 56*, 177–196) remains unread on the same terms (DOI `10.1007/bf02294457`). Still not a Kalman filter, not a matrix `expm`, not ESEM estimation, not DSEM, and not ctsem estimation.
- `event_core` adds bounded Allen interval-consistency classification, atomic path-consistency closure, contradiction/resource refusals, and an explicit dependency-error fallback without claiming unrestricted global satisfiability.

- `psychometric_core` recovers the Driver, Oud, and Voelkle (2017, Table 2, p. 12 `MANIFESTTRAITVAR`; §7.1, p. 19; p. 16 `MANIFESTTRAITVARstd`; footnote 4; 2017-era ctsem `summary.ctsemFit.R`; JSS PDF re-opened 2026-08-27T14:20Z from https://www.jstatsoft.org/index.php/jss/article/download/v077i05/1104) scalar standardised manifest-trait variance on current main after `0ce16e8` dropped the pre-consolidation code while research notes already named the map (register items 83–84). Table 2 names `MANIFESTTRAITVAR` `Ψ_τ` the additional time-invariant variance-covariance on the measurement level and sets it `NULL` when there is no manifest trait. Equation 5 writes `Γ ~ N(τ, Ψ)` and names that covariance the manifest traits. Section 7.1 names manifest traits stable individual differences in indicator levels, distinct from process-level `TRAITVAR` `φ_ξ`. Page 16 prints standardised matrices with the suffix `std` when appropriate. The printed example on p. 16 is `discreteDRIFTstd`, not `MANIFESTTRAITVARstd`. Footnote 4 standardises using only the relevant variance, not the total. The relevant variance for that named indicator-level correlation is `MANIFESTTRAITVAR`, not process-level `TRAITVAR` and not residual `MANIFESTVAR` `θ`. The 2017-era source forms `MANIFESTTRAITVARstd` only when `MANIFESTTRAITVAR != 0`, as `solve(sqrt(diag(MANIFESTTRAITVAR) + ridging)) %&% MANIFESTTRAITVAR` when `verbose = TRUE`. OpenMx `%&%` is `t(A) %*% B %*% A`. Unlike `TRAITVARstd`, that formation adds `diag(c(ridging), n.manifest)`. The default `ridging = FALSE` adds 0, not `0.0001`; that ridge is a numerical hack and is not this exact map. The scalar correlation is `ψ / ψ = 1` after strictly positive `MANIFESTTRAITVAR`. Form strictly positive `ψ` first, then `1 / √ψ`, then `(1 / √ψ) ψ (1 / √ψ)`. Unstandardised `MANIFESTTRAITVAR` is defined for a zero trait; standardised `MANIFESTTRAITVAR` is not. Zero `MANIFESTTRAITVAR` skips forming `MANIFESTTRAITVARstd` in the 2017-era source and fails closed here. Indicator-level trait variance is an event-time structural quantity, so a non-event clock fails closed. `MANIFESTTRAITVAR` does not require stable `a < 0`. Distinct positive `ψ` recover the same 1. `trait / trait = 1` is `TRAITVARstd` and recovers the same number and remains a distinct named quantity. `θ` is `MANIFESTVAR` and is measurement error, not this correlation. Meredith (1993) remains unread (web search 2026-08-27T14:20Z: Springer/Cambridge Core paywalled; Unpaywall historically `is_oa: false`; Springer `content/pdf` is an HTML stub). Mislevy (1991, *Psychometrika, 56*, 177–196) remains unread on the same terms (DOI `10.1007/bf02294457`). Still not a Kalman filter, not a matrix `expm`, not ESEM estimation, not DSEM, and not ctsem estimation.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions crates/psychometric_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,26 @@ pub enum PsychometricError {
/// `MANIFESTVARstd`. `λ² Var(η) + θ` is `Var(y)`, not the
/// correlation form of `Θ`.
ObservedVarianceIsNotStandardisedManifestVariance,
/// 2017-era commented-out `asymTOTALVAR` after `addedTIPREDVAR`
/// was requested for a non-stable drift. The three-term map
/// `-q / (2 a) + trait / a² + (B / a)² v` requires `a < 0`
/// whenever a contribution is nonzero.
AsymptoticTotalVarianceAfterAddedPredictorRequiresStableDrift,
/// 2017-era two-term `asymTOTALVAR` was treated as the later
/// commented three-term total. `p + trait / a²` omits
/// `addedTIPREDVAR`. Equal numbers when `B = 0` or `v = 0`
/// remain distinct named quantities.
TwoTermAsymptoticTotalVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
/// Driver §4.3 / p. 16 stationary `T0VAR` was treated as 2017-era
/// `asymTOTALVAR` after `addedTIPREDVAR`. `trait + p + (B / a)² v`
/// keeps `TRAITVAR` in process units; the commented total uses
/// `solve(DRIFT)` and is `p + trait / a² + (B / a)² v`.
StationaryInitialLatentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
/// Driver §7.2 `addedTIPREDVAR` was treated as 2017-era
/// `asymTOTALVAR` after `addedTIPREDVAR`. `(B / a)² v` is the
/// later addend, not the three-term total that also includes
/// `asymDIFFUSION` and `asymTRAITVAR`.
AsymptoticTimeIndependentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
}

impl fmt::Display for PsychometricError {
Expand Down Expand Up @@ -1235,6 +1255,18 @@ impl fmt::Display for PsychometricError {
Self::ObservedVarianceIsNotStandardisedManifestVariance => {
"observed-indicator variance is not standardised measurement-error variance"
}
Self::AsymptoticTotalVarianceAfterAddedPredictorRequiresStableDrift => {
"asymptotic total variance after added time-independent predictor requires a stable negative drift"
}
Self::TwoTermAsymptoticTotalVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor => {
"two-term asymptotic total variance is not asymptotic total variance after added time-independent predictor"
}
Self::StationaryInitialLatentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor => {
"stationary initial latent variance is not asymptotic total variance after added time-independent predictor"
}
Self::AsymptoticTimeIndependentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor => {
"asymptotic time-independent predictor variance is not asymptotic total variance after added time-independent predictor"
}
};
formatter.write_str(message)
}
Expand Down Expand Up @@ -2073,4 +2105,28 @@ mod tests {
"measurement error is not standardised manifest-trait variance"
);
}

#[test]
fn asymptotic_total_variance_after_added_predictor_boundary_messages_are_stable() {
assert_eq!(
PsychometricError::AsymptoticTotalVarianceAfterAddedPredictorRequiresStableDrift
.to_string(),
"asymptotic total variance after added time-independent predictor requires a stable negative drift"
);
assert_eq!(
PsychometricError::TwoTermAsymptoticTotalVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor
.to_string(),
"two-term asymptotic total variance is not asymptotic total variance after added time-independent predictor"
);
assert_eq!(
PsychometricError::StationaryInitialLatentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor
.to_string(),
"stationary initial latent variance is not asymptotic total variance after added time-independent predictor"
);
assert_eq!(
PsychometricError::AsymptoticTimeIndependentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor
.to_string(),
"asymptotic time-independent predictor variance is not asymptotic total variance after added time-independent predictor"
);
}
}
186 changes: 185 additions & 1 deletion crates/psychometric_core/src/event_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@
//! mean when `u ≠ t0`; `e^{a(t−u)} m x` is a Dirac on the original
//! process, not this `DRIFT` drive). The JSS article
//! has no numbered §2.2 (2.1 is Continuous time and SEM; §3 follows).
//! The difference quotient `(x(t+Δt) − x(t)) / Δt` (their
//! The 2017-era commented `asymTOTALVAR` after `addedTIPREDVAR` is
//! `-q / (2 a) + trait / a² + (B / a)² v` (cran/ctsem 2.5.0
//! `summary.ctsemFit.R`; JSS PDF re-opened 2026-08-31T04:40Z). The
//! two-term total omits the later addend. Stationary `T0VAR` keeps
//! `TRAITVAR` in process units. The difference quotient `(x(t+Δt) − x(t)) / Δt` (their
//! Eqs. 3–4) is refused. This is not DSEM and not a matrix `expm`.

use std::collections::BTreeMap;
Expand Down Expand Up @@ -4160,6 +4164,186 @@ pub fn refuse_asymptotic_time_independent_variance_as_asymptotic_effect(
Err(PsychometricError::AsymptoticTimeIndependentVarianceIsNotAsymptoticEffect)
}

/// Exact scalar 2017-era commented-out `asymTOTALVAR` after
/// `addedTIPREDVAR`.
///
/// 2017-era ctsem `summary.ctsemFit.R` (cran/ctsem 2.5.0; JSS PDF
/// re-opened 2026-08-31T04:40Z from
/// <https://www.jstatsoft.org/index.php/jss/article/download/v077i05/1104>)
/// comments `asymTOTALVAR <- asymDIFFUSION + asymTRAITVAR` with
/// `asymTRAITVAR <- solve(DRIFT) %*% TRAITVAR %*% t(solve(DRIFT))`,
/// then later comments
/// `asymTOTALVAR <- asymTOTALVAR + addedTIPREDVAR` immediately
/// after forming `addedTIPREDVAR <- asymTIPREDEFFECT %*% TIPREDVAR
/// %*% t(asymTIPREDEFFECT)`. Driver, Oud, and Voelkle (2017, Eq. 1,
/// p. 4; Eq. 4, p. 5; Table 2, p. 12; §4.3, p. 9; §7.2, pp. 20–21)
/// write `dη = (Aη + ξ + Bz + Mx) dt + G dW`. The Lyapunov
/// within-subject variance is `asymDIFFUSION` `-q / (2 a)`. At a
/// stable equilibrium a random intercept in `CINT` units has
/// process-mean variance `trait / a²`. Section 7.2 names
/// `addedTIPREDVAR` the stable between-subject variance accounted
/// for by a time-independent predictor, `(B / a)² v`. The scalar
/// three-term map is `-q / (2 a) + trait / a² + (B / a)² v`. Form
/// the two-term total first (`1 / a`, then square, then multiply
/// by `trait`, then add `asymDIFFUSION`). Then include
/// `addedTIPREDVAR` (unit asymptotic effect, then square, then
/// multiply by `v`). Then add. This crate does not currently
/// export `recover_asymptotic_total_variance` or
/// `recover_asymptotic_trait_variance`; form those terms inline.
/// Table 2/3 do not name `asymTOTALVAR`. A zero trait, a zero
/// diffusion, and a zero TI extra is exactly zero even if
/// `a ≥ 0`. `a ≥ 0` with a nonzero contribution fails closed. A
/// zero trait and a zero diffusion keep `addedTIPREDVAR`. A zero
/// TI extra keeps the two-term total. `p + trait / a²` is the
/// two-term commented total and is not this map when
/// `addedTIPREDVAR ≠ 0`. Stationary `T0VAR`
/// `trait + p + (B / a)² v` keeps `TRAITVAR` in process units and
/// is not this map. `(B / a)² v` is `addedTIPREDVAR` and equals
/// this total when `q = 0` and `trait = 0` and remains a distinct
/// named quantity. This is not a Kalman filter, not a matrix
/// `expm`, and not ctsem estimation.
///
/// # Errors
///
/// Returns [`PsychometricError::EventTimeRequired`] for a non-event
/// clock,
/// [`PsychometricError::AsymptoticTotalVarianceAfterAddedPredictorRequiresStableDrift`]
/// when the drift is not strictly negative and a contribution is
/// nonzero, and [`PsychometricError::InvalidNumericInput`] when an
/// input is non-finite, a variance is negative, or a product or
/// sum overflows.
pub fn recover_asymptotic_total_variance_after_added_time_independent_predictor(
trait_variance: f64,
continuous_diffusion: f64,
time_independent_effect: f64,
predictor_variance: f64,
log_rate: f64,
clock: LagClock,
) -> Result<f64, PsychometricError> {
if !clock.admits_structural_lag() {
return Err(PsychometricError::EventTimeRequired);
}
if !trait_variance.is_finite() || trait_variance < 0.0 {
return Err(PsychometricError::InvalidNumericInput);
}
if !continuous_diffusion.is_finite() || continuous_diffusion < 0.0 {
return Err(PsychometricError::InvalidNumericInput);
}
if !time_independent_effect.is_finite() {
return Err(PsychometricError::InvalidNumericInput);
}
if !predictor_variance.is_finite() || predictor_variance < 0.0 {
return Err(PsychometricError::InvalidNumericInput);
}
if !log_rate.is_finite() {
return Err(PsychometricError::InvalidNumericInput);
}
let ti_extra_is_zero = time_independent_effect == 0.0 || predictor_variance == 0.0;
if trait_variance == 0.0 && continuous_diffusion == 0.0 && ti_extra_is_zero {
return Ok(0.0);
}
if log_rate >= 0.0 {
return Err(
PsychometricError::AsymptoticTotalVarianceAfterAddedPredictorRequiresStableDrift,
);
}
let stationary = if continuous_diffusion == 0.0 {
0.0
} else {
recover_stationary_latent_variance(continuous_diffusion, log_rate, clock)?
};
let asymptotic_trait = if trait_variance == 0.0 {
0.0
} else {
let inverse_rate = require_finite(1.0 / log_rate)?;
let inverse_rate_squared = require_finite(inverse_rate * inverse_rate)?;
require_finite(inverse_rate_squared * trait_variance)?
};
let two_term = if stationary == 0.0 {
asymptotic_trait
} else if asymptotic_trait == 0.0 {
stationary
} else {
require_finite(stationary + asymptotic_trait)?
};
let added = recover_asymptotic_time_independent_predictor_variance(
time_independent_effect,
predictor_variance,
log_rate,
clock,
)?;
if added == 0.0 {
return Ok(two_term);
}
if two_term == 0.0 {
return Ok(added);
}
require_finite(two_term + added)
}

/// Refuse treating the two-term commented `asymTOTALVAR` as the
/// later three-term total.
///
/// `p + trait / a²` omits `addedTIPREDVAR`. Equal numbers when the
/// TI extra is zero remain distinct named quantities.
///
/// # Errors
///
/// Always returns
/// [`PsychometricError::TwoTermAsymptoticTotalVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor`].
pub fn refuse_two_term_asymptotic_total_variance_as_asymptotic_total_variance_after_added_predictor(
two_term_total: f64,
three_term_total: f64,
) -> Result<f64, PsychometricError> {
let _ = (two_term_total, three_term_total);
Err(
PsychometricError::TwoTermAsymptoticTotalVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
)
}

/// Refuse treating §4.3 stationary `T0VAR` as 2017-era
/// `asymTOTALVAR` after `addedTIPREDVAR`.
///
/// `trait + p + (B / a)² v` keeps `TRAITVAR` in process units. The
/// commented three-term total uses `solve(DRIFT)` and is
/// `p + trait / a² + (B / a)² v`.
///
/// # Errors
///
/// Always returns
/// [`PsychometricError::StationaryInitialLatentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor`].
pub fn refuse_stationary_initial_latent_variance_as_asymptotic_total_variance_after_added_predictor(
stationary_initial: f64,
three_term_total: f64,
) -> Result<f64, PsychometricError> {
let _ = (stationary_initial, three_term_total);
Err(
PsychometricError::StationaryInitialLatentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
)
}

/// Refuse treating §7.2 `addedTIPREDVAR` as 2017-era
/// `asymTOTALVAR` after `addedTIPREDVAR`.
///
/// `(B / a)² v` is the later addend. The commented three-term
/// total also includes `asymDIFFUSION` and `asymTRAITVAR`. Equal
/// numbers when `q = 0` and `trait = 0` remain distinct named
/// quantities.
///
/// # Errors
///
/// Always returns
/// [`PsychometricError::AsymptoticTimeIndependentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor`].
pub fn refuse_asymptotic_time_independent_variance_as_asymptotic_total_variance_after_added_predictor(
added_predictor_variance: f64,
three_term_total: f64,
) -> Result<f64, PsychometricError> {
let _ = (added_predictor_variance, three_term_total);
Err(
PsychometricError::AsymptoticTimeIndependentVarianceIsNotAsymptoticTotalVarianceAfterAddedPredictor,
)
}

/// Exact scalar Table 2 `asymCINT`.
///
/// Driver, Oud, and Voelkle (2017, Table 2, p. 12; Eq. 3, p. 5;
Expand Down
Loading
Loading