bikuser - 1 month ago 11

Python Question

As I understood, Regression equation can be calculated by this functions:

`import statsmodels.formula.api as smf`

fg = smf.ols(formula='X ~ Y', data=data).fit()

we can also calculate from numpy polyfit function.

`numpy.polyfit(x, y, degree)`

as we can change the degree in numpy polyfit.

In ols function we can also add other independent variables as given below:

`fg = smf.ols(formula='X ~ Y+Y1+Y2', data=data).fit()`

So my question can we change the order/degree of fit in ols function ?

or can we add another independent variables in numpy polyfit function?

Answer

In the case of the statsmodels ability that you mention, formulae are specified using the patsy language (see http://patsy.readthedocs.io/en/latest/). Thus, for instance, that first invocation that you used could instead have been the following.

```
fg = smf.ols(formula='X ~ Y + Y**2', data=data).fit()
```

or

```
fg = smf.ols(formula='X ~ log(Y)', data=data).fit()
```