// // StatsTests.swift // Metrika // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Copyright © 2026 Simon-Pierre Boucher. All rights reserved. // import Foundation import Testing import ZQData import ZQStats /// Numerical tests against R-generated fixtures (Tests/Fixtures/generate.R) /// at 1e-10 relative tolerance (CLAUDE.md §0). @Suite("ZQStats vs R fixtures") struct StatsTests { let fixtures: Fixtures let y: [Double] // log(revenue), estimation sample let price: [Double] let region: [Double] let firmID: [Int] init() async throws { self.fixtures = try Fixtures() // Load the fixture CSV through the real data path (DuckDB). let store = try ZQDataStore() let frame = try await store.load(contentsOf: fixtures.datasetURL) let (revenue, revenueMissing) = try frame.requireNumeric("revenue") let (priceAll, priceMissing) = try frame.requireNumeric("price") let (regionAll, _) = try frame.requireNumeric("region") let (firmAll, _) = try frame.requireNumeric("firm_id") // Listwise deletion, mirroring generate.R. var y: [Double] = [], price: [Double] = [] var region: [Double] = [], firm: [Int] = [] for i in 0..