predict.onls: Predictions, confidence and prediction intervals from an onls...

View source: R/S3_functions.R

predict.onlsR Documentation

Predictions, confidence and prediction intervals from an onls fit

Description

Evaluates the fitted onls model at new predictor values, optionally with standard errors and with confidence intervals for the model function or prediction intervals for a new observation in the errors-in-variables model.

Usage

## S3 method for class 'onls'
predict(object, newdata, se.fit = FALSE, scale = NULL, df = NULL,
        interval = c("none", "confidence", "prediction"), level = 0.95,
        sigma_x = NULL, sigma_y = NULL, ...)

Arguments

object

an object returned from onls.

newdata

a data frame with columns for all predictors. If missing, the observed predictors of the fit are used.

se.fit

logical: return the standard errors of the fitted values?

scale

the residual standard deviation s. Default: 1 with known variances, otherwise \sqrt{\mathrm{reduced\_chisq}}. If given, the standard errors of the fitted values are rescaled to it too, as in predict.lm.

df

the degrees of freedom of the t quantiles. Default: Inf (normal quantiles) with known variances, otherwise df_resid.

interval

type of interval: none, a confidence interval for the model function f(x, \theta), or a prediction interval for a new observation y at the observed (error-prone) predictor x.

level

the confidence level.

sigma_x, sigma_y

the standard deviations of the predictor and response errors of the new observations, in any form accepted by onls: a scalar, a length-p vector, a p \times p covariance matrix (a square p \times p matrix is always taken as a covariance, also if newdata has p rows; give per-row standard deviations for p rows as a data frame), or one row of standard deviations per row of newdata; sigma_y of length 1 or nrow(newdata). Needed for interval = "prediction" only if the fit used observation-specific values; otherwise those of the fit are used.

...

further arguments, ignored.

Details

With J the gradient of the model function with respect to the free parameters at newdata and V their covariance (vcov), the standard error of the fitted value is se_{\mathrm{fit}} = \sqrt{J V J^T}.

A prediction interval refers to a new observation whose response and predictors are both measured with error. Its variance is the effective variance of ODR (as in the parameter covariance, see onls) plus the variance of the fitted value:

se^2 = se_{\mathrm{fit}}^2 + s^2\left(\sigma_{y,\mathrm{new}}^2 + g^T \Sigma_{x,\mathrm{new}}\, g\right),

where g is the gradient of the model function with respect to the predictors at newdata, and \Sigma_{x,\mathrm{new}} the predictor covariance of the new observation. The quantiles are taken from the normal distribution for known variances (known_sigma = TRUE) and from the t distribution with df_resid degrees of freedom otherwise, as in summary.onls and confint.onls.

A prediction interval at the observed predictor is the relevant one for a future measurement pair (x, y). If the predictor of the new observation is known exactly, use sigma_x = 0 (i.e. the response error only). A new observation has weight 1: if the fit used non-constant weights, a warning suggests to supply its sigma_y.

Value

If se.fit = FALSE and interval = "none", a vector of fitted values. With an interval, a matrix with columns fit, lwr and upr. If se.fit = TRUE, a list with the components fit (vector or matrix as before), se.fit (the standard errors of the fitted values), df and residual.scale (s).

Author(s)

Andrej-Nikolai Spiess

See Also

onls, confint.onls, summary.onls.

Examples

## straight line, known error variances in x and y
set.seed(1)
xt <- 1:20; x <- xt + rnorm(20, 0, 0.5); y <- 2 + 0.5 * xt + rnorm(20, 0, 0.3)
mod <- onls(y ~ a + b * x, data.frame(x, y), start = list(a = 1, b = 1),
            sigma_x = 0.5, sigma_y = 0.3)
nd <- data.frame(x = c(5, 15))
predict(mod, nd, interval = "confidence")
predict(mod, nd, interval = "prediction")
## new observations with an error-free predictor
predict(mod, nd, interval = "prediction", sigma_x = 0)

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