SPB Git

spb/metrika Public

Stata-class statistics, GPU-accelerated by Apple Silicon. Native Swift — no Electron, no Python runtime, no compromises.

Swift 92.4% HTML 3.3% R 3% Shell 1.3%

History of MetrikaKit/Sources/ZQStats/IV.swift · clear filter

  1. feat(engine): margins dydx() with delta-method standard errors
    - ZQOLSResult/ZQGLMResult expose the full covariance matrix (column-major
      k x k aligned with coefficients); IV passes it through
    - EstimationState carries vce, inference df, and the estimation-sample
      design (GLMs only — AMEs need it)
    - margins, dydx(varlist): OLS/IV effects are the coefficients with their
      SEs; GLM average marginal effects with analytic delta gradients
      (logit p(1-p)(1-2p), probit -xb*phi, poisson exp) over the estimation
      sample; t or z inference per model kind
    - factor/interaction dydx rejected with a clear message (discrete-change
      margins later); continuous terms of factor models work
    - R fixtures mirror the exact formulas at the converged coefficients;
      logit/poisson AME and delta SE match at 1e-10
    - 98 tests green (swift test and xcodebuild with GPU suites)
    
    Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
    simon-pierre boucher committed 6 days ago (Aug 5, 2026) · 1 file changed +2 −1
  2. feat(stats): xtreg fixed effects and ivregress 2sls
    - parser: (endog = instruments) varlist groups -> ZQIVSpec; digit-led
      sub-commands (2sls) reassembled from number+identifier tokens via
      column adjacency
    - ZQFixedEffects: within estimator with Stata conventions (add-back
      means, reported _cons, df = N-K-G), within R-squared, panel-clustered
      VCE with G/(G-1) and t on G-1 df; v0.2 restriction: cluster variable
      must equal the panel variable
    - ZQIV: 2SLS via thin-Q projection of the instrument matrix (Z'Z never
      formed), residuals from original regressors, Stata 'small' inference,
      classical/HC1/cluster VCE built on projected regressors
    - engine: xtreg (requires xtset + fe), ivregress 2sls with dedicated
      listwise deletion across depvar/exog/endog/instruments; shared
      coefficient-table renderer extracted
    - fixtures: z1/z2 instrument columns (drawn after existing draws, earlier
      golden values bit-identical), manual within/2SLS algebra in R
    - 75 tests green (swift test and xcodebuild with GPU suites)
    
    Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
    simon-pierre boucher committed 6 days ago (Aug 5, 2026) · 1 file changed +234