0
import numpy as np
import statsmodels.api as sm

n = 50
np.random.seed(42)
x = np.random.rand(n)
y = np.random.rand(n) + 1

X2 = sm.add_constant(x)
est = sm.OLS(y, X2).fit()
print(est.summary())

est.summary() gives me a nice printout of many summary statistics of my data. But I would like to retrieve the actual values of R^2 and the p-values (in this case, just the pvalue listed for x1). Something like:

pValue = est.pvalue()
R_squared = est.rsquared()

Is there a simple way to do this?

Forklift17
  • 2,245
  • 3
  • 20
  • 32
  • 1
    Does this answer your question? [How to get the P Value in a Variable from OLSResults in Python?](https://stackoverflow.com/questions/41075098/how-to-get-the-p-value-in-a-variable-from-olsresults-in-python) – Fabrizio Jul 27 '20 at 10:45
  • Indirectly. dir(est2) gave me what I needed, which was ```est2.rsquared```. – Forklift17 Jul 27 '20 at 17:14

0 Answers0