-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression for Complex Numbers #9053
Comments
duplicate of #3528 It's not easy. The main work is to figure out how all the statistics are defined for the complex number case. Internally in statsmodels many models that require nonlinear optimization are defined for complex numbers. This is implemented to support complex step derivatives. I would review and merge a PR for, for example, an OLSComplex model, but I don't have the time to figure this out on my own and go in details through the literature like those referenced in #3528 Do you know other packages that implement regression for complex variables that could be used for unit tests? |
Dear Josef, ok, reading your post, I now understand why it is not that easy. Well, I need to admit, being only a user of these great modules, so I do not understand to good about the internal problems. Some reduced, simplyfied model als "OLSComplex" does sound good to me. However, I do not have ready unittests at hand... As a starting point however: All unittests for real-numbers models should pretty much work, if any dependent and independent variable is multiplied with a fixed complex number. |
I was just suprised to see, that at least the OLS model works fine for simple regression on complex numbers, as long as you don't call results.summary. (Only when "summary" ist called, lots of errors due to complex->real-coercion appear). |
parameter estimation works, mainly because the linear algebra automatically handles it. But the other results like standard errors, inferential statistics like p-values and similar are not appropriate. |
Support for complex numbers for linear regression
In vibration engineering complex numbers are a big deal, since vibration at a given frequency can be represented by them.
Moreover, doing linear regression is often needed to fit some vibration-system-model against observed excitation and response. This is used especially for field-balancing.
However, statsmodels refuses to work with complex numbers. They get casted/coerced to float numers (real-part) at serveral locations in code, hence resulting in unvalid results.
In mathematics, however, using C (complex) instead of R (real) would not make any difference to all formulas of linear regression; at least long, as a proper metric / abs() is defined. Thus, changing statsmodels to also work with complex numbers would probably be only minor changes.
As a side note: I am well aware, that any complex number could be represented by two real numbers. However, transforming a complex regression problem into a real/float regression problem of double dimension, yields NOT the same solution (why: in short, there are double as much degrees of freedom/parameters for the fitting matrix. In complex fitting of one-dim there are only TWO parameters (real and imag of linear factor), while in transformed 2x2-real-domain it is FOUR parameters (4 real values of a 2x2 matrix). So, complex problems cannot be simply converted to doing regression in real-space.
Finally, I would ask for the feature to open statsmodels to also seamlessly work with standard Python complex numbers.
The text was updated successfully, but these errors were encountered: