logLik_o: Log-likelihood of the errors-in-variables model

View source: R/fit_functions.R

logLik_oR Documentation

Log-likelihood of the errors-in-variables model

Description

Returns the log-likelihood of the errors-in-variables (functional) model fitted by onls, in which both the response and the predictors are observed with Gaussian errors, with the precisions given by weights, sigma_x and sigma_y. It is computed from the weighted orthogonal distances (residuals_o) at the fitted parameters and foot points.

Usage

logLik_o(object) 

Arguments

object

an object returned from onls.

Details

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.

Value

An object of class c("logLik_o", "logLik"): the log-likelihood, with attributes "df" (the number of free model parameters, plus one if the variance scale was estimated, see 'Details') and "nobs"/"nall" (the number of observations with non-zero weight). AIC and BIC can be applied to it.

Note

The usual logLik applies to the vertical residuals of the orthogonal model, i.e. to an ordinary least-squares likelihood at the observed predictors.

Author(s)

Andrej-Nikolai Spiess

References

The Maximum Likelihood Solution of the Problem of Estimating a Linear Functional Relationship.
Solari ME.
Journal of the Royal Statistical Society, Series B (1969), 31: 372-375.

Examples

set.seed(123)
DNase1 <- subset(DNase, Run == 1)
DNase1$density <- sapply(DNase1$density, function(x) rnorm(1, x, 0.1 * x))
mod1 <- onls(density ~ Asym/(1 + exp((xmid - log(conc))/scal)), 
             data = DNase1, start = list(Asym = 3, xmid = 0, scal = 1))
logLik_o(mod1)

## AIC of the errors-in-variables model (not comparable with AIC(mod1),
## the least-squares likelihood of the vertical residuals; see 'Details').
AIC(logLik_o(mod1))

## Comparing two models fitted with the same (known) error variances:
## three- and four-parameter logistic.
m3 <- onls(density ~ Asym/(1 + exp((xmid - log(conc))/scal)), data = DNase1,
           start = list(Asym = 3, xmid = 0, scal = 1), sigma_x = 0.05, sigma_y = 0.1)
m4 <- onls(density ~ y0 + (Asym - y0)/(1 + exp((xmid - log(conc))/scal)), data = DNase1,
           start = list(y0 = 0, Asym = 3, xmid = 0, scal = 1), sigma_x = 0.05, sigma_y = 0.1)
c(m3 = AIC(logLik_o(m3)), m4 = AIC(logLik_o(m4)))

onls documentation built on Nov. 9, 2026, 5:06 p.m.