mooncopula

    Bivariate Archimedean dependence modeling and joint risk workflows in pure MoonBit

    copula
    dependence
    statistics
    risk
    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    7 hours ago
    Downloads
    4

    No dependencies

    #MoonCopula(月依存)

    纯 MoonBit 的二维 Archimedean Copula 建模库:把配对观测转换为秩分布,拟合并比较依赖模型,计算联合事件概率,再将条件场景还原为原始量纲。版本 0.1.0,模块 CYang-dep/mooncopula,MIT 许可证。

    它面向需要联合超越概率的环境分析者、需要相关寿命场景的可靠性工程开发者,以及需要可解释模型比较的风险工具开发者。三个完整、固定输入的示例见下文;合成数据仅用于展示计算流程。

    #已实现能力

    • 独立、Clayton、Gumbel、Frank 四类二维模型;0/90/180/270 度旋转。
    • 闭方形 CDF、开方形密度/对数密度、条件 CDF、带残差及迭代次数的条件反解。
    • 正向/逆向 Rosenblatt 变换;模拟均匀数由调用方提供,无隐藏随机状态。
    • 稳定平均秩、顺序秩及拒绝并列策略,Kendall tau-b、Spearman rho、有限阈值尾部统计。
    • 经验联合分布与矩形概率;无并列数据的 Checkerboard 平滑和均匀边缘。
    • 有界伪极大似然拟合、收敛/边界标志、AIC/BIC、显式候选集比较与 AIC 权重。
    • 联合/任一超越、混合象限概率、条件超越、重现期、渐近同尾系数。
    • 经验边缘的阶梯广义逆与独立的 type-7 线性分位数,原始量纲场景生成。
    • 网格差异、Rosenblatt 残差、KS/Cramer-von Mises 描述统计、阈值事件校准与 Wilson 区间。
    • 调用方提供索引计划的成对重采样:逐次重新排名和拟合、百分位汇总、边界拟合计数;失败的重复不会被悄悄丢弃。

    不提供高维/vine、Gaussian/t、自动边缘分布选择、缺失值清洗、时间序列建模、隐含随机数发生器、显著性 p 值或因果推断。与生态中面向金融 Gaussian/t 相关随机向量的 MonteCarlo 包有不同入口和核心任务;查重依据与限度见 选题与查重。

    #环境和安装

    固定验证工具链:moonc v0.10.18+6c83a7f62,moon 0.1.20261028 (e1e1f15),高于验收要求的 0.10.16。使用官方 MoonBit 工具链;JS 运行需要 Node.js。支持 wasm-gc、wasm、js 以及 Linux native,CI 针对四个后端分别执行检查、构建、测试和全部示例。Windows native 需要另外安装 MSVC C++ 工具和 Windows SDK;本机缺少这些组件,未声称在 Windows 上运行 native。

    在一个新的目录创建消费者,显式指定自己的模块身份:

    moon new copula-consumer --user guest --name copula-consumer cd copula-consumer moon add CYang-dep/mooncopula@0.1.0

    在 cmd/main/moon.pkg 中导入库:

    import { "CYang-dep/mooncopula" }
    options("is-main": true)

    将 cmd/main/main.mbt 替换为下面的快速开始,然后执行 moon check、moon build、moon run cmd/main。本库运行时仅依赖 MoonBit core,不需要 Python、网络、token 或本地登录。

    #快速开始

    ///|
    fn main raise {
    let model = @mooncopula.Copula::new(@mooncopula.Clayton, 2.0)
    println(model.cdf(0.5, 0.5))
    let inverse = model.inverse_conditional(0.3, 0.9)
    assert_true(inverse.residual <= 1.0e-8)
    println(inverse.value)
    }

    首行 CDF 约为 0.3779644730092272。反解同时提供 value、residual、iterations,不能只看结果值忽略收敛情况。示例使用 fn main raise 传播错误,调用系统可以捕获 CopulaError,区分非法输入、资源预算和数值失败。

    #三个可运行工作流

    从源码复现:

    git clone https://github.com/CYang-dep/mooncopula.git cd mooncopula git checkout v0.1.0 moon run examples/environment moon run examples/reliability moon run examples/risk

    用户与输入示例的处理可观察结果
    环境分析:12 组模拟降雨/流量平均秩、Gumbel 拟合、联合超越、经验对照、网格诊断theta 约 9.80595,阈值 0.8 的联合超越约 0.187031,经验频率 1/12
    可靠性开发:6 组模拟寿命、4 对固定均匀数Clayton 逆变换、经验寿命边缘恢复、残差检查场景 (100,130)、(240,410)、(400,360)、(500,410)
    风险工具:8 组配对观测11 候选 AIC 比较、校准、Rosenblatt 诊断、4 个固定重采样计划最优 Frank 正分支 AIC 约 -6.31681,联合预测约 0.181204,输出 4 个重复结果

    浮点末位和近似并列模型的顺序可因平台不同变化。风险示例的四个计划仅验证执行机制,不能据此声称百分位区间具有实际覆盖率;实际应用应由调用方提供符合数据抽样设计的充分重复次数。

    #核心 API 与语义

    let uniforms = @mooncopula.pseudo_observations(raw)
    let fitted = @mooncopula.fit(@mooncopula.Clayton, uniforms)
    assert_true(fitted.converged)
    let joint = fitted.model.risk(0.8, 0.9)
    let scenarios = fitted.model.scenarios(raw, supplied_uniforms)

    这段为主函数内的接口片段,raw 为配对原始观测,supplied_uniforms 为调用方提供的开方形均匀对。完整可运行变量与错误处理见示例。完整公开签名见 接口文件。

    • ranks 已经返回秩除以 n+1 的值,勿重复归一化。默认平均秩;并列可显式拒绝或按输入次序打破。常数坐标的相关系数无定义,会抛出错误。
    • cdf 接受 [0,1]² 并有精确边缘;密度/似然/模拟输入要求 (0,1)²。conditional(u,v) 为 ∂C(u,v)/∂u,不是 C(u,v)/u。
    • risk 的下侧为 <=,上侧为 >;rectangle(lo_u,hi_u,lo_v,hi_v) 对应 (lo_u,hi_u]×(lo_v,hi_v]。经验 CDF 有离散边缘;只有无并列的 Checkerboard 平滑保证连续均匀边缘。
    • Clayton 参数 [0.01,30],Gumbel [1,20],Frank [-30,-0.01]∪[0.01,30];精确独立使用 independence() 或 Independence,0。
    • Frank 拟合默认正分支;负分支须显式给出负上下界,不能跨零拟合。standard_candidates() 明确包含两个分支与旋转模型。AIC 权重是相对拟合分数,不是模型正确概率。
    • 拟合先扫描 25 个点,再在最优邻域黄金分割;保留端点最优、报告预算耗尽,不保证全局最优。at_boundary 提示结果受参数域约束。二维连续边缘被经验排名替代后的似然属于伪似然。
    • return_period(p,period_length) 返回 period_length/p;零概率返回 None,解释为平均事件周期需等长、独立且平稳的观测期假设。
    • 诊断均为描述量;同样本拟合、排名与序列依赖会影响显著性或区间覆盖。Wilson 区间描述观测 Bernoulli 频率,未包含参数估计不确定性。Bootstrap 百分位并不自动保证覆盖率。
    • 每组最多 4096 个观测、候选最多 32 个、网格最多 63×63、重采样 2–128 次且最多 262144 个总抽取。Kendall/tie 统计与经验网格的最坏复杂度为二次;调用者应按工作量选择预算。
    • 不接受 NaN、无穷、缺失值;接近奇点时密度可下溢,反解可显式报告数值失败。log_density 优先于 density,不能将测试容差外推为全域精度保证。

    #开发与验证

    moon info moon fmt --check moon check --deny-warn moon build --deny-warn moon test --deny-warn moon test --deny-warn --target wasm moon test --deny-warn --target js moon test --deny-warn --target native

    31 个测试用例包含独立数值预期、边界、并列、旋转、预算、拒绝无效输入、所有核心流程及函数不变量。statsmodels / SciPy / 80 位 Decimal 的独立向量可重新生成:

    python -m pip install -r scripts/oracle-requirements.txt python scripts/generate_oracle.py --check python scripts/audit_source.py

    Python 仅用于开发验证,要求 3.12。数据、版本与容差来源见 独立预期。测试通过不代表数学全域精度、统计假设或无 Bug 的证明。CI 定义见 .github/workflows/ci.yml。

    #结构、许可和 AI 使用

    根目录 13 个生产 .mbt 文件按概率引擎、变换、秩统计、经验分布、风险、拟合、选择、边缘、诊断、重采样、校准拆分;测试与生成测试向量独立,三个 examples/ 目录为真实消费者入口。设计见 架构,发布变更见 CHANGELOG。

    本项目为原创方程与算法实现,采用 MIT。没有复制 statsmodels、SciPy 或相邻生态包的实现。依赖、参考来源和许可证边界见 THIRD_PARTY.md。AI 参与选题研究、实现、测试与文档,参见 AI 使用说明。输入与状态的边界见 SECURITY.md。

    CopulaError

    pub(all) suberror CopulaError {
    InvalidInput(String)
    BudgetExceeded(String)
    NumericalFailure(String)
    } derive(
    Debug
    )

    Explicit failures; numerical singularities are not silently clipped.

    BootstrapReplicate

    pub struct BootstrapReplicate {
    model : Copula
    log_likelihood : Double
    at_boundary : Bool
    upper_joint_probability : Double
    }

    Each raw-data replicate is reranked; no fixed original margins are reused.

    BootstrapResult

    pub struct BootstrapResult {
    replicates : Array[BootstrapReplicate]
    theta : SampleSummary
    upper_joint_probability : SampleSummary
    boundary_fits : Int
    }

    Deterministic replicates, summaries and visible boundary-fit frequency.

    CalibrationPoint

    pub struct CalibrationPoint {
    threshold : Pair
    forecast : Double
    observed : RateInterval
    residual : Double
    }

    Observed threshold frequency and model forecast at a single threshold pair.

    Candidate

    pub(all) struct Candidate {
    label : String
    family : Family
    rotation : Rotation
    options : FitOptions
    }

    An explicit model candidate, including Frank branch and rotation.

    Concordance

    pub struct Concordance {
    concordant : Int
    discordant : Int
    x_only_ties : Int
    y_only_ties : Int
    both_ties : Int
    tau_b : Double
    } derive(
    Debug
    )

    Exact finite-sample concordance counts, including coordinate-specific ties.

    Copula

    pub struct Copula {
    family : Family
    theta : Double
    rotation : Rotation
    } derive(
    Debug
    )

    Construction validates parameters. Fields cannot be changed by consumers.

    Copula::calibration_curve

    fn Copula::calibration_curve(self : Copula, data : Array[Pair], thresholds : Array[Pair], event : ThresholdEvent, z? : Double) -> Array[CalibrationPoint] raise CopulaError

    Compare analytic forecasts with exact counts, including observed ties. Wilson ranges describe observed Bernoulli frequencies only. In-sample model fitting and rank transformations are not accounted for in their coverage.

    Copula::cdf

    fn Copula::cdf(self : Copula, u : Double, v : Double) -> Double raise CopulaError

    Closed-square CDF with exact margins and explicit finite validation.

    Copula::conditional

    fn Copula::conditional(self : Copula, u : Double, v : Double) -> Double raise CopulaError

    P(V<=v | U=u) = derivative C(u,v)/du, for 0<u<1 and 0<=v<=1.

    Copula::conditional_exceedance

    fn Copula::conditional_exceedance(self : Copula, u : Double, v : Double) -> Double raise CopulaError

    P(V>v | U>u), a threshold event; differs from conditional(v|u) at a point.

    Copula::density

    fn Copula::density(self : Copula, u : Double, v : Double) -> Double raise CopulaError

    Density on the open square; boundary singularities are rejected.

    Copula::grid_diagnostic

    fn Copula::grid_diagnostic(self : Copula, data : Array[Pair], grid : Array[Pair]) -> GridDiagnostic raise CopulaError

    Compare an analytic CDF with a step empirical CDF at caller-chosen points. The finite sample statistic depends on the chosen grid and rank policy.

    Copula::inverse_conditional

    fn Copula::inverse_conditional(self : Copula, u : Double, q : Double, tolerance? : Double, max_iterations? : Int) -> Inversion raise CopulaError

    Invert conditional CDF by monotone bisection (up to 80 iterations). Endpoint q is supported, conditioning u remains strictly interior.

    Copula::log_density

    fn Copula::log_density(self : Copula, u : Double, v : Double) -> Double raise CopulaError

    Log density is preferred for fitting, including near singular boundaries.

    Copula::log_likelihood

    fn Copula::log_likelihood(self : Copula, data : Array[Pair]) -> Double raise CopulaError

    Sum of log densities using compensated accumulation.

    Copula::new

    fn Copula::new(family : Family, theta : Double, rotation? : Rotation) -> Copula raise CopulaError

    Create an analytic model in its documented numerically bounded domain. Clayton: [0.01,30], Gumbel: [1,20], Frank: [-30,-0.01] or [0.01,30]. Independence requires theta=0. Use it for the exact independence limit.

    Copula::rectangle

    fn Copula::rectangle(self : Copula, lo_u : Double, hi_u : Double, lo_v : Double, hi_v : Double) -> Double raise CopulaError

    Continuous rectangle mass using inclusion-exclusion, with explicit order.

    Copula::residual_diagnostic

    fn Copula::residual_diagnostic(self : Copula, data : Array[Pair]) -> RosenblattDiagnostic raise CopulaError

    Transform observations then diagnose both marginal uniformity and dependence. Parameters fitted on the same data invalidate ordinary null p-values; this API intentionally returns descriptive statistics only.

    Copula::risk

    fn Copula::risk(self : Copula, u : Double, v : Double) -> JointRisk raise CopulaError

    Copula::rosenblatt

    fn Copula::rosenblatt(self : Copula, data : Array[Pair]) -> Array[Pair] raise CopulaError

    Rosenblatt transform (u,v) -> (u,H(v|u)). Does not mutate input.

    Copula::scenarios

    fn Copula::scenarios(self : Copula, raw : Array[Pair], uniforms : Array[Pair]) -> Array[Pair] raise CopulaError

    Full raw-units scenario workflow using input observations as empirical margins.

    Copula::simulate

    fn Copula::simulate(self : Copula, uniforms : Array[Pair]) -> Array[Pair] raise CopulaError

    Inverse Rosenblatt map. Input consists of caller-provided open-square uniforms. Enforces residual <=1e-8; concentrated/extreme cases may fail explicitly.

    Copula::tail_coefficients

    fn Copula::tail_coefficients(self : Copula) -> (Double, Double)

    Theoretical asymptotic same-tail coefficients; no inference from data.

    Copula::to_repr

    EmpiricalCopula

    pub struct EmpiricalCopula {
    // private fields
    }

    Owned empirical distribution on the unit square. Construction copies input.

    EmpiricalCopula::cdf

    fn EmpiricalCopula::cdf(self : EmpiricalCopula, u : Double, v : Double) -> Double raise CopulaError

    Empirical joint CDF, both coordinates use <=. Margins are discrete.

    EmpiricalCopula::from_raw

    fn EmpiricalCopula::from_raw(data : Array[Pair], policy? : TiePolicy) -> EmpiricalCopula raise CopulaError

    EmpiricalCopula::new

    Already ranked uniforms; use from_raw for finite raw measurements.

    EmpiricalCopula::observations

    fn EmpiricalCopula::observations(self : EmpiricalCopula) -> Array[Pair]

    Return a defensive copy of pseudo-observations.

    EmpiricalCopula::rectangle

    fn EmpiricalCopula::rectangle(self : EmpiricalCopula, lo_u : Double, hi_u : Double, lo_v : Double, hi_v : Double) -> Double raise CopulaError

    Probability of (lo_u,hi_u] x (lo_v,hi_v], including exact discrete ties.

    EmpiricalCopula::size

    fn EmpiricalCopula::size(self : EmpiricalCopula) -> Int

    EmpiricalMargin

    pub struct EmpiricalMargin {
    // private fields
    }

    Owned sorted finite empirical margin. No parametric extrapolation.

    EmpiricalMargin::cdf

    fn EmpiricalMargin::cdf(self : EmpiricalMargin, x : Double) -> Double raise CopulaError

    Empirical CDF with upper-bound binary search; ties use <=.

    EmpiricalMargin::linear_quantile

    fn EmpiricalMargin::linear_quantile(self : EmpiricalMargin, p : Double) -> Double raise CopulaError

    Linear order-statistic quantile (type 7), separate from the step inverse.

    EmpiricalMargin::new

    fn EmpiricalMargin::new(values : Array[Double]) -> EmpiricalMargin raise CopulaError

    EmpiricalMargin::quantile

    fn EmpiricalMargin::quantile(self : EmpiricalMargin, p : Double) -> Double raise CopulaError

    Left-continuous generalized inverse: x[ceil(n*p)-1], p=0 -> minimum. Returning an observed value avoids imposing interpolation on discrete margins.

    EmpiricalMargin::size

    fn EmpiricalMargin::size(self : EmpiricalMargin) -> Int

    Family

    pub(all) enum Family {
    Independence
    Clayton
    Gumbel
    Frank
    } derive(
    Debug
    )

    Supported bivariate analytic families.

    Family::to_repr

    FitOptions

    pub(all) struct FitOptions {
    lower : Double
    upper : Double
    tolerance : Double
    iterations : Int
    }

    Fitting controls are validated on every call, including caller-built values.

    FitResult

    pub struct FitResult {
    model : Copula
    log_likelihood : Double
    aic : Double
    bic : Double
    observations : Int
    evaluations : Int
    converged : Bool
    at_boundary : Bool
    }

    Result of coarse-grid bracketing plus golden-section local refinement.

    GridDiagnostic

    pub struct GridDiagnostic {
    points : Int
    maximum_absolute : Double
    root_mean_square : Double
    sample_scaled_mean_square : Double
    }

    Grid discrepancy is descriptive; no uncalibrated goodness-of-fit p-value.

    Inversion

    pub struct Inversion {
    value : Double
    residual : Double
    iterations : Int
    } derive(
    Debug
    )

    Bounded inversion result exposes numerical residual instead of claiming exactness.

    JointRisk

    pub struct JointRisk {
    lower_both : Double
    upper_both : Double
    upper_either : Double
    x_above_y_below : Double
    x_below_y_above : Double
    } derive(
    Debug
    )

    Joint event decomposition for uniform thresholds, evaluated in one model.

    Pair

    pub(all) struct Pair {
    x : Double
    y : Double
    } derive(
    Debug
    )

    Owned pair of finite observations. Validation is performed by operations.

    Pair::to_repr

    RankedModel

    pub struct RankedModel {
    label : String
    fit : FitResult
    delta_aic : Double
    weight : Double
    }

    Ranked model fit plus normalized AIC weight.

    RateInterval

    pub struct RateInterval {
    successes : Int
    trials : Int
    observed : Double
    lower : Double
    upper : Double
    }

    Wilson interval for a Bernoulli rate, conditional on iid observations.

    RosenblattDiagnostic

    pub struct RosenblattDiagnostic {
    first : UniformDiagnostic
    second : UniformDiagnostic
    residual_spearman : Double
    }

    Residual marginal diagnostics and remaining rank correlation.

    Rotation

    pub(all) enum Rotation {
    R0
    R90
    R180
    R270
    } derive(
    Debug
    )

    Rotation of a base copula on the unit square.

    Rotation::to_repr

    SampleSummary

    pub struct SampleSummary {
    count : Int
    mean : Double
    standard_deviation : Double
    lower : Double
    median : Double
    upper : Double
    }

    Percentile summary uses the type-7 sample quantile and sample variance.

    TailDiagnostic

    pub struct TailDiagnostic {
    threshold : Double
    lower_joint : Double
    upper_joint : Double
    lower_coefficient : Double
    upper_coefficient : Double
    observations : Int
    } derive(
    Debug
    )

    Finite-threshold tail probabilities, not asymptotic tail estimates.

    ThresholdEvent

    pub(all) enum ThresholdEvent {
    LowerBoth
    UpperBoth
    UpperEither
    FirstUpperSecondLower
    FirstLowerSecondUpper
    }

    Threshold event convention: lower is <=; upper is >.

    TiePolicy

    pub(all) enum TiePolicy {
    Midrank
    Ordinal
    RejectTies
    } derive(
    Debug
    )

    Midrank policy keeps ties equal; Ordinal is stable input-order tie breaking.

    UniformDiagnostic

    pub struct UniformDiagnostic {
    count : Int
    mean : Double
    variance : Double
    ks_distance : Double
    cramer_von_mises : Double
    }

    Univariate descriptive uniformity statistics, without a significance claim.

    bootstrap_raw

    fn bootstrap_raw(family : Family, raw : Array[Pair], plans : Array[Array[Int]], threshold : Pair, rotation? : Rotation, options? : FitOptions, coverage? : Double) -> BootstrapResult raise CopulaError

    Resample raw paired observations using caller-supplied plans. This library never invents an RNG seed or silently drops failed replicates. Plan generation determines the resampling design; iid percentile inference needs iid observations and sufficient replicates, which this API cannot prove.

    checked_probability

    fn checked_probability(x : Double) -> Double raise CopulaError

    checkerboard_cdf

    fn checkerboard_cdf(raw : Array[Pair], u : Double, v : Double) -> Double raise CopulaError

    Smoothed checkerboard CDF uses ordinal (untied) ranks only. Each rank cell spreads mass uniformly over its n-by-n grid cell.

    compare_models

    fn compare_models(candidates : Array[Candidate], data : Array[Pair]) -> Array[RankedModel] raise CopulaError

    AIC comparison on identical data. Failure/nonconvergence is explicit; unsuccessful candidates are never silently discarded.

    concordance

    fn concordance(data : Array[Pair]) -> Concordance raise CopulaError

    Kendall tau-b; fails when either coordinate is constant.

    default_fit_options

    fn default_fit_options(family : Family) -> FitOptions

    Defaults cover the positive branch; Frank's negative branch is explicit.

    empirical_tails

    fn empirical_tails(data : Array[Pair], threshold : Double) -> TailDiagnostic raise CopulaError

    threshold in (0,0.5]; lower uses <=q, upper uses >1-q.

    fit

    fn fit(family : Family, data : Array[Pair], rotation? : Rotation, options? : FitOptions) -> FitResult raise CopulaError

    Fit open-square data. Raw observations must first be transformed to ranks. No global optimality or confidence-interval guarantee is implied.

    fit_raw

    fn fit_raw(family : Family, raw : Array[Pair], rotation? : Rotation) -> FitResult raise CopulaError

    Fit a specific family from raw paired observations using midrank uniforms.

    independence

    fn independence() -> Copula

    Exact independent model.

    probability_grid

    fn probability_grid(divisions : Int) -> Array[Pair] raise CopulaError

    Interior rectangular grid; limits bound both memory and diagnostic work.

    pseudo_observations

    fn pseudo_observations(data : Array[Pair], policy? : TiePolicy) -> Array[Pair] raise CopulaError

    Convert finite paired raw observations into paired open-square ranks.

    ranks

    fn ranks(values : Array[Double], policy? : TiePolicy) -> Array[Double] raise CopulaError

    One-based ranks divided by n+1, ensuring every output is interior.

    resample_pairs

    fn resample_pairs(data : Array[Pair], indices : Array[Int]) -> Array[Pair] raise CopulaError

    Copy paired rows by zero-based indices. The original array is never aliased.

    restore_margins

    fn restore_margins(data : Array[Pair], x_margin : EmpiricalMargin, y_margin : EmpiricalMargin) -> Array[Pair] raise CopulaError

    Map simulated dependence uniforms back to observed marginal units.

    return_period

    fn return_period(event_probability : Double, period_length : Double) -> Double? raise CopulaError

    Expected waiting time under independent, identically distributed event periods. Zero probability gives None, never an artificial finite return period.

    sample_summary

    fn sample_summary(values : Array[Double], coverage? : Double) -> SampleSummary raise CopulaError

    Summarize finite replicates. Coverage is a percentile range, not a guarantee.

    spearman

    fn spearman(data : Array[Pair]) -> Double raise CopulaError

    Spearman rho is Pearson correlation of midranks, including tied data.

    standard_candidates

    fn standard_candidates() -> Array[Candidate]

    A compact standard model set; negative dependence is represented explicitly.

    tie_counts

    fn tie_counts(data : Array[Pair]) -> (Int, Int) raise CopulaError

    Count excess observations tied with an earlier occurrence, per coordinate.

    uniform_diagnostic

    fn uniform_diagnostic(values : Array[Double]) -> UniformDiagnostic raise CopulaError

    Finite-sample empirical-vs-uniform KS and Cramer-von Mises statistics. Variance uses n, not n-1. Inputs may include exact endpoints.

    validate_uniforms

    fn validate_uniforms(data : Array[Pair], minimum : Int) -> Unit raise CopulaError

    wilson_interval

    fn wilson_interval(successes : Int, trials : Int, z? : Double) -> RateInterval raise CopulaError

    Caller chooses z (1.959963984540054 approximates a two-sided 95% interval). No time-series dependence or fitted-parameter adjustment is implied.