Solved – How to get regression equation from statsmodel (python)

multiple regressionpythonregressionstatsmodels

I am poor in statistics. I did a multiple linear regression in python by using statsmodels. I know that I can transform a non-linear relation into a linear relation in different ways using this model. Combinations of different independent variables are shown in below:

smf.ols(formula = 'y ~ a + I(a**2) + log(b) + c + d', data=data).fit()

where $y$ is a dependent variable depends on second degree polynomial of $a$, log of $b$ and linear in $c$ and $d$.

My question is in such a case what will my equation be?

Best Answer

If I understand your question, you're asking for the model form:

$$y = \alpha + \beta_0a + \beta_1a^2 + \beta_2\log(b) + \beta_3c + \beta_4d + \epsilon$$

where:

  • $\epsilon \sim N(0,\sigma^2)$ is the OLS assumption
  • $a,b,c,d$ are in your data
  • $\beta_0,...\beta_4$ are your coefficients. $\alpha$ is the intercept which is added automatically when you use formulas, unless specified otherwise (by including a -1 in the formula).

See here for more on how Python formulas work.

Related Question