Converting statsmodels summary object to Pandas Dataframe

The answer from @Michael B works well, but requires “recreating” the table. The table itself is actually directly available from the summary().tables attribute. Each table in this attribute (which is a list of tables) is a SimpleTable, which has methods for outputting different formats. We can then read any of those formats back as a … Read more

Highest Posterior Density Region and Central Credible Region

From my understanding “central credible region” is not any different from how confidence intervals are calculated; all you need is the inverse of cdf function at alpha/2 and 1-alpha/2; in scipy this is called ppf ( percentage point function ); so as for Gaussian posterior distribution: >>> from scipy.stats import norm >>> alpha = .05 … Read more

What’s the difference between pandas ACF and statsmodel ACF?

The difference between the Pandas and Statsmodels version lie in the mean subtraction and normalization / variance division: autocorr does nothing more than passing subseries of the original series to np.corrcoef. Inside this method, the sample mean and sample variance of these subseries are used to determine the correlation coefficient acf, in contrary, uses the … Read more

How to extract the regression coefficient from statsmodels.api?

You can use the params property of a fitted model to get the coefficients. For example, the following code: import statsmodels.api as sm import numpy as np np.random.seed(1) X = sm.add_constant(np.arange(100)) y = np.dot(X, [1,2]) + np.random.normal(size=100) result = sm.OLS(y, X).fit() print(result.params) will print you a numpy array [ 0.89516052 2.00334187] – estimates of intercept … Read more

confidence and prediction intervals with StatsModels

For test data you can try to use the following. predictions = result.get_prediction(out_of_sample_df) predictions.summary_frame(alpha=0.05) I found the summary_frame() method buried here and you can find the get_prediction() method here. You can change the significance level of the confidence interval and prediction interval by modifying the “alpha” parameter. I am posting this here because this was … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)