This Python package provides bindings for the well-known weighted orthogonal distance regression (ODR) solver odrpack95. This design ensures that users benefit from the performance and reliability of the original Fortran implementation, while working within the modern Python ecosystem.
ODR, also known as errors-in-variables regression, is designed primarily for instances when both the explanatory and response variables have significant errors.
You can install the package via pip:
pip install odrpack
The following example demonstrates a simple use of the package. For more comprehensive examples and explanations, please refer to the documentation pages.
from odrpack import odr
import numpy as np
x = np.array([0.982, 1.998, 4.978, 6.01])
y = np.array([2.7, 7.4, 148.0, 403.0])
beta0 = np.array([2., 0.5])
lower = np.array([0., 0.])
upper = np.array([10., 0.9])
def f(beta: np.ndarray, x: np.ndarray) -> np.ndarray:
"Model function."
return beta[0] * np.exp(beta[1]*x)
sol = odr(f, beta0, y, x, lower=lower, upper=upper, iprint=1001)
print("beta:", sol.beta)
print("delta:", sol.delta)
beta: [1.63337057 0.9 ]
delta: [-0.36885787 -0.31272733 0.02928942 0.11031791]