When trying to do orthogonal distance regression for a linear model, the scipy.odr package fails whenever I hand it errors (in x and y) in array shape (as opposed to scalar). The Error is “Problem is not full rank at solution”. It works, as long as these parameters are scalars, but that is not my requirement.
“Not full rank” appears usually when there isn’t sufficient data to describe the model (rank-deficiency). This is not the case for me. Even for simple synthetic data, the problem remains. Also, trying to reproduce the answer here (other ODR issue) does not work for me. I get again the rank error.
This code below is a minumum “working” example:
import numpy as np
from scipy.optimize import curve_fit
import scipy.odr as odr
import matplotlib.pyplot as plt
def odrlin(b,x):
return b[0]*x+b[1]
linmodel = odr.Model(odrlin)
fig,ax = plt.subplots()
x = np.linspace(1,10,10)
y = 2.8*x+4.2
y = y*(1+(np.random.random(len(y))-0.5)*0.2) #some noise in y
xerr, yerr = np.ones(len(x))*x*0.1, np.ones(len(y))*y*0.1 #10 % relative error in x and y
ax.errorbar(x,y,xerr=xerr,yerr=yerr,ls='',marker='.')
#case 1 - functioning
print('case 1')
sx, sy = 0.1, 2
odrdata = odr.RealData(x=x,y=y,sx=sx,sy=sy)
myodr = odr.ODR(odrdata,linmodel,beta0=[2,4])
odrout = myodr.run()
odrout.pprint()
#case 2 - does not work
print('n case 2')
sx, sy = xerr,yerr
odrdata = odr.RealData(x=x,y=y,sx=sx,sy=sy)
myodr = odr.ODR(odrdata,linmodel,beta0=[2,4])
odrout = myodr.run()
odrout.pprint()
#case 3 - does still not work
print('n case 3')
sx, sy = np.ones(len(x))*0.1,np.ones(len(y))*2
odrdata = odr.RealData(x=x,y=y,sx=sx,sy=sy)
myodr = odr.ODR(odrdata,linmodel,beta0=[2,4])
odrout = myodr.run()
odrout.pprint()
SCguy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.