| predict.onls | R Documentation |
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.
## 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, ...)
object |
an object returned from |
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 |
df |
the degrees of freedom of the |
interval |
type of interval: none, a confidence interval for the model function |
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 |
... |
further arguments, ignored. |
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.
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).
Andrej-Nikolai Spiess
onls, confint.onls, summary.onls.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.