是否可以在多元回归拟合中使用正交距离回归,其中 1 个自变量被完美测量(即没有不确定性)?
这是我的意思的一个例子:
y
是x_0
和x_1
的函数。 y
和 x_1
都是带有不确定性的测量,但是 x_0
没有不确定性(例如测量日期)。为了表示这一点,我将 x_0
的不确定性设置为零数组。我用这段代码来评估我的问题:
import numpy as np
from scipy import odr
def model_test(B, x):
x_0, x_1 = x[0], x[1]
return B[0]*x_0 + B[1]*x_1**2 + B[2]
N = 1000
x_0 = np.linspace(0, 100, N)
x_1 = np.linspace(0, 100, N)
x = np.row_stack([x_0, x_1])
sx = np.row_stack([np.full(N, 0.0), np.random.random(N)])
sy = np.random.random(N)
y = model_test([3.0, 4.0, 5.0], x)
model = odr.Model(model_test)
data = odr.RealData(x = x, y = y, sx = sx, sy = sy)
odr_test = odr.ODR(data = data, model = model, beta0 = [1.0, 2.0, 3.0])
output = odr_test.run()
output.pprint()
当我尝试运行它时,我得到一个被零除的错误:
RuntimeWarning: divide by zero encountered in true_divide
return 1./numpy.power(sd, 2)
Beta: [nan nan nan]
Beta Std Error: [0. 0. 0.]
Beta Covariance: [[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
Residual Variance: 0.0
Inverse Condition #: 0.001067101765072725
Reason(s) for Halting:
Numerical error detected
我定义变量的方式是否存在问题,或者这是 ODR 的基本限制?如果是后者,还有哪些其他方法可以用于此目的?