Each observation \(i\) contributes \(1 + p\) Gaussian error components, the response error with precision \(s^{-2} Qyy_i\) and the \(p\) predictor errors with precision matrix \(s^{-2} Qx_i\), where \(Qyy_i\) and \(Qx_i\) are the precisions used by onls and \(s^2\) is a common variance scale. At the fitted parameters and foot points, the exponents add up to \(S = \sum_i d_i^2\), the minimized objective, and with \(N\) observations of non-zero weight and \(k = N(1 + p)\) components the log-likelihood is
$$\ell = -\frac{S}{2 s^2} - \frac{k}{2}\log(2\pi s^2) + \frac{1}{2}\sum_{i=1}^{N} \log Qyy_i + \frac{1}{2}\sum_{i=1}^{N} \log|Qx_i|$$
With known variances (known_sigma = TRUE in onls), \(s^2 = 1\), otherwise, \(s^2\) is replaced by its maximum-likelihood estimate \(S/k\), giving \(\ell = -\frac{k}{2}(\log(2\pi S/k) + 1) + \frac{1}{2}\sum\log Qyy_i + \frac{1}{2}\sum\log|Qx_i|\), and the scale counts as one estimated parameter.
\(|Qx_i|\) is the determinant of the predictor precision matrix (a scalar for one predictor; it accounts for predictor correlation in the multivariate case). Observations with zero weight are excluded, as in logLik for weighted fits. When sigma_x and sigma_y are scaled by a common factor and the scale is estimated, \(\ell\) does not change.
The foot points \(\hat\xi_i\) (the incidental parameters of the functional model) are maximized out but not counted in "df": their number grows with \(N\), so the usual asymptotics of the likelihood do not apply to them, and the maximum-likelihood estimate \(S/k\) of the scale is biased downwards (reduced_chisq = \(S/\mathrm{df\_resid}\) is the usual estimate). logLik_o and the AIC/BIC derived from it are therefore meant for comparing onls fits to the same data (same response, predictors and observations) with the same weights, sigma_x and sigma_y that differ in the model function or in the fixed or free parameters; they are not comparable with logLik of an nls fit, which assumes error-free predictors.
The ratio of the predictor to the response error variance cannot be chosen by maximizing logLik_o: in the functional model, the likelihood with an estimated scale is unbounded as this ratio tends to zero (or infinity), a known property of errors-in-variables models (Solari 1969). The ratio has to be known, as in Deming regression.
Version 0.3-0 changed the definition: earlier versions treated the \(d_i\) as \(N\) (instead of \(k\)) Gaussian residuals with an estimated variance, also for known variances.