## 15.4 Complex linear regression

Complex valued linear regression with complex predictors and regression coefficients looks just like standard regression. For example, if we take x to be predictors, y to be an array of outcomes. For example, consider the following complete Stan program for an intercept and slope.

data {
int<lower=0> N;
complex_vector[N] x;
complex_vector[N] y;
}
parameters {
complex alpha;
complex beta;
}
model {
complex_vector[N] eps = y - (alpha + beta * x);
eps ~  // ...error distribution...
}

The question remains of how to fill in the error distribution and there are several alternatives. We consider only two simple alternatives, and do not consider penalizing the absolute value of the error.

### 15.4.1 Independent real and imaginary error

The simplest approach to error in complex regression is to give the real and imaginary parts of eps_n independent independent normal distributions, as follows.

parameters {
// ...
vector[2] sigma;
}
// ...
model {
// ...
get_real(eps) ~ normal(0, sigma[1]);
get_imag(eps) ~ normal(0, sigma[2]);
sigma ~ //...hyperprior...
}

A new error scale vector sigma is introduced, and it should itself get a prior based on the expected scale of error for the problem.

### 15.4.2 Dependent complex error

The next simplest approach is to treat the real and imaginary parts of the complex number as having a multivariate normal prior. This can be done by adding a parameter for correlation to the above, or just working with a multivariate covariance matrix, as we do here.

parameters {
cholesky_factor_corr[2] L_Omega;  // correlation matrix
vector[2] sigma;                  // real, imag error scales
// ...
}
// ...
model {
array[N] vector[2] eps_arr;
for (n in 1:N) {
eps_arr[n] = { to_real(eps[n]), to_imag(eps[n]) };
}
eps_arr ~ multi_normal_cholesky([0, 0]',
diag_pre_multiply(sigma, L_Omega));
L_Omega ~ lkj_cholesky(4);  // shrink toward diagonal correlation
sigma ~ // ... hyperprior ...
}

Here, the real and imaginary components of the error get a joint distribution with correlation and independent scales. The error gets a multivariate normal distribution with zero mean and a Cholesky factor representation of covariance, consisting of a scale vector sigma and a Cholesky factor or a correlation matrix, L_Omega. The prior on the correlations is concentrated loosely around diagonal covariance, and the prior on the scales is left open. In order to vectorize the call to multi_normal_cholesky, the vector of complex numbers needs to be converted to an array of size 2 vectors.