2
$\begingroup$

Are there any existing R packages capable of performing a robust linear regression on complex valued data?

I have a set $Y$ of complex valued ($a + b i$) data, that are linearly dependent on another set $X$. I need to find the (complexed valued) slope and intercept of the relationship $Y = m X + b$ that best fits the data.

I've implemented an ordinary least-squares fitting in R, per Whuber's excellent answer. However, there are a significant number of outliers among my data, so this method often fails to give useful results. So I'm looking to use a robust fit instead.

Unfortunately, I haven't been able to find much information on applying such fits to complex data. This paper has the best overview I've seen so far. I have found the rlm function in the MASS library, but it's only set up to handle real numbers. I could modify the source of it to handle them, but I don't really understand it.

Does anyone know of a library that has a robust linear fit function that can handle complex numbers?

$\endgroup$
1
  • $\begingroup$ It is tempting to adapt IRLS (aka IWLS) to the complex case, because it should be straightforward. $\endgroup$
    – whuber
    Commented Aug 2, 2021 at 18:59

1 Answer 1

1
$\begingroup$

Well, there is now.

I've spent the past month or so studying the rlm code in MASS and modifying it to accept complex numbers. It's working now, and the code is available on github: MASS with complex rlm

The functions rlm() and lqs() now accept complex data and return complex fitting parameters. I also ended up modifying the lm.wfit() function from the stats package to accept complex data, renamed it to zlm.wfit(), and included it in the modified MASS package.

There are still some bugs to work out, mainly that rlm(..., method = "MM") often causes R to crash. But otherwise it works pretty well.

From the example script tests/complex_rlm.R,

Let $w$ be a collection of independent variables. Then let, $z.pure = \beta_1 * w + \beta_0$

$z.clean = \beta_1 * w + \beta_0 + \epsilon$

Where $\beta_1$ and $\beta_0$ are complex numbers (slope and intercept), and $\epsilon$ is a set of random complex number that adds error to the dependent variable. Finally let $z$ be $z.clean$ with some of the values replaced by outliers.

The following graphs compare the results of using ordinary regression and robust regression to find the relationship between $w$ and $z$.

Dependent variables z.

Residuals of ordinary and robust complex linear fits.

Comparison of squared residuals.

Clearly, the robust regression is less effected by the outliers, and thus closer to the true relationship.

$\endgroup$
1
  • $\begingroup$ The example looks good, but would you mind explaining how your version actually works? What assumptions does it make and what algorithm(s) does it use? Exactly what form of robustness does it have? $\endgroup$
    – whuber
    Commented Sep 15, 2021 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.