Skip to main content

roxy

roxy:

Regression and Optimisation with X and Y errors

Authors:

Deaglan J. Bartlett and Harry Desmond

Homepage:

https://github.com/DeaglanBartlett/roxy

Documentation:

https://roxy.readthedocs.io/en/latest/

Documentation Status https://img.shields.io/badge/astro.CO-arXiv%32309.00948-B31B1B.svg Unit tests Coverage

Build Status Build Status MacOS Build Status Windows

About

roxy (Regression and Optimisation with X and Y errors) is a python package for fitting a function to data (regression) where the data have both x and y errors, using Markov Chain Monte Carlo (MCMC). The common approach for this problem is to use a Gaussian likelihood with a mean given by \(f(x_{\rm obs}, \theta)\) and a variance \(\sigma_y^2 + f^\prime(x_{\rm obs}, \theta)^2 \sigma_x^2\), but this ignores the underlying distribution of true x values and thus gives biased results. Instead, this package allows one to use the MNR (Marginalised Normal Regression) method which does not exhibit such biases. A range of likelihoods are available in roxy, however we recommed you use the following one in these situations:

  • If you have \(x\) and \(y\) errors and DO wish to infer intrinsic scatter: use method='mnr'.

  • If you have \(x\) and \(y\) errors and DO NOT wish to infer intrinsic scatter: use method='prof'.

  • If you only have \(y\) errors: use method='prof' or method='unif' (they are identical in this case).

The code uses automatic differentiation enabled by jax to both sample the likelihood using Hamiltonian Monte Carlo and to compute the derivatives required for the likelihood. We employ the NUTS method implemented in numpyro for fast sampling. For the galaxy cluster example in the MNR paper (which contains over 250 data points), a single chain run on a laptop performs approximately 3500 iterations per second, such that a chain with 700 warm-up steps and 5000 samples takes approximately 1.6 seconds to sample, and gives over 3500 effective samples for each of the parameters, with Gelman Rubin statistics equal to unity within less than 0.01. Given its efficiency and simplicity to use (one need to just define the function of interest, the parameters to sample and their prior ranges), we advocate for its use not just in the presence of x errors, but also without these.

As well as returning posterior samples and allowing likelihood computations (which can be integrated into the user’s larger code), roxy is interfaced with arviz to produce trace plots, corner and getdist to make two-dimensional posterior plots, and fgivenx for posterior predictive plots. See below for the relevant citations one must use if one uses these modules.

Installation

Installing

roxy requires python 3.12 or later; we test it with python 3.12 and 3.13. To install the latest release from PyPI, run

pip install roxy-regression

Note that the package is called roxy-regression on PyPI, but is imported as roxy (e.g. from roxy.regressor import RoxyRegressor). Installing it also installs the runtime dependencies: numpy, scipy, jax, numpyro, jaxopt, scikit-learn, matplotlib, corner, getdist, arviz and fgivenx.

We recommend installing into a fresh virtual environment, for example

python3 -m venv roxy_env
source roxy_env/bin/activate
pip install roxy-regression

Optional extras

If one wants to reproduce the results of the roxy paper, one needs to run the example given in examples/bias_example.py, which requires mpi4py. This is not installed by default, and needs MPI to be installed beforehand:

MacOS:

brew install open-mpi

Ubuntu:

sudo apt-get install openmpi-bin libopenmpi-dev

after which mpi4py can be installed alongside roxy with

pip install "roxy-regression[mpi]"

Development version

To install the development version from GitHub, with the tools needed to build the documentation and run the tests, run

git clone https://github.com/DeaglanBartlett/roxy.git
pip install -e "roxy[docs,test]"

and then run the tests with pytest roxy/tests.

Licence and Citation

Users are required to cite the roxy paper, for which the following bibtex can be used

@ARTICLE{roxy,
  author = {{Bartlett}, D.~J. and {Desmond}, H.},
  title = "{Marginalised Normal Regression: Unbiased curve fitting in the presence of x-errors}",
  eprint = "2309.00948",
  archivePrefix = "arXiv",
  primaryClass = "stat.ME",
  doi = "10.21105/astro.2309.00948",
  journal = "Open J. Astrophys.",
  volume = "6",
  pages = "astro.2309.00948",
  year = "2023"
}

and are encourgaed to cite the numpyro papers

@ARTICLE{numpyro1,
      title={Composable Effects for Flexible and Accelerated Probabilistic Programming in NumPyro},
      author={Phan, Du and Pradhan, Neeraj and Jankowiak, Martin},
      journal={arXiv preprint arXiv:1912.11554},
      year={2019}
  }
@ARTICLE{numpyro2,
      author    = {Eli Bingham and
             Jonathan P. Chen and
             Martin Jankowiak and
             Fritz Obermeyer and
             Neeraj Pradhan and
             Theofanis Karaletsos and
             Rohit Singh and
             Paul A. Szerlip and
             Paul Horsfall and
             Noah D. Goodman},
      title     = {Pyro: Deep Universal Probabilistic Programming},
      journal   = {J. Mach. Learn. Res.},
      volume    = {20},
      pages     = {28:1--28:6},
      year      = {2019},
      url       = {http://jmlr.org/papers/v20/18-403.html}
  }

Additionally, if you use the function roxy.plotting.posterior_predictive_plot, then, as this used the fgivenx package, you must cite

@article{fgivenx,
    doi = {10.21105/joss.00849},
    url = {http://dx.doi.org/10.21105/joss.00849},
    year  = {2018},
    month = {Aug},
    publisher = {The Open Journal},
    volume = {3},
    number = {28},
    author = {Will Handley},
    title = {fgivenx: Functional Posterior Plotter},
    journal = {The Journal of Open Source Software}
}

We also provide simple routines to plot posterior distribtuions with roxy.plotting.triangle_plot. If you use module="corner" with this function, please cite

@article{corner,
     doi = {10.21105/joss.00024},
     url = {https://doi.org/10.21105/joss.00024},
     year  = {2016},
     month = {jun},
     publisher = {The Open Journal},
     volume = {1},
     number = {2},
     pages = {24},
     author = {Daniel Foreman-Mackey},
     title = {corner.py: Scatterplot matrices in Python},
     journal = {The Journal of Open Source Software}
 }

and if you use module="getdist", please cite

@article{getdist,
   author         = "Lewis, Antony",
   title          = "{GetDist: a Python package for analysing Monte Carlo
                     samples}",
   year           = "2019",
   eprint         = "1910.13970",
   archivePrefix  = "arXiv",
   primaryClass   = "astro-ph.IM",
   SLACcitation   = "%%CITATION = ARXIV:1910.13970;%%",
   url            = "https://getdist.readthedocs.io"
  }

MIT License

Copyright (c) 2023–2026 Deaglan John Bartlett

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors

Below is a list of contributors to this repository.

Deaglan Bartlett (CNRS & Sorbonne Université, Institut d’Astrophysique de Paris and Astrophysics)

Harry Desmond (Institute of Cosmology & Gravitation, University of Portsmouth)

Documentation

The documentation for this project can be found at this link

Acknowledgements

DJB is supported by the Simons Collaboration on “Learning the Universe.”

HD is supported by a Royal Society University Research Fellowship (grant no. 211046).

Metadata

Release files for roxy-regression 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for roxy-regression 1.0.1
File Size Uploaded Provenance Actions
roxy_regression-1.0.1.tar.gz 37.3 kB With provenance Details for roxy_regression-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for roxy-regression 1.0.1
File Interpreter ABI Platform Actions
roxy_regression-1.0.1-py3-none-any.whl Python 3 none any Details for roxy_regression-1.0.1-py3-none-any.whl

Total release size: 68.3 kB

Release files / roxy_regression-1.0.1.tar.gz

Download URL roxy_regression-1.0.1.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7cfe2eebd1c53b585cc0d67921abd4ce80fa0ebd3c461f0cc1044a8d9dad5da1
BLAKE2b-256 checksum
How to use checksums
2bcfa4cfa71e5fc0a9a03372505315bd3a265b64525a83251dcefbe14330e1ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / roxy_regression-1.0.1-py3-none-any.whl

Download URL roxy_regression-1.0.1-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73b2dd346a8c4a6c53496c3a28fb9d64c24820fb56d9efb02bb7b9c1deadc5f9
BLAKE2b-256 checksum
How to use checksums
39268478ccc90390dae0ae61f266e62028e5aafab20a7e12bc49eebe9dedcadf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for roxy-regression 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for roxy_regression-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page