{"id":15360547,"url":"https://github.com/devmotion/rcalibration","last_synced_at":"2026-02-01T11:33:56.340Z","repository":{"id":44014428,"uuid":"364090458","full_name":"devmotion/rcalibration","owner":"devmotion","description":"Estimation and hypothesis tests of calibration in R using CalibrationErrors.jl and CalibrationTests.jl. ","archived":false,"fork":false,"pushed_at":"2022-02-12T22:40:33.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-16T13:12:19.551Z","etag":null,"topics":["calibration","julia-language","r-language","reliability"],"latest_commit_sha":null,"homepage":"https://devmotion.github.io/CalibrationErrors.jl/dev","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devmotion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-03T23:46:23.000Z","updated_at":"2022-01-29T01:35:50.000Z","dependencies_parsed_at":"2022-09-18T04:11:46.259Z","dependency_job_id":null,"html_url":"https://github.com/devmotion/rcalibration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devmotion/rcalibration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2Frcalibration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2Frcalibration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2Frcalibration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2Frcalibration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devmotion","download_url":"https://codeload.github.com/devmotion/rcalibration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2Frcalibration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28977318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T11:31:13.034Z","status":"ssl_error","status_checked_at":"2026-02-01T11:30:25.558Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calibration","julia-language","r-language","reliability"],"created_at":"2024-10-01T12:50:34.469Z","updated_at":"2026-02-01T11:33:56.309Z","avatar_url":"https://github.com/devmotion.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rcalibration\n\nEstimation and hypothesis tests of calibration in R using CalibrationErrors.jl and CalibrationTests.jl.\n\n[![Stable](https://img.shields.io/badge/Julia%20docs-stable-blue.svg)](https://devmotion.github.io/CalibrationErrors.jl/stable)\n[![Dev](https://img.shields.io/badge/Julia%20docs-dev-blue.svg)](https://devmotion.github.io/CalibrationErrors.jl/dev)\n[![R-CMD-check](https://github.com/devmotion/rcalibration/workflows/R-CMD-check/badge.svg?branch=main)](https://github.com/devmotion/rcalibration/actions?query=workflow%3AR-CMD-check+branch%3Amain)\n[![CalibrationErrors.jl Status](https://img.shields.io/github/workflow/status/devmotion/CalibrationErrors.jl/CI/main?label=CalibrationErrors.jl)](https://github.com/devmotion/CalibrationErrors.jl/actions?query=workflow%3ACI+branch%3Amain)\n[![CalibrationTests.jl Status](https://img.shields.io/github/workflow/status/devmotion/CalibrationTests.jl/CI/main?label=CalibrationTests.jl)](https://github.com/devmotion/CalibrationTests.jl/actions?query=workflow%3ACI+branch%3Amain)\n\nrcalibration is a package for estimating calibration of probabilistic models in R.\nIt is an R interface for [CalibrationErrors.jl](https://github.com/devmotion/CalibrationErrors.jl) and [CalibrationTests.jl](https://github.com/devmotion/CalibrationTests.jl).\nAs such, the package allows the estimation of calibration errors (ECE and SKCE) and statistical testing of the null hypothesis that a model is calibrated.\n\n## Installation\n\nYou can install `rcalibration` with [`devtools`](https://devtools.r-lib.org/):\n\n```R\n\u003e library(devtools)\n\u003e devtools::install_github(\"devmotion/rcalibration\")\n```\n\nThe use of `rcalibration` requires that its dependency\n[`JuliaCall`](https://github.com/Non-Contradiction/JuliaCall) (installed automatically)\nand itself are configured correctly.\n\nFor `JuliaCall`, you have to\n[install Julia](https://github.com/Non-Contradiction/JuliaCall#installation).\nThe configuration process is described in the\n[`JuliaCall` documentation](https://non-contradiction.github.io/JuliaCall/index.html).\n\nWhen `JuliaCall` is configured correctly, you can install the Julia packages required by\n`rcalibration`:\n\n```R\n\u003e library(rcalibration)\n\u003e rcalibration::install()\n```\n\n### Crash on MacOS with Julia 1.6\n\nDue to a [problem in Julia 1.6](https://github.com/JuliaLang/julia/issues/40246), `JuliaCall`\nand `rcalibration` crash on MacOS with this Julia version. Please use Julia 1.5 on MacOS\nuntil this issue is fixed.\n\n### Custom Julia environment\n\nWith the default settings, `JuliaCall` and `rcalibration` install all Julia dependencies\nin the default environment. In particular, if you use Julia for other projects as well,\na separate [project environment](https://pkgdocs.julialang.org/v1/environments/) can\nsimplify package management and ensure that the state of the Julia dependencies is\nreproducible. In `JuliaCall` and `rcalibration`, a custom project environment is used if\nyou set the environment variable `JULIA_PROJECT`:\n\n```shell\nexport JULIA_PROJECT=\"path/to/the/environment/\"\n```\n\n## Usage\n\nImport and setup calibration analysis tools from CalibrationErrors.jl and CalibrationTests.jl with\n```R\n\u003e ca \u003c- rcalibration::load()\n```\n\nYou can then do the same as would be done in Julia, except you have to add `ca$` in front for functionality from the Julia packages.\nMost of the commands will work without any modification.\nThus the documentation of the Julia packages is the main in-depth documentation for this package.\n\n### Callable objects\n\nR does not support the callable object syntax that is a common idiom in Julia.\n`JuliaCall` supports the\n[syntax `f$.(x)` in R for the function call `f(x)`](https://github.com/Non-Contradiction/JuliaCall/pull/118#issuecomment-534203455)\nwith callable object `f` in Julia.\n\n### Calibration errors\n\nLet us estimate the squared kernel calibration error (SKCE) with the tensor\nproduct kernel\n```math\nk((p, y), (p̃, ỹ)) = exp(-|p - p̃|) δ(y - ỹ)\n```\nfrom a set of predictions and corresponding observed outcomes.\n\n```R\n\u003e skce \u003c- ca$SKCE(ca$tensor(ca$ExponentialKernel(), ca$WhiteKernel()))\n```\n\nOther estimators of the SKCE and estimators of other calibration errors such\nas the expected calibration error (ECE) are available as well. The Julia package\n[KernelFunctions.jl](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl)\nsupports a variety of kernels, all compositions and transformations of\n[kernels available there](https://juliagaussianprocesses.github.io/KernelFunctions.jl/stable/kernels/)\ncan be used.\n\n#### Probabilities\n\nPredictions can be provided as probabilities. In this case, the\npredictions correspond to Bernoulli distributions with these parameters and the\ntargets are boolean values.\n\n```R\n\u003e set.seed(1234)\n\u003e predictions \u003c- runif(100)\n\u003e outcomes \u003c- sample(c(TRUE, FALSE), 100, replace=TRUE)\n\u003e skce$.(predictions, outcomes)\n[1] 0.01518318\n```\n\n#### Probability vectors\n\nPredictions can be provided as probability vectors (i.e., vectors in the probability\nsimplex) as well. In this case, the predictions correspond to categorical\ndistributions with these class probabilities and the targets are integers in `{1,...,n}`.\nThe probability vectors can be given as a matrix. However, it is\nrequired to specify if the probability vectors correspond to rows or columns of the matrix\nby wrapping them in `ca.RowVecs` and `ca.ColVecs`, respectively. These wrappers are defined\nin [KernelFunctions.jl](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl).\n\n```R\n\u003e library(extraDistr)\n\u003e set.seed(1234)\n\u003e predictions \u003c- rdirichlet(100, c(3, 2, 5))\n\u003e outcomes \u003c- sample(1:3, 100, replace=TRUE)\n\u003e skce$.(ca$RowVecs(predictions), outcomes)\n[1] 0.02585344\n```\n\n#### Probability distributions\n\nPredictions can also be provided as probability distributions defined in the\nJulia package [Distributions.jl](https://github.com/JuliaStats/Distributions.jl). Currently,\nanalytical formulas for the estimators of the SKCE and unnormalized calibration mean embedding\n(UCME) are implemented for uni- and multivariate normal distributions `ca$Normal` and\n`ca$MvNormal` with squared exponential kernels on the target space and Laplace distributions\n`ca$Laplace` with exponential kernels on the target space.\n\nIn this example we use the tensor product kernel\n```math\nk((p, y), (p̃, ỹ)) = exp(-W₂(p, p̃)) exp(-(y - ỹ)²/2),\n```\nwhere `W₂(p, p̃)` is the 2-Wasserstein distance of the two normal distributions `p` and `p̃`.\nIt is given by\n```math\nW₂(p, p̃) = √((μ - μ̃)² + (σ - σ̃)²),\n```\nwhere `p = N(μ, σ)` and `p̃ = N(μ̃, σ̃)`.\n\n```R\n\u003e set.seed(1234)\n\u003e predictions \u003c- replicate(100, ca$Normal(rnorm(1), runif(1)))\n\u003e outcomes \u003c- rnorm(100)\n\u003e skce \u003c- ca$SKCE(ca$tensor(ca$ExponentialKernel(metric=ca$Wasserstein()), ca$SqExponentialKernel()))\n\u003e skce$.(predictions, outcomes)\n[1] 0.02301165\n```\n\n### Calibration tests\n\n`rcalibration` provides different calibration tests that estimate the p-value of the null hypothesis\nthat a model is calibrated, based on a set of predictions and outcomes:\n- `ca$ConsistencyTest` estimates the p-value with consistency resampling for a given calibration error estimator\n- `ca$DistributionFreeSKCETest` computes distribution-free (and therefore usually quite weak) upper bounds of the p-value for different estimators of the SKCE\n- `ca$AsymptoticBlockSKCETest` estimates the p-value based on the asymptotic distribution of the unbiased block estimator of the SKCE\n- `ca$AsymptoticSKCETest` estimates the p-value based on the asymptotic distribution of the unbiased estimator of the SKCE\n- `ca$AsymptoticCMETest` estimates the p-value based on the asymptotic distribution of the UCME\n\n```R\n\u003e library(extraDistr)\n\u003e set.seed(1234)\n\u003e predictions \u003c- rdirichlet(100, c(3, 2, 5))\n\u003e outcomes \u003c- sample(1:3, 100, replace=TRUE)\n\u003e test \u003c- ca$AsymptoticSKCETest(kernel, ca$RowVecs(predictions), outcomes)\n\u003e print(test)\nJulia Object of type AsymptoticSKCETest{KernelTensorProduct{Tuple{ExponentialKernel{TotalVariation}, WhiteKernel}}, Float64, Float64, Matrix{Float64}}.\nAsymptotic SKCE test\n--------------------\nPopulation details:\n    parameter of interest:   SKCE\n    value under h_0:         0.0\n    point estimate:          0.0259434\n\nTest summary:\n    outcome with 95% confidence: reject h_0\n    one-sided p-value:           0.0100\n\nDetails:\n    test statistic: -0.007291403994633658\n\u003e ca$pvalue(test)\n[1] 0.004\n```\n\n## Citing\n\nIf you use rcalibration as part of your research, teaching, or other activities, please consider citing the following publications:\n\nWidmann, D., Lindsten, F., \u0026 Zachariah, D. (2019). [Calibration tests in multi-class classification: A unifying framework](https://proceedings.neurips.cc/paper/2019/hash/1c336b8080f82bcc2cd2499b4c57261d-Abstract.html). In *Advances in Neural Information Processing Systems 32 (NeurIPS 2019)* (pp. 12257–12267).\n\nWidmann, D., Lindsten, F., \u0026 Zachariah, D. (2021). [Calibration tests beyond classification](https://openreview.net/forum?id=-bxf89v3Nx). *International Conference on Learning Representations (ICLR 2021)*.\n\n## Acknowledgements\n\nThis work was financially supported by the Swedish Research Council via the projects *Learning of Large-Scale Probabilistic Dynamical Models* (contract number: 2016-04278), *Counterfactual Prediction Methods for Heterogeneous Populations* (contract number: 2018-05040), and *Handling Uncertainty in Machine Learning Systems* (contract number: 2020-04122), by the Swedish Foundation for Strategic Research via the project *Probabilistic Modeling and Inference for Machine Learning* (contract number: ICA16-0015), by the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation, and by ELLIIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmotion%2Frcalibration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevmotion%2Frcalibration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmotion%2Frcalibration/lists"}