In standard Lomb-Scargle, we start with values
$$ \{t,y,dy\} $$We then compute the mean of the $y$ values using the maximum likelihood:
$$ \mu_y = \frac{\sum_i y_i/dy_i^2}{\sum_i 1/dy_i^2} $$Then we compute the centered $y$:
$$ \bar{y} \equiv y - \mu_y $$The model is a simple 1-term sinusoid given by
$$ M(t,\omega~|~\theta) = \theta_0 \sin(\omega t) + \theta_1\cos(\omega t) $$The likelihood for the dataset is
$$ L(\{t,y,dy\},\omega~|~\theta) = \sum_i \frac{1}{\sqrt{2\pi dy_i^2}} \exp\left[ \frac{-(y_i - M(t_i,\omega~|~\theta)^2}{2dy_i^2} \right] $$Which leads to the chi-squared function (derived from the log-likelihood)
$$ \chi^2(\omega, \theta) = \sum_i\frac{(\bar{y}_i - M(t_i,\omega~|~\theta)^2}{2dy_i^2} $$If we re-express the model by defining
$$ X_\omega = \left[ \begin{array}{ll} \sin(\omega t_1) & \cos(\omega t_1)\\ \sin(\omega t_2) & \cos(\omega t_2)\\ \vdots & \vdots \\ \sin(\omega t_N) & \cos(\omega t_N)\\ \end{array} \right],~~~~ y = \left[ \begin{array}{l} y_1 \\ y_2\\ \vdots \\ y_N\\ \end{array} \right] $$And create the error matrix
$$ \Sigma_y = \left[ \begin{array}{lllll} dy_1^2 & 0 & 0 & \cdots & 0\\ 0 & dy_2^2 & 0 & \cdots & 0\\ 0 & 0 & dy_3^2 & \cdots & 0\\ \vdots & \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & 0 & \cdots & dy_N^2 \end{array} \right] $$then our model is given by
$$ M(\omega, \theta) = X_\omega\theta $$and our $\chi^2$ can be written
$$ \chi^2(\omega, \theta) = (\bar{y} - X_\omega\theta)^T\Sigma_y^{-1}(\bar{y} - X_\omega\theta) $$Minimizing this cost funciton with respect to $\theta$ gives the maximum likelihood parameters:
$$ \hat{\theta} = (X_\omega^T\Sigma_y^{-1}X_\omega)^{-1}X_\omega^T\Sigma_y^{-1}\bar{y} $$We can simplify this a bit by defining
$$ X_{\omega,\ast} = \Sigma_y^{-1/2}X_\omega \\ \bar{y}_\ast = \Sigma_y^{-1/2}\bar{y} $$And the above becomes
$$ \hat{\theta} = (X_{\omega,\ast}^TX_{\omega,\ast})^{-1}X_{\omega,\ast}^T\bar{y}_\ast $$Now the $\chi^2$ of the model fit is given by
$$ \chi^2(\omega,\hat{\theta}) = \left[ \bar{y}_\ast^T\bar{y}_\ast - \bar{y}_\ast^TX_{\omega,\ast} (X_{\omega,\ast}^TX_{\omega,\ast})^{-1}X_{\omega,\ast}^T\bar{y}_\ast \right] $$The reference $\chi^2$ is
$$ \chi_0^2 = \bar{y}_\ast^T\bar{y}_\ast $$So the power $P_{LS} = 1 - \chi^2/\chi_0^2$ is given by
$$ P_{LS}(\omega) = \frac{\bar{y}_\ast^TX_{\omega,\ast} (X_{\omega,\ast}^TX_{\omega,\ast})^{-1}X_{\omega,\ast}^T\bar{y}_\ast}{\bar{y}_\ast^T\bar{y}_\ast} $$The generalized lomb-scargle fits for the mean of $y$ as part of the model, rather than as a separete step.
So what changes is that the $X_\omega$ becomes:
$$ X_\omega = \left[ \begin{array}{lll} 1 & \sin(\omega t_1) & \cos(\omega t_1)\\ 1 & \sin(\omega t_2) & \cos(\omega t_2)\\ \vdots & \vdots & \vdots \\ 1 & \sin(\omega t_N) & \cos(\omega t_N)\\ \end{array} \right] $$and $\bar{y}$ becomes
$$ \bar{y} = y - X_\omega \mathbf{1}_1 \hat{\theta} $$where the best-fit parameters $\hat{\theta}$ satisfy
$$ \hat{\theta} = (X_\omega^T\Sigma_y^{-1}X_\omega)^{-1}X_\omega^T\Sigma_y^{-1} y $$and we have defined,
$$ \mathbf{1}_1 = \left[ \begin{array}{lll} 1 & 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0 \end{array} \right] $$With this change, we write the maximum $\chi^2$ as
$$ \chi^2(\omega) = (y - X_\omega\hat{\theta})^T\Sigma_y^{-1}(y - X_\omega\hat{\theta}) $$Let's re-express this in terms of $\bar{y}$:
$$ \chi^2(\omega) = (\bar{y} - X_\omega\tilde{\mathbf{1}}_1\hat{\theta})^T\Sigma_y^{-1}(y - X_\omega\tilde{\mathbf{1}}_1\hat{\theta}) $$Where we have defined
$$ \tilde{\mathbf{1}}_1 = I - \mathbf{1}_1 $$
In [ ]: