I have the following R code with binomial regression to fit the y and polynomial of x
res = glm(df.mat ~ poly(x, deg=degree), family=binomial(link="logit"))
and the result is
However, when I use the statsmodels GLM function in Python as
import statsmodels.api as sm
def poly(x, d):
x = np.array(x)
X = np.transpose(np.vstack((x**k for k in range(d+1))))
return np.linalg.qr(X)[0][:,1:]
res_m = sm.GLM(np.array(df_mat), poly(x, 7), family = sm.families.Binomial())
result = res_m.fit()
with the polynomial function created by Python equivalent to R poly() function? then the result is
poly
calculation or the GLM fitting (or both). Have you compared the result of R'spoly(x, deg = degree)
with Python'spoly(x, 7)
to see if the issue is there? If you need more help than that, you should probably post some sample data. – Gregor Thomasreturn np.linalg.qr(X)[0]
– Josef