Is there a Python Statsmodels OLS function to get only the statistical significant coefficients after fit a regression?

Viewed 2341

I have fit a linear regression using the OLS.fit() function of Statsmodels, obtained the estimated coefficients and corresponding p-values by calling the .params and .pvalues of the results classes.

Among the obtained parameters, few of them are statistically significant (i.e. at 5% significance level), is there any function can return the significant parameters only?

Have tried calling the .params after fitting the OLS, but this returns ALL coefficients.

Y = [1,3,4,5,2,3,4,20,100]
X1 = range(1,10)
X1 = sm.add_constant(X1)
results = sm.OLS(Y,X1).fit()
print(results.summary())
results.params
results.pvalues

Actual results:

results.params returned:
array([-21.30555556,   7.41666667])

results.pvalues returned:
array([0.30606981, 0.06733325])

Expected results:

Only return the params 7.41666667, since the corresponding p-value is significant at 10%, 0.06733325 is smaller than 10%

0 Answers
Related