# Calculating standard errors of non-OLS regressions in python and scipy [closed]

Scipy/statsmodels provides the ability to get a number of metrics from the output of an OLS regression model, a few examples of which (from statsmodels) are the following:

model = sm.OLS(y, x).fit()
results = model.params
SE = model.bse
r2 = model.rsquared


The variable "results" gives you the parameters for the slope and intercept, "SE" gets you the standard error of the intercept and slope, and "r2" gets you the r-squared of the regression.

I am, however, working with a few additional Scipy/statsmodels packages that don't have these output estimates. Specifically, I am looking to get the standard errors of the intercept and slope for the Theil-Sen regression and Siegel regression. The reason I want these standard errors is so I can create a confidence interval of my predictions, and standard error is one of the inputs to that calculation. I know Theil-Sen gives you the confidence interval of the slope, but I would like to have these standard errors in addition to this output. It seems I have to do this manually instead of simply calling:

model.bse


I have been looking up options for manually calculating these standard errors for way too long, and I have tried numerous different options, all of which produce drastically different results. I am wondering whether there are packages in Python that will provide the standard errors that I'm looking for without having to manually calculate standard errors?

Or if someone knows how Scipy/statsmodels calculates the standard errors for OLS, would you be able to explain how that is done or where I can find resources that discuss the formula they use?

If not, would anyone be able to provide me, what they believe, to be the standard formulas to calculate each standard error? I'm unsure why this has been so difficult, as almost every online source has different ways of calculating standard errors for the slope and intercept.

UPDATE:

If I'm way off the mark with this request, I would appreciate someone letting me know and/or directing me to resources that could help me further my understanding, as there have been a number of views on this post but no interaction with it. This request may just relate to a misunderstanding of what I'm looking to get done, but I have a feeling there is something here to discuss. And please feel free to ask clarifying questions if needed.

• I think if you rewrote your question to be oriented around the statistical content, it would be a better fit for stats.SE: Instead of asking "how do I __ in python?", ask "how do I compute the standard error for a Theil-Sen model?" – Sycorax says Reinstate Monica Jun 21 '19 at 15:49