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%
1.8 KB · 50 lines r
Raw Blame History
1#!/usr/bin/env Rscript2#3#  make_samples.R — Metrika4#5#  Author:  Simon-Pierre Boucher6#  Contact: contact@spboucher.ai7#  Copyright © 2026 Simon-Pierre Boucher. All rights reserved.8#9#  Generates the sample datasets bundled with the app (loaded via the10#  `sysuse` command). Deterministic: fixed seed, values rounded so the11#  CSVs are bit-stable across regenerations.12#1314out <- file.path(15  dirname(dirname(normalizePath(sub("--file=", "", grep("--file=", commandArgs(FALSE), value = TRUE))))),16  "MetrikaKit", "Sources", "ZQEngine", "Resources", "Samples"17)18dir.create(out, recursive = TRUE, showWarnings = FALSE)1920# sales — the CLAUDE.md flagship example: firm-year panel of revenue and21# price with regional effects. 200 firms × 5 years.22set.seed(2026)23firms <- 20024years <- 2019:202325n <- firms * length(years)26firm_id <- rep(seq_len(firms), each = length(years))27year <- rep(years, times = firms)28region <- rep(sample(1:4, firms, replace = TRUE), each = length(years))29firm_effect <- rep(round(rnorm(firms, 0, 0.3), 6), each = length(years))30price <- round(runif(n, 5, 25) + 0.4 * (year - 2019), 4)31log_revenue <- 4.2 - 0.07 * price + 0.12 * (region - 1) +32  0.05 * (year - 2019) + firm_effect + round(rnorm(n, 0, 0.2), 6)33sales <- data.frame(34  firm_id = firm_id,35  year = year,36  region = region,37  price = price,38  revenue = round(exp(log_revenue), 4),39  employees = pmax(1, round(exp(2 + 0.5 * firm_effect + rnorm(n, 0, 0.4))))40)41write.csv(sales, file.path(out, "sales.csv"), row.names = FALSE, quote = FALSE)4243# mtcars — the R classic (public dataset), with the car name as a string44# column so string handling has a sample too.45data(mtcars)46cars <- cbind(model = rownames(mtcars), mtcars)47write.csv(cars, file.path(out, "mtcars.csv"), row.names = FALSE)4849cat("wrote", file.path(out, "sales.csv"), "and mtcars.csv\n")50