Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python OLS model: __init__() missing 1 required positional argument: 'endog'

import statsmodels.api as sm
xdat = rets['EUROSTOXX']
xdat = sm.add_constant(xdat)
ydat = rets['VSTOXX']
model = sm.OLS(y=ydat,x=xdat).fit()

I don't understand why there is an error popping up as stated on the topic. The following is the tail of the Dataframe of rets

Out[105]:
            EUROSTOXX   VSTOXX
2014-12-23  0.011835    -0.039307
2014-12-24  -0.002449   0.000000
2014-12-29  0.000160    0.121598
2014-12-30  -0.015574   0.048998
2014-12-31  0.003336    0.000000
like image 835
user8417321 Avatar asked Dec 26 '17 12:12

user8417321


People also ask

How to fix Python TypeError __init__() missing 1 required positional argument?

The Python "TypeError: __init__() missing 1 required positional argument" occurs when we forget to provide a required argument when instantiating a class. To solve the error, specify the argument when instantiating the class or set a default value for the argument.

Why does Python say missing 1 required positional argument ‘self’?

Python classes need to be instantiated, or called, before you can access their methods. If you forget to instantiate an object of a class and try to access a class method, you encounter an error saying “missing 1 required positional argument: ‘self’”. In this guide, we talk about what this error means and why it is raised.

Why is my positional argument missing from my class?

The “missing 1 required positional argument: ‘self’” error can occur when you incorrectly instantiate a class. Consider the following code: While this code is similar to our solution from the last example, it is incorrect. This is because we have not added any parenthesis after the word Hero.

What is the required positional argument in JavaScript?

missing 1 required positional argument: ‘self’ Positional arguments refer to data that is passed into a function. In a class, every function must be given the value “ self ”. The value of “self” is similar to “this” in JavaScript. “self” represents the data stored in an object of a class.


1 Answers

According to the documentation of OLS, the function's parameters aren't called y and x, but endog and exog. You can simply change your function call to:

model = sm.OLS(ydat, xdat).fit()

or:

model = sm.OLS(endog=ydat, exog=xdat).fit()
like image 136
Glenn D.J. Avatar answered Nov 15 '22 04:11

Glenn D.J.