Skip to content Skip to sidebar Skip to footer

Statsmodels Summary To Latex

I'm a newbie to latex and I want to import a statsmodels(python-package) summary to my report in latex. I found that it's possible to transform a summary into a latex tabular with

Solution 1:

That seems to be a misunderstanding. You can either convert a whole summary into latex via summary.as_latex() or convert its tables one by one by calling table.as_latex_tabular() for each table.

The following example code is taken from statsmodels documentation. Note that you cannot call as_latex_tabular on a summary object.

import numpy as np
import statsmodels.api as sm

nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)

X = sm.add_constant(X)
y = np.dot(X, beta) + e

model = sm.OLS(y, X)
results = model.fit()

# do either
print(results.summary().as_latex())

# alternatively
for table in results.summary().tables:
    print(table.as_latex_tabular())

Post a Comment for "Statsmodels Summary To Latex"