I'm having some issues with getting the standard errors, t-statistics, p-values and 95% confidence intervals of the Huber Regression parameters in Scikit-Learn. All I can return is intercept and coefficients but nothing else.
solution = HuberRegressor()
solution.fit(beta_fac2, B)
print(solution.intercept_)
print(solution.coef_)
I tried implementing the solution from this answer:
params = np.append(solution.intercept_,solution.coef_)
predictions = solution.predict(beta_fac2)
newX = np.append(np.ones((len(beta_fac2),1)), beta_fac2, axis=1)
MSE = (sum((B-predictions)**2))/(len(newX)-len(newX[0]))
var_b = MSE*(np.linalg.inv(np.dot(newX.T,newX)).diagonal())
sd_b = np.sqrt(var_b)
ts_b = params/ sd_b
p_values =[2*(1-stats.t.cdf(np.abs(i),(len(newX)-len(newX[0])))) for i in ts_b]
sd_b = np.round(sd_b,3)
ts_b = np.round(ts_b,3)
p_values = np.round(p_values,3)
params = np.round(params,4)
myDF3 = pd.DataFrame()
myDF3["Coefficients"],myDF3["Standard Errors"],myDF3["t values"],myDF3["Probabilities"] = [params,sd_b,ts_b,p_values]
print(myDF3)
but this line of code
var_b = MSE*(np.linalg.inv(np.dot(newX.T,newX)).diagonal())
returns an error:
numpy.linalg.LinAlgError: Singular matrix